ref: e7cef4c863e80881584d6d9d58af76e9b95b07ad
parent: fa8a09271af88e2845062494c6d5a196213eb869
author: Ori Bernstein <ori@eigenstate.org>
date: Mon May 23 20:35:27 EDT 2016
Make the subtest runner a bit more resilient. Don't accept nested tests or multiple test exits.
--- a/mbld/subtest.myr
+++ b/mbld/subtest.myr
@@ -59,6 +59,7 @@
}
const showtests = {f, log, ntests
+ var curtest
var nresults
var ok
@@ -67,13 +68,15 @@
-> false
;;
ok = true
+ curtest = ""
nresults = 0
+ std.put("\n")
for ln in bio.byline(f)
ln = std.strstrip(ln)
match testhead(ln)
| `std.None:
| `std.Some t:
- std.put("\trun {}:\t", std.strstrip(t))
+ starttest(&curtest, t)
bio.put(log, "RUN {}\n", t)
continue
;;
@@ -81,13 +84,11 @@
match testfoot(ln)
| `std.None:
| `std.Some `std.Ok _:
- std.put("PASS\n")
- nresults++
+ endtest(&curtest, &nresults, true)
continue
| `std.Some `std.Fail m:
- std.put("FAIL\n")
+ endtest(&curtest, &nresults, false)
ok = false
- nresults++
continue
;;
@@ -98,6 +99,28 @@
-> false
;;
-> ok
+}
+
+const starttest = {curtest, t
+ if curtest#.len != 0
+ std.fatal("malformed input: test {} nested in {}\n", t, curtest)
+ ;;
+ std.put("\trun {}:\t", std.strstrip(t))
+ curtest# = t
+}
+
+const endtest = {curtest, nresults, pass
+ if curtest#.len == 0
+ std.fatal("malformed input: test ended without start\n")
+ ;;
+ std.slfree(curtest#)
+ curtest# = ""
+ if pass
+ std.put("PASS\n")
+ else
+ std.put("FAIL\n")
+ ;;
+ nresults#++
}
const testhead = {ln
--- a/test/runtest.sh
+++ b/test/runtest.sh
@@ -87,7 +87,7 @@
# Should fail
function F {
- echo "test $test <<{!"
+ echo "test $1 <<{!"
(build $1) > /dev/null 2>1
if [ $? -eq '1' ]; then
pass $1