Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

118 lines (86 sloc) 2.211 kb
use("atomy")
io = require("io")
nesting-level = dynamic(0)
running-stats = dynamic
data(Stats(@passed = 0, @failed = 0))
indented(s) := " " * (^nesting-level * 2) + s
colored(color, s) := do:
unless(^io::OutputPort tty?):
return(s)
codes = [
.black
.red
.green
.yellow
.blue
.magenta
.cyan
.white
]
i"\e[3#{codes index(color)}m#{s}\e[0m"
export
theorize &tests :=
let(running-stats = Stats new):
tests call
"\n" display
^running-stats onto:
f"total of %d tests (%s passed, %s failed)" [
failed + passed
colored(.green, passed to-s)
if(failed == 0)
then: "0"
else: colored(.red, failed to-s)
] display
"\n" display
^running-stats
describe(what) &body := do:
indented(f"- %s" [what]) println
let(nesting-level = ^nesting-level + 1):
body call
nil
it(description) &tests := do:
{ tests call
indented(colored(.green, f"✓ %s" [description])) println
} rescue {
e:
when(^running-stats):
^running-stats failed += 1
indented(colored(.red, f"✗ %s" [description])) println
indented(
colored(
.yellow
f" ` %s: %s" [
e class name
e message
])) println
e backtrace first((ENV["THERIE_BT_LIMIT"] or 5) to-i) each [l]:
indented(f" %s" [colored(.cyan, l)]) println
} else:
when(^running-stats):
^running-stats passed += 1
nil
macro(~x should ~(check: Block)):
`(unless(~x onto ~check):
raise(f"assertion failed for %v" ['~x pretty]))
x should-be(y) :=
unless(x == y):
raise(f"expected %v, got %v" [y, x])
x should-raise(y) :=
x rescue {
e ->
unless(e kind-of(y)?):
raise(f"expected exception %s, got: %s" [y, e class])
} else:
raise("#should-raise - no exception raised")
x should-error(y) :=
{ with-restarts(errored -> nil):
x call
raise("#should-error - no error signaled")
} bind {
(e: ExceptionError) ->
raise(e exception)
(e: Error):
when(e kind-of(y)?):
restart(.errored)
raise(f"expected error %s, got: %s" [y, e message])
}
Jump to Line
Something went wrong with that request. Please try again.