summaryrefslogtreecommitdiff
path: root/lib/testr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-10-08 19:24:26 -0700
committerOri Bernstein <ori@eigenstate.org>2016-10-08 19:28:12 -0700
commit7f8734b0b4c43f60a3b4a79929fe60725f64fbc2 (patch)
treeffb8be7188cacd1048df7054d786867659db8065 /lib/testr
parent44bd7d2ca3dc2b1a06cc0f4f688c0980d52a296e (diff)
downloadmc-7f8734b0b4c43f60a3b4a79929fe60725f64fbc2.tar.gz
Add vararg messages to failures.
It's useful to be able to pass back a value in your failure reason.
Diffstat (limited to 'lib/testr')
-rw-r--r--lib/testr/testr.myr36
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/testr/testr.myr b/lib/testr/testr.myr
index 1f7660c..2c43449 100644
--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -14,10 +14,10 @@ pkg testr =
const run : (specs : spec[:] -> void)
const ok : (ctx : ctx# -> void)
- const fail : (ctx : ctx#, msg : byte[:] -> void)
- const check : (ctx : ctx#, cond : bool, msg : byte[:] -> void)
+ const fail : (ctx : ctx#, msg : byte[:], args : ... -> void)
+ const check : (ctx : ctx#, cond : bool, msg : byte[:], args : ... -> void)
- const softfail : (ctx : ctx#, msg : byte[:] -> void)
+ const softfail : (ctx : ctx#, msg : byte[:], args : ... -> void)
;;
const run = {specs
@@ -31,20 +31,37 @@ const ok = {ctx
/* nothing to do here */
}
-const check = {ctx, cond, msg
+const check = {ctx, cond, msg, args
+ var ap
+
if !cond
- fail(ctx, msg)
+ ap = std.vastart(&args)
+ failv(ctx, msg, &ap)
;;
}
-const fail = {ctx, msg
- softfail(ctx, msg)
+const fail = {ctx, msg, args
+ var ap
+
+ ap = std.vastart(&args)
+ failv(ctx, msg, &ap)
+}
+
+const failv = {ctx, msg, ap
+ softfailv(ctx, msg, ap)
std.longjmp(ctx.jmpbuf)
}
-const softfail = {ctx, msg
+const softfail = {ctx, msg, args
+ var ap
+
+ ap = std.vastart(&args)
+ softfailv(ctx, msg, &ap)
+}
+
+const softfailv = {ctx, msg, ap
ctx.ok = false
- ctx.reason = msg
+ ctx.reason = std.fmtv(msg, ap)
}
const runspec = {ts
@@ -69,4 +86,5 @@ const runspec = {ts
reason = ctx.reason
;;
std.put("!}}>> {} {}\n", status, reason)
+ std.slfree(reason)
}