nomsu/lib/tools/test.nom
Bruce Hill a1849da175 Autoformat (mostly just to do with the new
blank-line-after-end-of-multi-indent-block rule
2019-03-27 15:22:46 -07:00

67 lines
2.4 KiB
Plaintext
Executable File

#!/usr/bin/env nomsu -V7.0.0
###
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 ($i = $filename) in $args.extras:
$file = (read file $filename)
unless $file:
fail "Couldn't find \$filename"
$(test environment) = (new environment)
$(test environment), export $filename
$version =
$file, matching ("
#![^
]* nomsu %-V[ ]*([%d.]*)
")
$file_tests = []
for ($src = $test) in (nomsu environment, Module $filename).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 "))"
if $args.e:
$(test environment), run $.test
..else:
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:")
\(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)"