shithub: mc

Download patch

ref: d43127a52e3dfac1f1f1eba32986ae3bbdd083ee
parent: 88a4ba446d6b505f26cfefb8f81b223a45bbeba3
author: Ori Bernstein <ori@eigenstate.org>
date: Tue May 31 06:08:02 EDT 2016

Test failures should longjmp out of the context.

--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -4,6 +4,8 @@
 	type ctx = struct
 		ok	: bool
 		reason	: byte[:]
+
+		retctx	: std.jmpbuf#
 	;;
 
 	type spec = struct
@@ -14,6 +16,7 @@
 	const run	: (specs : spec[:] -> void)
 	const ok	: (ctx : ctx# -> void)
 	const fail	: (ctx : ctx#, msg : byte[:] -> void)
+	const softfail	: (ctx : ctx#, msg : byte[:] -> void)
 ;;
 
 const run = {specs
@@ -24,23 +27,31 @@
 }
 
 const ok = {ctx
-	/* nothing to do here */
+	/* nothing to do here? */
 }
 
 const fail = {ctx, msg
+	softfail(ctx, msg)
+	std.longjmp(ctx.retctx)
+}
+
+const softfail = {ctx, msg
 	ctx.ok = false
 	ctx.reason = msg
 }
 
 const runspec = {ts
+	var status, reason, jbuf
 	var ctx : ctx
-	var status, reason
 
 	ctx.ok = true
 	ctx.reason = ""
+	ctx.retctx = &jbuf
 	std.put("test {} <<{{!\n", ts.name)
 
-	ts.fn(&ctx)
+	if !std.setjmp(&jbuf)
+		ts.fn(&ctx)
+	;;
 
 	if ctx.ok
 		status = "ok"