aboutsummaryrefslogtreecommitdiff
path: root/lib/tools/test.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-14 15:42:48 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-14 15:43:24 -0800
commitc1c32688a4afc43f6addb99b8b5fa878944a70e3 (patch)
treec886f21b5b08a9053aa74fcba4b241dae5ede76d /lib/tools/test.nom
parent2309b696fc34b24f05f6658b94f9105ca8ee76e4 (diff)
Overhaul in progress, mostly working. Moved all the nomsu packages into
lib/, including core/*. Changes to how nomsu environments and importing work.
Diffstat (limited to 'lib/tools/test.nom')
-rwxr-xr-xlib/tools/test.nom65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/tools/test.nom b/lib/tools/test.nom
new file mode 100755
index 0000000..4663bd4
--- /dev/null
+++ b/lib/tools/test.nom
@@ -0,0 +1,65 @@
+#!/usr/bin/env nomsu -V6.14
+#
+ Tool to run all tests in a file (i.e. the code block inside a call to 'test $'). Usage:
+ nomsu tools/test.nom file1 file2 directory1 ...
+
+use "filesystem"
+use "consolecolor"
+use "commandline"
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+command line program with $args:
+ for $filename in $args.extras at $i:
+ $file = (read file $filename)
+ unless $file:
+ fail "Couldn't find \$filename"
+
+ $(test environment) = (new environment)
+ $(test environment), export $filename
+ $version =
+ $file, matching ("
+ #![^
+ ]* nomsu %-V[ ]*([^
+ ]*)
+ ")
+ $file_tests = []
+ for $src = $test in $(test environment).TESTS:
+ if $version:
+ $test = ("
+ #!/usr/bin/env nomsu -V\$version
+ \$test
+ ")
+ $file_tests, add {.test = $test, .source = $src}
+
+ unless ($file_tests is empty):
+ sort $file_tests by $ -> $.source
+ say "[ .. ] \$filename" inline
+ $io.flush()
+
+ if $args.v: say ""
+
+ $failures = []
+ for $ in $file_tests:
+ if $args.v:
+ say " \(yellow ($.test, with "\n" -> "\n "))"
+ try:
+ $(test environment), run $.test
+ ..if it fails with $msg:
+ $src = ($Source, from string $.source)
+ $l1 = ($file, line number at $src.start)
+ $l2 = ($file, line number at $src.stop)
+ $failures, add "\(yellow "\($src.filename):\($l1)-\$l2:")\n\(bright (red ($msg, indented)))"
+
+ if ($failures is empty):
+ if $args.v:
+ say (green "PASS")
+ ..else:
+ say "\r[\(green "PASS")"
+ ..else:
+ if $args.v:
+ say (red (bright "FAIL"))
+ ..else:
+ say "\r[\(red (bright "FAIL"))"
+ say "\($failures, joined with "\n", indented)"
+