Skip to content

Commit b7811fa

Browse files
nuUnit should be callable from the nu cli, as a nu script and as a standalone via the shebang
1 parent eb6bf30 commit b7811fa

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

nuunit.nu

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
def main [
1+
#!/usr/bin/env nu
2+
3+
export def main [
24
--test-spec-module-name = "test-spec.nu"
35
--as-json
46
] {
@@ -33,7 +35,7 @@ def run-test-discoverer [module testImportScript] {
3335
| from nuon
3436
}
3537

36-
def discover-tests [module testImportScript] {
38+
export def discover-tests [module testImportScript] {
3739
scope modules
3840
| where name == $module
3941
| get commands

test-spec.nu

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ export def "test output is tap compliant" [] {
7373
| verify tap results
7474
}
7575

76+
export def "test can run via nu cli" [] {
77+
use tests/generic-test-spec.nu "verify json results"
78+
let specFile = "tests/generic-test-spec.nu"
79+
80+
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
81+
| verify json results
82+
}
83+
84+
export def "test can run via nu script" [] {
85+
use tests/generic-test-spec.nu "verify json results"
86+
let specFile = "tests/generic-test-spec.nu"
87+
let script = $"use nuunit.nu *; nuunit --test-spec-module-name ($specFile) --as-json"
88+
89+
^$nu.current-exe --no-config-file -c $script
90+
| verify json results
91+
}
92+
93+
export def "test can run via shebang" [] {
94+
use tests/generic-test-spec.nu "verify json results"
95+
let specFile = "tests/generic-test-spec.nu"
96+
97+
^./nuunit.nu --test-spec-module-name ($specFile) --as-json
98+
| verify json results
99+
}
100+
76101
def run-test-spec [specFile] {
77102
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
78103
| from json

tests/generic-test-spec.nu

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

0 commit comments

Comments
 (0)