application/octet-stream
•
2.52 KB
•
62 lines
#!/usr/bin/env nujel
[def test/beginning [time/milliseconds]]
[def test/testsuite-errors 0]
[defun prog-str [fun-color i path start]
[cat "[" [fun-color [string/pad-start i 2]]
"/" [string/pad-start test/count 2]
"] " [string/pad-end [cut path 2 [length path]] 32]
[if start [cat " " [ansi-blue [string/pad-start [- [time/milliseconds] start] 5]] "ms"] #nil]]]
[when [not [tree/has? repl/options :only-test-suite]]
[println [ansi-purple "First we test the basic functions of the runtime."]]]
[for-each [directory/read-relative "tests/suite"] file/eval]
[when [tree/has? repl/options :only-test-suite]
[exit [if [ref repl/options :bytecoded]
[test-run-bytecode]
[test-run]]]]
[if [ref repl/options :bytecoded]
[set! test/testsuite-errors [test-run-bytecode]]
[set! test/testsuite-errors [test-run]]]
[println [ansi-green "Great, Now we can do some more complicated and thorough tests."]]
[def test/slow [or [ref repl/options :slow-test] #f]]
[def test/ridiculous [or [ref repl/options :ridiculous-test] #f]]
[def test/start [time/milliseconds]]
[def test/success 0]
[def test/errors 0]
[def i]
[defun file/test [path]
[++ i]
[def test/start/file [time/milliseconds]]
[try [\ [err]
[print "\r"]
[println [prog-str ansi-red i path test/start/file]]
[++ test/errors]
[display/error err]
[newline]]
[print [prog-str ansi-yellow i path #nil]]
[file/eval path [ω]]
[++ test/success]
[print "\r"]
[println [prog-str ansi-green i path test/start/file]]]]
[def test-paths [list/sort [filter [append [directory/read-relative "./tests/fast"]
[when test/slow [directory/read-relative "./tests/slow"]]
[when test/ridiculous [directory/read-relative "./tests/ridiculous"]]]
[path/ext?! "nuj"]]]]
[def test/count [length test-paths]]
[for-each test-paths file/test]
[newline]
[def dur [- [time/milliseconds] test/start]]
[if [and [> test/success 0] [zero? test/errors]]
[do [println [cat [ansi-green "AoC Tests succeeded"] " - [" [ansi-green test/success] " / " [ansi-red test/errors] "] in " dur "ms"]]]
[do [println [cat [ansi-red "AoC Tests failed"] " - [" [ansi-green test/success] " / " [ansi-red test/errors] "] in " dur "ms"]]]]
[println [cat "Running everything took " [ansi-blue [- [time/milliseconds] test/beginning]] "ms"]]
[exit test/errors + test/testsuite-errors]