diff options
author | Ori Bernstein <ori@eigenstate.org> | 2016-05-27 17:59:44 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2016-06-11 06:34:32 -0700 |
commit | 3c96292a713f091b96d015aedcf824a7ea82f1cf (patch) | |
tree | 41caad46f4dc3105f8c6e289d36b54f0deef3700 /lib/testr | |
parent | 2b9c96053f0d6947452862d89217541b96492241 (diff) | |
download | mc-3c96292a713f091b96d015aedcf824a7ea82f1cf.tar.gz |
Break out of a test when failing.
Diffstat (limited to 'lib/testr')
-rw-r--r-- | lib/testr/testr.myr | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/lib/testr/testr.myr b/lib/testr/testr.myr index 99990e9..1f7660c 100644 --- a/lib/testr/testr.myr +++ b/lib/testr/testr.myr @@ -4,8 +4,7 @@ pkg testr = type ctx = struct ok : bool reason : byte[:] - - retctx : std.jmpbuf# + jmpbuf : std.jmpbuf# ;; type spec = struct @@ -14,10 +13,11 @@ pkg testr = ;; const run : (specs : spec[:] -> void) - const check : (ctx : ctx#, cond : bool, msg : byte[:], args : ... -> void) const ok : (ctx : ctx# -> void) - const fail : (ctx : ctx#, msg : byte[:], args : ... -> void) - const softfail : (ctx : ctx#, msg : byte[:], args : ... -> void) + const fail : (ctx : ctx#, msg : byte[:] -> void) + const check : (ctx : ctx#, cond : bool, msg : byte[:] -> void) + + const softfail : (ctx : ctx#, msg : byte[:] -> void) ;; const run = {specs @@ -27,54 +27,37 @@ const run = {specs ;; } -const check = {ctx, cond, msg, args - var ap - var msg - - if !cond - ap = std.vastart(&args) - failv(ctx, msg, &ap) - ;; -} - const ok = {ctx - /* nothing to do here? */ + /* nothing to do here */ } -const fail = {ctx, msg, args - var ap - - ap = std.vastart(&args) - failv(ctx, msg, &ap) -} - -const softfail = {ctx, msg, args - var ap - - ap = std.vastart(&args) - softfailv(ctx, msg, &ap) +const check = {ctx, cond, msg + if !cond + fail(ctx, msg) + ;; } -const failv = {ctx, msg, ap - softfailv(ctx, msg, ap) - std.longjmp(ctx.retctx) +const fail = {ctx, msg + softfail(ctx, msg) + std.longjmp(ctx.jmpbuf) } -const softfailv = {ctx, msg, ap +const softfail = {ctx, msg ctx.ok = false - ctx.reason = std.fmtv(msg, ap) + ctx.reason = msg } const runspec = {ts - var status, reason, jbuf var ctx : ctx + var status, reason + var jmpbuf ctx.ok = true ctx.reason = "" - ctx.retctx = &jbuf - std.put("test {} <<{{!\n", ts.name) + ctx.jmpbuf = &jmpbuf - if !std.setjmp(&jbuf) + std.put("test {} <<{{!\n", ts.name) + if !std.setjmp(&jmpbuf) ts.fn(&ctx) ;; @@ -86,5 +69,4 @@ const runspec = {ts reason = ctx.reason ;; std.put("!}}>> {} {}\n", status, reason) - std.slfree(reason) } |