ref: 62a6dc43879c5eb846f0e918bd489e61d8401057
parent: d43127a52e3dfac1f1f1eba32986ae3bbdd083ee
author: Ori Bernstein <[email protected]>
date: Tue May 31 06:19:10 EDT 2016
Make fail/softfail take format strings.
--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -14,9 +14,10 @@
;;
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 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 @@
reason = ctx.reason
;;
std.put("!}}>> {} {}\n", status, reason)
+ std.slfree(reason)
}