shithub: mc

Download patch

ref: 3c96292a713f091b96d015aedcf824a7ea82f1cf
parent: 2b9c96053f0d6947452862d89217541b96492241
author: Ori Bernstein <ori@eigenstate.org>
date: Fri May 27 13:59:44 EDT 2016

Break out of a test when failing.

--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -4,8 +4,7 @@
 	type ctx = struct
 		ok	: bool
 		reason	: byte[:]
-
-		retctx	: std.jmpbuf#
+		jmpbuf	: std.jmpbuf#
 	;;
 
 	type spec = struct
@@ -14,10 +13,11 @@
 	;;
 
 	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 check	= {ctx, cond, msg, args
-	var ap
-	var msg
+const ok = {ctx
+	/* nothing to do here */
+}
 
+const check = {ctx, cond, msg
 	if !cond
-		ap = std.vastart(&args)
-		failv(ctx, msg, &ap)
+		fail(ctx, msg)
 	;;
 }
 
-const ok = {ctx
-	/* nothing to do here? */
+const fail = {ctx, msg
+	softfail(ctx, msg)
+	std.longjmp(ctx.jmpbuf)
 }
 
-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 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 @@
 		reason = ctx.reason
 	;;
 	std.put("!}}>> {} {}\n", status, reason)
-	std.slfree(reason)
 }