-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtest.ngs
executable file
·52 lines (44 loc) · 1.26 KB
/
test.ngs
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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ngs
tests_counter = 0
doc Mark Exception objects which are coming out of successful assert()
F assert(f:Fun, t:Type, msg:Str="Assertion failed") {
guard t <= Exception
r = super(f, t, msg)
r.meta().test_ngs = true
r
}
F perform_test(test_code:Str) {
F ok(x) throw Error("Don't know how to check test result of type ${x.Type()}")
F ok(x:Bool) x
F ok(ms:MatchSuccess) true
F ok(e:Exception) { e.meta() =~ {'test_ngs': true} }
global tests_counter
echo("+ Test: $test_code")
c = "{ F() { $test_code }() }"
program_bytecode = compile(c, '<test>')
program_func = load(program_bytecode, '<test>')
result = program_func()
not(ok(result)) throws Error("Test failed: $test_code. Returned $result")
tests_counter += 1
}
F perform_tests_in_file(file:Str) {
# TODO: also other files
File(file).lines(F(line) {
# dump(line)
if m = line ~ /^\s*TEST (.*?)$/ {
test_code = m[1]
perform_test(test_code)
}
})
}
if ARGV {
files = ARGV
} else {
base_dir = ENV.get('NGS_TESTS_BASE_DIR', `line: dirname ${realpath(ARGV0)}` / 'lib')
files = %[lang-tests.ngs stdlib.ngs].map(base_dir / X) + ``find "${base_dir}/autoload" -name '*.ngs'``
}
files.each(perform_tests_in_file)
if not(ARGV) {
assert(tests_counter > 540)
}
echo("OK. Tests: ${tests_counter}")