ref: d4bb1a020b60fe906dfa7ee2a12cc4fee1513e6a
parent: bc9ee15fdd4a4c961bac0de2f4f9c4fceccd4a86
author: Ori Bernstein <ori@markovcorp.com>
date: Wed Jan 31 06:42:25 EST 2018
Teach libtestr to listen MTEST_SUBSET. Now it won't run tests that aren't listed there.
--- a/lib/http/url.myr
+++ b/lib/http/url.myr
@@ -60,6 +60,7 @@
const parseurl = {url
var schema, host, port, path, params
+ std.put("url: {}\n", url)
match parseschema(&url)
| `std.Ok s: schema = s
| `std.Err e: -> `std.Err e
--- a/lib/testr/testr.myr
+++ b/lib/testr/testr.myr
@@ -22,17 +22,25 @@
;;
const bench = {specs
+ var subset
+
+ subset = subtests()
std.put("MTEST {}\n", specs.len)
for s : specs
- benchspec(&s)
+ benchspec(&s, subset)
;;
+ std.htfree(subset)
}
const run = {specs
+ var subset
+
+ subset = subtests()
std.put("MTEST {}\n", specs.len)
for s : specs
- testspec(&s)
+ testspec(&s, subset)
;;
+ std.htfree(subset)
}
const ok = {ctx
@@ -75,11 +83,11 @@
;;
}
-const benchspec = {ts
+const benchspec = {ts, sub
+ var ctx : ctx
var avg, m, d, n, nsamp
var start, dt
- var ctx : ctx
- var jmpbuf
+ var dorun, jmpbuf
ctx.ok = true
ctx.reason = ""
@@ -89,8 +97,9 @@
m = 0.0;
n = 0.0;
nsamp = 0
+ dorun = matchtest(ts.name, sub)
std.put("test {} <<{{!\n", ts.name)
- if !std.setjmp(&jmpbuf)
+ if !std.setjmp(&jmpbuf) && dorun
/* estimate samples */
start = std.now()
ts.fn(&ctx)
@@ -114,7 +123,9 @@
;;
;;
- if ctx.ok
+ if !dorun
+ std.put("!}}>> skip filtered\n", nsamp, avg, m)
+ elif ctx.ok
std.put("!}}>> timing {} {} {}\n", nsamp, avg, m)
else
std.put("!}}>> fail {}\n", ctx.reason)
@@ -122,20 +133,23 @@
;;
}
-const testspec = {ts
+const testspec = {ts, sub
var ctx : ctx
- var jmpbuf
+ var dorun, jmpbuf
ctx.ok = true
ctx.reason = ""
ctx.jmpbuf = &jmpbuf
+ dorun = matchtest(ts.name, sub)
std.put("test {} <<{{!\n", ts.name)
- if !std.setjmp(&jmpbuf)
+ if !std.setjmp(&jmpbuf) && dorun
ts.fn(&ctx)
;;
- if ctx.ok
+ if !dorun
+ std.put("!}}>> skip filtered\n")
+ elif ctx.ok
std.put("!}}>> ok\n")
else
std.put("!}}>> fail {}\n", ctx.reason)
@@ -142,3 +156,23 @@
std.slfree(ctx.reason)
;;
}
+
+const subtests = {
+ var subset
+
+ subset = std.mkht()
+ match std.getenv("MTEST_SUBSET")
+ | `std.None: /* no subtests */
+ | `std.Some "": /* no subtests */
+ | `std.Some subs:
+ for s : std.bysplit(subs, ",")
+ std.htput(subset, s, true)
+ ;;
+ ;;
+ -> subset
+}
+
+const matchtest = {name, sub
+ -> std.htcount(sub) == 0 || std.hthas(sub, name)
+}
+