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

119 lines (87 sloc) 2.243 kb
use("atomy")
io = require("io")
condition = require("condition")
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"
theorize &tests :=
let(running-stats = Stats new):
tests call
puts("")
stats = ^running-stats
puts(
f"total of %d tests (%s passed, %s failed)" [
stats failed + stats passed
colored(.green, stats passed)
if(stats failed == 0)
then: "0"
else: colored(.red, stats failed)
])
stats
describe(what) &body := do:
puts(indented(f"- %s" [what]))
let(nesting-level = ^nesting-level + 1):
body call
nil
it(description) &tests := do:
{ tests call
puts(indented(colored(.green, f"✓ %s" [description])))
} rescue {
e:
when(^running-stats):
^running-stats failed += 1
puts(indented(colored(.red, f"✗ %s" [description])))
puts(
indented(
colored(
.yellow
f" ` %s: %s" [
e class name
e message
])))
e backtrace first((ENV["THERIE_BT_LIMIT"] or 5) to-i) each [l]:
puts(indented(f" %s" [colored(.cyan, l)]))
} 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]))
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)?):
condition restart(.errored)
raise(f"expected error %s, got: %s" [y, e message])
}
Jump to Line
Something went wrong with that request. Please try again.