ref: d3566a96838ddc2346fa57f8c4d908812bee6206
parent: e35e7e3998b990d50818927d30e4792e25368206
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Sep 17 07:10:48 EDT 2015
Allow any binary or command to be tagged as a test.
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -22,12 +22,14 @@
;;
std.htput(b.built, tn, true)
match gettarg(b.targs, tn)
- | `Bin bt: buildbin(b, bt, false)
+ | `Bin bt:
+ if !bt.istest
+ buildbin(b, bt, false)
+ ;;
| `Lib lt: buildlib(b, lt)
- | `Test tt: /* build on 'mbld test' by default */
| `Gen gt: genfiles(b, gt)
| `Man mt: /* nothing needed */
- | `Cmd ct: /* these are for manual commands */
+ | `Cmd ct: /* these are for manual commands or tests */
;;
;;
-> true
@@ -47,12 +49,14 @@
;;
std.htput(b.built, tn, true)
match gettarg(b.targs, tn)
- | `Bin bt: buildbin(b, bt, false)
+ | `Bin bt:
+ if !bt.istest
+ buildbin(b, bt, false)
+ ;;
| `Lib lt: buildlib(b, lt)
- | `Test tt: /* build on 'mbld test' by default */
| `Gen gt: genfiles(b, gt)
| `Man mt: /* nothing needed */
- | `Cmd ct: /* these are for manual commands */
+ | `Cmd ct: /* these are for manual commands or tests */
;;
;;
build(b, targ)
@@ -94,7 +98,6 @@
match std.htget(b.targs, targ)
| `std.Some (`Bin bt): buildbin(b, bt, false)
| `std.Some (`Lib lt): buildlib(b, lt)
- | `std.Some (`Test tt): buildbin(b, tt, false)
| `std.Some (`Gen gt): runin(b, gt.cmd, gt.dir)
| `std.Some (`Cmd ct): runin(b, ct.cmd, ct.dir)
| `std.Some (`Man mt): /* nothing needed */
--- a/mbld/clean.myr
+++ b/mbld/clean.myr
@@ -19,8 +19,6 @@
cleanup(b, bt, bt.inputs)
| `Lib lt:
cleanup(b, lt, lt.inputs)
- | `Test tt:
- cleanup(b, tt, tt.inputs)
| `Gen gt:
for f in gt.out
if !gt.durable && std.remove(f)
@@ -44,10 +42,6 @@
| `Lib lt:
if std.sleq(lt.name, targ)
cleanup(b, lt, lt.inputs)
- ;;
- | `Test tt:
- if std.sleq(tt.name, targ)
- cleanup(b, tt, tt.inputs)
;;
| `Gen gt:
for f in gt.out
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -28,11 +28,11 @@
for tn in b.all
match gettarg(b.targs, tn)
| `Bin bt:
- if bt.install
+ if bt.install && !bt.istest
movefile(b, rm, bt.dir, bt.name, config.Binpath, 0o755)
;;
| `Lib lt:
- if lt.install
+ if lt.install && !lt.istest
movefile(b, rm, lt.dir, lt.name, config.Libpath, 0o644)
libarchive = std.fmt("lib{}.a", lt.name)
movefile(b, rm, lt.dir, libarchive, config.Libpath, 0o644)
@@ -47,7 +47,6 @@
for m in mt.pages
moveman(b, rm, mt.dir, m)
;;
- | `Test tt: /* nothing */
;;
;;
-> true
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -215,7 +215,9 @@
const testtarget = {b, p
var t
t = myrtarget(p, "test")
- addtarg(p, b, t.name, t.systags, `Test t)
+ t.istest = true
+ t.install = false
+ addtarg(p, b, t.name, t.systags, `Bin t)
}
/* mantarget: anontarget */
@@ -242,7 +244,7 @@
/* gentarget: wordlist {attrs} = wordlist ;; */
const cmdtarget = {b, p, cmd, iscmd
var outlist, deplist, cmdlist, systags
- var durable
+ var durable, istest
var attrs
var gt
@@ -256,7 +258,7 @@
;;
skipspace(p)
- if !iscmd && matchc(p, '{')
+ if matchc(p, '{')
match attrlist(p)
| `std.Some al: attrs = al
| `std.None: failparse(p, "invalid attr list for {}\n", outlist[0])
@@ -267,7 +269,7 @@
skipspace(p)
if !matchc(p, '=')
- failparse(p, "expected '=' after '{} {}'\n", cmdlist, outlist[outlist.len-1])
+ failparse(p, "expected '=' after '{} {}'\n", cmd, outlist[outlist.len-1])
;;
match wordlist(p)
@@ -281,11 +283,13 @@
;;
durable = false
+ istest = false
deplist = [][:]
systags = [][:]
for elt in attrs
match elt
| ("durable", ""): durable = true
+ | ("test", ""): istest = true
| ("dep", depname): deplist = std.slpush(deplist, depname)
| ("sys", tag): systags = std.slpush(systags, tag)
| (attr, ""):
@@ -299,6 +303,7 @@
.dir=std.sldup(p.fdir),
.out=outlist,
.durable=durable,
+ .istest=istest,
.deps=deplist,
.cmd=cmdlist,
.systags=systags,
@@ -320,6 +325,7 @@
const myrtarget = {p, targ
var ldscript, runtime, inst, incpath, systags
var name, inputs, libdeps, attrs
+ var istest
var fsel
match word(p)
@@ -360,6 +366,7 @@
;;
inst = true
+ istest = false
ldscript = ""
runtime = ""
incpath = [][:]
@@ -370,6 +377,7 @@
| ("runtime", rt): runtime = std.sldup(rt)
| ("inc", path): incpath = std.slpush(incpath, std.sldup(path))
| ("noinst", ""): inst = false
+ | ("test", ""): istest = true
| ("sys", tag): systags = std.slpush(systags, tag)
| (invalid, _):
std.fatal("{}: got invalid attr '{}'\n", targ, invalid)
@@ -385,6 +393,7 @@
.inputs=inputs,
.libdeps=libdeps,
.islib=false,
+ .istest=istest,
/* attrs */
.systags=systags,
.install=inst,
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -15,8 +15,9 @@
;;
const test = {b
+ var tests : (byte[:][:], byte[:])[:]
+ var bincmd
var ok
- var tests : (byte[:], byte[:])[:]
/* no implicit tests to run */
tests = [][:]
@@ -34,12 +35,21 @@
;;
for tn in b.all
match gettarg(b.targs, tn)
- | `Test t:
+ | `Bin t:
+ if !t.istest
+ continue
+ ;;
if t.incpath.len == 0 || !std.sleq(t.incpath[0], ".")
t.incpath = std.slput(t.incpath, 0, std.sldup("."))
;;
buildbin(b, t, false)
- tests = std.slpush(tests, (std.strcat("./", t.name), std.sldup(t.dir)))
+ bincmd = std.sldup([std.strcat("./", t.name)][:])
+ tests = std.slpush(tests, (bincmd, std.sldup(t.dir)))
+ | `Cmd t:
+ if !t.istest
+ continue
+ ;;
+ tests = std.slpush(tests, (dupcmd(t.cmd), std.sldup(t.dir)))
| _:
/* skip */
;;
@@ -46,15 +56,15 @@
;;
ok = true
- for (bin, dir) in tests
+ for (c, dir) in tests
setdir(b, dir)
- if !runtest(bin)
+ if !runtest(c)
ok = false
;;
;;
for (bin, dir) in tests
- std.slfree(bin)
+ freecmd(bin)
std.slfree(dir)
;;
std.slfree(tests)
@@ -68,8 +78,26 @@
;;
}
+const dupcmd = {cmd
+ var ret
+
+ ret = [][:]
+ for c in cmd
+ ret = std.slpush(ret, std.sldup(c))
+ ;;
+ -> ret
+}
+
+const freecmd = {cmd
+ for c in cmd
+ std.slfree(c)
+ ;;
+ std.slfree(cmd)
+}
+
const buildtests = {b, targ
var tt, bin, tests
+ var cmd
tests = [][:]
setdir(b, targ.dir)
@@ -89,7 +117,8 @@
cleantest(b, path)
buildbin(b, &tt, true)
- tests = std.slpush(tests, (std.strcat("./", bin), std.sldup(targ.dir)))
+ cmd = std.sldup([std.strcat("./", bin)][:])
+ tests = std.slpush(tests, (cmd, std.sldup(targ.dir)))
std.slfree(tt.libdeps)
std.slfree(tt.incpath)
std.slfree(path)
@@ -117,15 +146,19 @@
std.slfree(bin)
}
-const runtest = {bin
+const runtest = {cmd
var r, log
- std.put("run {}:\t", bin)
- log = std.strcat(bin, ".log")
- match std.spork([bin][:])
+ std.put("run")
+ for c in cmd
+ std.put(" {}", c)
+ ;;
+ std.put(":\t")
+ match std.spork(cmd)
| `std.Fail m:
- std.fatal("unable to run test: {}\n", m)
+ std.fatal("\nunable to run test: {}\n", m)
| `std.Ok (pid, infd, outfd):
+ log = std.strcat(cmd[0], ".log")
match std.fslurp(outfd)
| `std.Ok "": /* empty output; nothing to log */
| `std.Ok buf:
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -21,7 +21,6 @@
type targ = union
`Bin myrtarg#
`Lib myrtarg#
- `Test myrtarg#
`Gen cmdtarg#
`Cmd cmdtarg#
`Man mantarg#
@@ -32,6 +31,7 @@
line : int
islib : bool
+ istest : bool
dir : byte[:]
name : byte[:]
inputs : byte[:][:]
@@ -52,6 +52,7 @@
durable : bool
/* we can have multiple outputs, but we only want to run once for each */
done : bool
+ istest : bool
;;
type mantarg = struct