diff options
author | Ori Bernstein <ori@eigenstate.org> | 2016-05-31 10:19:10 -0400 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2016-05-31 10:24:29 -0400 |
commit | 62a6dc43879c5eb846f0e918bd489e61d8401057 (patch) | |
tree | 07ade92e3d4f836e0800063d0ba680ea28c41f99 /lib/testr | |
parent | d43127a52e3dfac1f1f1eba32986ae3bbdd083ee (diff) | |
download | mc-62a6dc43879c5eb846f0e918bd489e61d8401057.tar.gz |
Make fail/softfail take format strings.
Diffstat (limited to 'lib/testr')
-rw-r--r-- | lib/testr/testr.myr | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/lib/testr/testr.myr b/lib/testr/testr.myr index 7c5e3cc..99990e9 100644 --- a/lib/testr/testr.myr +++ b/lib/testr/testr.myr @@ -14,9 +14,10 @@ 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[:] -> void) - const softfail : (ctx : ctx#, msg : byte[:] -> void) + const fail : (ctx : ctx#, msg : byte[:], args : ... -> void) + const softfail : (ctx : ctx#, msg : byte[:], args : ... -> void) ;; const run = {specs @@ -26,18 +27,42 @@ 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? */ } -const fail = {ctx, msg - softfail(ctx, msg) +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 failv = {ctx, msg, ap + softfailv(ctx, msg, ap) std.longjmp(ctx.retctx) } -const softfail = {ctx, msg +const softfailv = {ctx, msg, ap ctx.ok = false - ctx.reason = msg + ctx.reason = std.fmtv(msg, ap) } const runspec = {ts @@ -61,4 +86,5 @@ const runspec = {ts reason = ctx.reason ;; std.put("!}}>> {} {}\n", status, reason) + std.slfree(reason) } |