Skip to content

Commit 4f74937

Browse files
Use actual test spec files for simplicity and as examples
1 parent 099b6ef commit 4f74937

8 files changed

+107
-53
lines changed

nuunit.nu

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
def main [
22
--test-spec-module-name = "test-spec.nu"
3-
--test-spec-module-script:string
43
--as-json
54
] {
6-
if (not ($test_spec_module_name | path exists) and ($test_spec_module_script | is-empty)) {
5+
if (not ($test_spec_module_name | path exists)) {
76
return $"Invalid test spec module: ($test_spec_module_name)"
87
}
9-
let module = $test_spec_module_name | str replace '.nu' ''
10-
let importScript = $test_spec_module_script | default $"use ($test_spec_module_name) *"
8+
let module = $test_spec_module_name | split row '/' | last | str replace '.nu' ''
9+
let importScript = $"use ($test_spec_module_name) *"
1110
let testResults = discover-tests $module $importScript
1211
| run-tests
1312

test-spec.nu

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,66 @@ export def "test handles when spec does not exist" [] {
77
}
88

99
export def "test exit with error when test errors" [] {
10-
let specScript = "
11-
export module test {
12-
export def test_that_fails [] { exit 400 }
13-
}
14-
"
10+
use tests/test-spec-that-errs.nu "verify json results"
11+
let specFile = "tests/test-spec-that-errs.nu"
12+
1513
do {
16-
^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name "test" --test-spec-module-script $specScript
14+
^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile
1715
}
1816
| complete
1917
| assert not equal 0 ($in.exit_code)
2018
}
2119

22-
export def "test handles when no tests" [] {
23-
let specScript = "
24-
export module test {
25-
}
26-
use test *
27-
"
28-
(^$nu.current-exe --no-config-file nuunit.nu
29-
--test-spec-module-name "test"
30-
--test-spec-module-script $specScript
31-
--as-json)
20+
export def "test when there are no tests everything still works" [] {
21+
use tests/test-spec-with-zero-tests.nu "verify json results"
22+
let specFile = "tests/test-spec-with-zero-tests.nu"
23+
24+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
3225
| from json
33-
| length
34-
| assert equal 0 $in
26+
| verify json results
3527
}
3628

37-
export def "test runs tests from spec script" [] {
38-
let specScript = "
39-
export module test {
40-
export def test_the_stuff [] {}
41-
export def test_the_other [] {}
42-
}
43-
use test *
44-
"
45-
(^$nu.current-exe --no-config-file nuunit.nu
46-
--test-spec-module-name "test"
47-
--test-spec-module-script $specScript
48-
--as-json)
29+
export def "test when there is one test everything still works" [] {
30+
use tests/test-spec-with-one-test.nu "verify json results"
31+
let specFile = "tests/test-spec-with-one-test.nu"
32+
33+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
34+
| from json
35+
| verify json results
36+
}
37+
38+
export def "test when there are two tests everything still works" [] {
39+
use tests/test-spec-with-two-tests.nu "verify json results"
40+
let specFile = "tests/test-spec-with-two-tests.nu"
41+
42+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
4943
| from json
50-
| length
51-
| assert equal 2 $in
44+
| verify json results
5245
}
5346

5447
export def "test when test errors runner keeps chugging" [] {
55-
let specScript = "
56-
export module test {
57-
export def test_the_stuff [] {}
58-
}
59-
use test *
60-
"
61-
(^$nu.current-exe --no-config-file nuunit.nu
62-
--test-spec-module-name "test"
63-
--test-spec-module-script $specScript
64-
--as-json)
65-
| print
48+
use tests/test-spec-that-errs.nu "verify json results"
49+
let specFile = "tests/test-spec-that-errs.nu"
50+
51+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
52+
| from json
53+
| verify json results
6654
}
6755

68-
export def "not starting with test means the command will not run" [] {
69-
"why would you run this?"
70-
exit 1
56+
export def "test when exported command does not match pattern it is not included" [] {
57+
use tests/test-spec-with-exported-commands-that-are-not-tests.nu "verify json results"
58+
let specFile = "tests/test-spec-with-exported-commands-that-are-not-tests.nu"
59+
60+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
61+
| from json
62+
| verify json results
7163
}
7264

73-
def "test private commands are not magically ran" [] {
74-
"why would you run this?"
75-
exit 1
65+
export def "test private commands that look likes tests are not included" [] {
66+
use tests/test-spec-with-private-commands-that-look-like-tests.nu "verify json results"
67+
let specFile = "tests/test-spec-with-private-commands-that-look-like-tests.nu"
68+
69+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
70+
| from json
71+
| verify json results
7672
}

tests/test-spec-that-errs.nu

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export def "test that is broken" [] {
2+
error make { msg: "It broke!" }
3+
}
4+
5+
export def "verify json results" [] {
6+
let results = $in
7+
use std assert
8+
9+
assert equal 1 ($results | length)
10+
assert not equal 0 ($results.exit_code)
11+
assert not equal "" ($results.stderr)
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export def "not starting with test means the command will not run" [] {
2+
"why would you run this?"
3+
exit 1
4+
}
5+
6+
export def "verify json results" [] {
7+
let results = $in
8+
use std assert
9+
10+
assert equal 0 ($results | length)
11+
}

tests/test-spec-with-one-test.nu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export def "test 1" [] {}
2+
3+
export def "verify json results" [] {
4+
let results = $in
5+
use std assert
6+
7+
assert equal 1 ($results | length)
8+
}
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def "test private command that looks like a test is not included" [] {
2+
"why would you run this?"
3+
exit 1
4+
}
5+
6+
export def "verify json results" [] {
7+
let results = $in
8+
use std assert
9+
10+
assert equal 0 ($results | length)
11+
}

tests/test-spec-with-two-tests.nu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export def "test 1" [] {}
2+
export def "test 2" [] {}
3+
4+
export def "verify json results" [] {
5+
let results = $in
6+
use std assert
7+
8+
assert equal 2 ($results | length)
9+
}
10+

tests/test-spec-with-zero-tests.nu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export def "verify json results" [] {
2+
let results = $in
3+
use std assert
4+
5+
assert equal 0 ($results | length)
6+
}

0 commit comments

Comments
 (0)