aboutsummaryrefslogtreecommitdiff
path: root/tools/test.nom
blob: 6caea8737716a41fb844e2f65daba8cb9b076f0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env nomsu -V3.5.5.6
#
    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 "lib/os.nom"
use "lib/consolecolor.nom"

%args = (command line args)
if (%args.1 == "-v"):
    remove index 1 from %args
    %verbose = (yes)

# Make sure all the files get run
for %path in (command line args):
    for file %filename in %path:
        if (%filename matches "%.nom$"): use %filename

for %path in (command line args): use %path
%tests = ((=lua "Source:from_string(\%s)") = %t for %s = %t in (tests))
for %path in (command line args):
    for file %filename in %path:
        unless (%filename matches "%.nom$"): do next %filename
        %file_tests = []
        for %src = %test in %tests:
            if (%src.filename == %filename):
                add {test:%test, source:%src} to %file_tests
        
        unless (%file_tests is empty):
            sort %file_tests by % -> %.source
            lua> "io.write('[ .. ] ', \%filename); io.flush()"
            if %verbose: say ""
            for % in %file_tests:
                if %verbose:
                    say "    \(yellow (%.test with "\n" replaced by "\n    "))"
                run %.test
            
            if %verbose: say (green "PASS")
            ..else:
                say "\r[\(green "PASS")"