ref: 0c475a0c82f93c48c82e95bf52fb5a3fe59a96c1
parent: eed9e36c5e089005e8c8cb80400a1af7a3ed6332
author: Ori Bernstein <ori@eigenstate.org>
date: Tue May 24 08:04:04 EDT 2016
Add testr library. A simple, half-assed test framework.
--- a/lib/bld.sub
+++ b/lib/bld.sub
@@ -7,4 +7,5 @@
std
sys
thread
+ testr
;;
--- /dev/null
+++ b/lib/testr/bld.sub
@@ -1,0 +1,3 @@
+lib testr =
+ testr.myr
+;;
--- /dev/null
+++ b/lib/testr/testr.myr
@@ -1,0 +1,53 @@
+use std
+
+pkg testr =
+ type ctx = struct
+ ok : bool
+ reason : byte[:]
+ ;;
+
+ type spec = struct
+ name : byte[:]
+ fn : (ctx : ctx# -> void)
+ ;;
+
+ const run : (specs : spec[:] -> void)
+ const ok : (ctx : ctx# -> void)
+ const fail : (ctx : ctx#, msg : byte[:] -> void)
+;;
+
+const run = {specs
+ std.put("MTEST {}\n", specs.len)
+ for s in specs
+ runspec(&s)
+ ;;
+}
+
+const ok = {ctx
+ /* nothing to do here */
+}
+
+const fail = {ctx, msg
+ ctx.ok = false
+ ctx.reason = msg
+}
+
+const runspec = {ts
+ var ctx : ctx
+ var status, reason
+
+ ctx.ok = true
+ ctx.reason = ""
+ std.put("test {} <<{{!\n", ts.name)
+
+ ts.fn(&ctx)
+
+ if ctx.ok
+ status = "ok"
+ reason = ""
+ else
+ status = "fail"
+ reason = ctx.reason
+ ;;
+ std.put("!}}>> {} {}\n", status, reason)
+}