(67 lines)
1 #!/usr/bin/env nomsu -V7.0.02 ###3 Tool to run all tests in a file (i.e. the code block inside a call to 'test $'). Usage:4 nomsu tools/test.nom file1 file2 directory1 ...6 use "filesystem"7 use "consolecolor"8 use "commandline"10 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~12 command line program with $args:13 for ($i = $filename) in $args.extras:14 $file = (read file $filename)15 unless $file:16 fail "Couldn't find \$filename"17 $(test environment) = (new environment)18 $(test environment), export $filename19 $version =20 $file, matching ("21 #![^22 ]* nomsu %-V[ ]*([%d.]*)23 ")24 $file_tests = []25 for ($src = $test) in (nomsu environment, Module $filename).TESTS:26 if $version:27 $test = ("28 #!/usr/bin/env nomsu -V\$version29 \$test30 ")31 $file_tests, add {.test = $test, .source = $src}33 unless ($file_tests is empty):34 sort $file_tests by $ -> $.source35 say "[ .. ] \$filename" inline36 $io.flush()37 if $args.v: say ""38 $failures = []39 for $ in $file_tests:40 if $args.v:41 say " \(yellow ($.test, with "\n" -> "\n "))"43 if $args.e:44 $(test environment), run $.test45 ..else:46 try:47 $(test environment), run $.test48 ..if it fails with $msg:49 $src = ($Source, from string $.source)50 $l1 = ($file, line number at $src.start)51 $l2 = ($file, line number at $src.stop)52 $failures, add ("53 \(yellow "\($src.filename):\($l1)-\$l2:")54 \(bright (red ($msg, indented)))55 ")57 if ($failures is empty):58 if $args.v:59 say (green "PASS")60 ..else:61 say "\r[\(green "PASS")"62 ..else:63 if $args.v:64 say (red (bright "FAIL"))65 ..else:66 say "\r[\(red (bright "FAIL"))"67 say "\($failures, joined with "\n", indented)"