Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-resilience

Resilience pipelines for Pudu: retry, circuit breaker, timeout, fallback, hedging, rate limiting, and chaos injection

0.1.0Apache-2.01

InstallClose

LayoutTest.pudu

Pudu66 lines2.4 KB

GitHub ↗
1/** @Test.Package.LayoutTest.Suite — every shipped module stays under the package's module root */2module Package.LayoutTest34import Std.Io as Io5import Std.List as List6import Std.Result as Result7import Std.Test as Test8import Std.Text as Text910/// The module root the manifest declares.11const ROOT: Str = "PuduLangResilience"1213/// Every source file under a directory, sorted.14fn sources(directory: Str) -> Array[Str] {15  var found: Array[Str] = []16  for path in List.sortBy(&Result.unwrapOr(Io.listPaths(directory), []), fn(left: Str, right: Str) -> Bool { left < right }) {17    if path.endsWith(".pudu") {18      found = found.push(path)19    } else if !path.contains(".") {20      found = found.concat(sources(path))21    }22  }23  found24}2526/// The name a file's `module` line declares, or empty text when it has none.27fn declared(path: Str) -> Str {28  let text = Result.unwrapOr(Io.read(path), "")29  match List.find(&text.split("\n"), |line: Str| line.startsWith("module ")) {30    case Some(line) => Text.stripPrefix(line, "module ").trim()31    case None => ""32  }33}3435/// Whether a module name is the root or inside it.36fn owned(name: Str) -> Bool {37  name == ROOT || name.startsWith(ROOT + ".")38}3940/// The module name a path under `src/` must declare.41fn expected(path: Str) -> Str {42  Text.stripPrefix(path, "src/").replace(".pudu", "").replace("/", ".")43}4445/// Runs the suite.46fn main() -> Int {47  let shipped = sources("src")48  let outside = shipped.filter(|path: Str| !owned(declared(path)))49  let misnamed = shipped.filter(|path: Str| declared(path) != expected(path))50  let manifest = Result.unwrapOr(Io.read("pudu.toml"), "")51  let checks = Test.suite("Package.Layout", &[52      Test.that("the source tree is found", shipped.length() > 1),53      Test.equals("every shipped module is under the package root", &outside, &[]),54      Test.equals("every module is named after its path", &misnamed, &[]),55      Test.that("the manifest declares the same root", manifest.contains("root = \"" + ROOT + "\"")),56      Test.equals("the package root is the root module", &declared("src/PuduLangResilience.pudu"), &ROOT),57      Test.that("a name beside the root is refused", !owned("App.Context") && !owned("PuduLangResilienceExtra")),58      Test.that("the root and its children are owned", owned(ROOT) && owned(ROOT + ".App.Context"))59    ])60  let report = Test.run(&checks)61  for failure in Test.failuresOf(&report) {62    let _reported = Io.writeErrorLine(failure)63  }64  Test.report(&report)65}66