summaryrefslogtreecommitdiff
path: root/lib/testr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-05-31 10:08:02 -0400
committerOri Bernstein <ori@eigenstate.org>2016-05-31 10:08:02 -0400
commitd43127a52e3dfac1f1f1eba32986ae3bbdd083ee (patch)
treecc3c5228f66a39aadf5968956ce4acb1cf113ffb /lib/testr
parent88a4ba446d6b505f26cfefb8f81b223a45bbeba3 (diff)
downloadmc-d43127a52e3dfac1f1f1eba32986ae3bbdd083ee.tar.gz
Test failures should longjmp out of the context.
Diffstat (limited to 'lib/testr')
-rw-r--r--lib/testr/testr.myr17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/testr/testr.myr b/lib/testr/testr.myr
index ff3ecc2..7c5e3cc 100644
--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -4,6 +4,8 @@ pkg testr =
type ctx = struct
ok : bool
reason : byte[:]
+
+ retctx : std.jmpbuf#
;;
type spec = struct
@@ -14,6 +16,7 @@ pkg testr =
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
@@ -24,23 +27,31 @@ const run = {specs
}
const ok = {ctx
- /* nothing to do here */
+ /* 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
- var status, reason
ctx.ok = true
ctx.reason = ""
+ ctx.retctx = &jbuf
std.put("test {} <<{{!\n", ts.name)
- ts.fn(&ctx)
+ if !std.setjmp(&jbuf)
+ ts.fn(&ctx)
+ ;;
if ctx.ok
status = "ok"