-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-spec.nu
131 lines (100 loc) · 3.98 KB
/
test-spec.nu
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use std assert
export def "test handles when spec does not exist" [] {
let specFile = "not real"
^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile
| assert equal $"Invalid test spec module: ($specFile)" ($in | str trim)
}
export def "test exit with error when test errors" [] {
let specFile = "tests/test-spec-that-errs.nu"
do {
^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile
}
| complete
| assert not equal 0 ($in.exit_code)
}
export def "test when there are no tests everything still works" [] {
use tests/test-spec-with-zero-tests.nu "verify json results"
let specFile = "tests/test-spec-with-zero-tests.nu"
run-test-spec $specFile
| verify json results
}
export def "test when there is one test everything still works" [] {
use tests/test-spec-with-one-test.nu "verify json results"
let specFile = "tests/test-spec-with-one-test.nu"
run-test-spec $specFile
| verify json results
}
export def "test when there are two tests everything still works" [] {
use tests/test-spec-with-two-tests.nu "verify json results"
let specFile = "tests/test-spec-with-two-tests.nu"
run-test-spec $specFile
| verify json results
}
export def "test when test errors runner keeps chugging" [] {
use tests/test-spec-that-errs.nu "verify json results"
let specFile = "tests/test-spec-that-errs.nu"
run-test-spec $specFile
| verify json results
}
export def "test when exported command does not match pattern it is not included" [] {
use tests/test-spec-with-exported-commands-that-are-not-tests.nu "verify json results"
let specFile = "tests/test-spec-with-exported-commands-that-are-not-tests.nu"
run-test-spec $specFile
| verify json results
}
export def "test private commands that look likes tests are not included" [] {
use tests/test-spec-with-private-commands-that-look-like-tests.nu "verify json results"
let specFile = "tests/test-spec-with-private-commands-that-look-like-tests.nu"
run-test-spec $specFile
| verify json results
}
export def "test output is tap compliant" [] {
use tests/test-spec-outputs-tap.nu "verify tap results"
let specFile = "tests/test-spec-outputs-tap.nu"
^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile
| verify tap results
}
export def "test can run via nu cli" [] {
use tests/generic-test-spec.nu "verify json results"
let specFile = "tests/generic-test-spec.nu"
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
| verify json results
}
export def "test can run via nu script" [] {
use tests/generic-test-spec.nu "verify json results"
let specFile = "tests/generic-test-spec.nu"
let script = $"use nuunit.nu *; nuunit --test-spec-module-name ($specFile) --as-json"
^$nu.current-exe --no-config-file -c $script
| verify json results
}
export def "test can run via shebang" [] {
use tests/generic-test-spec.nu "verify json results"
let specFile = "tests/generic-test-spec.nu"
^./nuunit.nu --test-spec-module-name ($specFile) --as-json
| verify json results
}
export def "test that the before each passes context to a test" [] {
use tests/test-spec-with-before-each.nu "verify json results"
let specFile = "tests/test-spec-with-before-each.nu"
run-test-spec $specFile
| verify json results
}
export def "test that the after each passes context to a test" [] {
use tests/test-spec-with-after-each.nu "verify json results"
let specFile = "tests/test-spec-with-after-each.nu"
run-test-spec $specFile
| verify json results
}
export def "test that importing all nuunit commands is gracefully handled" [] {
use std assert
let specFile = "tests/generic-test-spec.nu"
let results = do {
^$nu.current-exe --no-config-file -c $'use nuunit.nu; nuunit --test-spec-module-name ($specFile)'
}
| complete
assert (0 == $results.exit_code)
}
def run-test-spec [specFile] {
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
| from json
}