summaryrefslogtreecommitdiff
path: root/lib/testr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-05-24 12:04:04 -0700
committerOri Bernstein <ori@eigenstate.org>2016-05-24 12:04:04 -0700
commit0c475a0c82f93c48c82e95bf52fb5a3fe59a96c1 (patch)
tree392b7babd6f87ed79fc31f2fef571f415da882e3 /lib/testr
parenteed9e36c5e089005e8c8cb80400a1af7a3ed6332 (diff)
downloadmc-0c475a0c82f93c48c82e95bf52fb5a3fe59a96c1.tar.gz
Add testr library.
A simple, half-assed test framework.
Diffstat (limited to 'lib/testr')
-rw-r--r--lib/testr/bld.sub3
-rw-r--r--lib/testr/testr.myr53
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/testr/bld.sub b/lib/testr/bld.sub
new file mode 100644
index 0000000..7288d85
--- /dev/null
+++ b/lib/testr/bld.sub
@@ -0,0 +1,3 @@
+lib testr =
+ testr.myr
+;;
diff --git a/lib/testr/testr.myr b/lib/testr/testr.myr
new file mode 100644
index 0000000..ff3ecc2
--- /dev/null
+++ b/lib/testr/testr.myr
@@ -0,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)
+}