ref: d43127a52e3dfac1f1f1eba32986ae3bbdd083ee
dir: /lib/testr/testr.myr/
use std
pkg testr =
type ctx = struct
ok : bool
reason : byte[:]
retctx : std.jmpbuf#
;;
type spec = struct
name : byte[:]
fn : (ctx : ctx# -> void)
;;
const run : (specs : spec[:] -> void)
const ok : (ctx : ctx# -> void)
const fail : (ctx : ctx#, msg : byte[:] -> void)
const softfail : (ctx : ctx#, msg : byte[:] -> void)
;;
const run = {specs
std.put("MTEST {}\n", specs.len)
for s in specs
runspec(&s)
;;
}
const ok = {ctx
/* nothing to do here? */
}
const fail = {ctx, msg
softfail(ctx, msg)
std.longjmp(ctx.retctx)
}
const softfail = {ctx, msg
ctx.ok = false
ctx.reason = msg
}
const runspec = {ts
var status, reason, jbuf
var ctx : ctx
ctx.ok = true
ctx.reason = ""
ctx.retctx = &jbuf
std.put("test {} <<{{!\n", ts.name)
if !std.setjmp(&jbuf)
ts.fn(&ctx)
;;
if ctx.ok
status = "ok"
reason = ""
else
status = "fail"
reason = ctx.reason
;;
std.put("!}}>> {} {}\n", status, reason)
}