-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.ty
84 lines (64 loc) · 1.57 KB
/
test.ty
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os (..)
import sh (sh)
import chalk (..)
import time
import tp (ThreadPool)
import ty
let start = time.utime()
let passed = Sync(0)
let failed = Sync(0)
let timedOut = Sync(0)
let g = pen(bold, green)
let r = pen(bold, red)
let m = pen(bold, brightMagenta)
let b = pen(bold, blue)
let TY_PATH = getenv('TY_PATH') ?? ty.executable
function getTyCommand(test) {
#|if __windows__
"{TY_PATH} tests\\{test}"
#|else
"{TY_PATH} tests/{test}"
#|]
}
function doTest(name) {
let testStart = time.utime()
let result = match sh(getTyCommand(name), timeoutMs: 2000) {
nil => do {
timedOut += 1
m('TIMEOUT')
},
&strip ~> 'PASS' => do {
passed += 1
let elapsedMs = (time.utime() - testStart) / 1000.0
let elapsed = match elapsedMs <=> 100.0 {
1 => "({elapsedMs / 1000.0:.2g}s)",
_ => "({elapsedMs:d}ms)",
}
"{g('PASS')} {yellow(elapsed)}"
},
x => do {
failed += 1
r('FAIL')
}
}
print("{b(name.comb(/\.ty$/).padLeft(16))} ... {result}")
}
let pool = ThreadPool(16, doTest)
let fs = []
for test in listdir('tests') {
fs.push(pool.submit(test))
}
fs.map(&wait)
print()
let elapsedSec = (time.utime() - start) / (1000.0 * 1000.0)
if passed > 0 {
print("{g('Passed')}: {g(passed)}")
}
if failed > 0 {
print("{r('Failed')}: {r(failed)}")
}
if timedOut > 0 {
print("{m('Timed out')}: {m(timedOut)}")
}
print()
print("{b('Elapsed')}: {b(str(elapsedSec) + 's')}")