ref: eed9e36c5e089005e8c8cb80400a1af7a3ed6332
parent: e7cef4c863e80881584d6d9d58af76e9b95b07ad
author: Ori Bernstein <ori@eigenstate.org>
date: Tue May 24 08:03:04 EDT 2016
Allow subtests to add MTEST lines. At any point outside a test, MTEST n will add 'n' to the number of tests expected.
--- a/mbld/subtest.myr
+++ b/mbld/subtest.myr
@@ -13,12 +13,11 @@
const __init__ = {
planpat = std.try(regex.compile("MTEST\\s+(-?\\d+)\\s*"))
headpat = std.try(regex.compile("test\\s+(.*)<<{!"))
- footpat = std.try(regex.compile("!}>>\\s*(ok|fail\\s*(.*))"))
+ footpat = std.try(regex.compile("!}>>\\s*(ok|fail\\s*(.*))\\s*"))
}
const showsub = {fd, logfd
var f, log
- var ntests
var res
f = bio.mkfile(fd, bio.Rd)
@@ -28,15 +27,14 @@
| `bio.Err e: std.fatal("error reading subfile: {}\n", e)
| `bio.Eof: -> `std.None
| `bio.Ok ln:
- match regex.exec(planpat, ln)
+ match testplan(ln)
| `std.None:
bio.write(log, ln)
showraw(fd, logfd)
- | `std.Some m:
- ntests = std.get(std.intparse(m[1]))
- regex.matchfree(m)
+ | `std.Some ntests:
res = `std.Some showtests(f, log, ntests)
;;
+
std.slfree(ln)
;;
bio.close(f)
@@ -92,6 +90,15 @@
continue
;;
+ match testplan(ln)
+ | `std.None:
+ | `std.Some n:
+ if curtest.len == 0
+ ntests += n
+ continue
+ ;;
+ ;;
+
bio.put(log, "\t{}\n", ln)
;;
if ntests > 0 && ntests != nresults
@@ -121,6 +128,19 @@
std.put("FAIL\n")
;;
nresults#++
+}
+
+const testplan = {ln
+ var ntests
+
+ match regex.exec(planpat, ln)
+ | `std.None:
+ -> `std.None
+ | `std.Some m:
+ ntests = std.get(std.intparse(m[1]))
+ regex.matchfree(m)
+ -> `std.Some ntests
+ ;;
}
const testhead = {ln