~/bend-docscommunity

src/ez/verdict.bend source

src/ez/verdict.bend on the hub · documented module

# ez/verdict: what the two runners read off a run. `ez prove` passes a proof# whose first line is exactly `ALL PROOFS CHECK` and counts it; `ez test`# tallies each comparison of a run with its trailer. Both runners print what# failed indented under the line that names it. All of it is pure, so what a# run is judged and counted as is a law (laws/ProofPassesOnVerdictLine.bend,# laws/TestTallyCounts.bend); running `bend` and reading its output is the# runners' (ez/prove.bend, ez/test.bend).import Baseimport ../share/capped.bend as Capped# the first line of a run's outputdef head.of(ls: List<&2, String>) -> String:  match ls:    case []:      ""    case h <> _t:      h# the first line of some textdef head(text: String) -> String:  head.of(String.lines(text))# the one line a proof passes ondef verdict() -> String:  "ALL PROOFS CHECK"# every line of a block, indented under the line that introduces itdef indent.go(ls: List<&2, String>) -> List<&2, String>:  match ls:    case []:      []    case h <> t:      ("    " ++ h ++ "\n") <> indent.go(t)# a block of text, indenteddef indent(text: String) -> String:  String.concat(indent.go(String.lines(text)))# whether a run passed the proof gate: its first line is the verdict, exactlydef passed(text: String) -> Bool:  String.eq(head(text), verdict())# one more proof counted, and one more pass when it helddef count(ok: Bool, +passed: Nat) -> Nat:  Bool.pick(Nat, ok, (1n + passed : Nat), passed)# how many comparisons were made, and how many of them heldtype Tally is Data:  Tally{pass: Nat, total: Nat}# one more comparison, and one more pass when it helddef tally.go(ok: Bool, passed: Nat, total: Nat) -> Tally:  match ok:    case True{}:      Tally{(1n + passed : Nat), (1n + total : Nat)}    case False{}:      Tally{passed, (1n + total : Nat)}# the tally with this comparison's verdict in itdef tally(ok: Bool, score: Tally) -> Tally:  Tally{p, n} = score  tally.go(ok, p, n)# a `bend` on one file, inside the memory cap and with this project's BEND_LIB# set for itdef cmd(cap: Bool, +gigs: String, +at: String, +path: String) -> List<&2, String>:  Capped.argv(cap, gigs, at, ["bend", path])# every file's command, in the tree's orderdef cmds(ps: List<&2, String>, +cap: Bool, +gigs: String, +at: String) -> List<&2, List<&2, String>>:  match ps:    case Nil{}:      Nil{}    case Con{+h, t}:      cmd(cap, gigs, at, h) <> cmds(t, cap, gigs, at)