Skip to content

Commit 67fa2a9

Browse files
Gracefully handled when nuunit commands are not imported (#11)
1 parent 8c10119 commit 67fa2a9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

nuunit.nu

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export def main [
44
--test-spec-module-name = "test-spec.nu"
55
--as-json
66
] {
7-
if (not ($test_spec_module_name | path exists)) {
7+
if (is-not-valid-test-spec $test_spec_module_name) {
88
return $"Invalid test spec module: ($test_spec_module_name)"
99
}
1010
let module = $test_spec_module_name | split row '/' | last | str replace '.nu' ''
@@ -24,17 +24,30 @@ export def main [
2424
| exit $in
2525
}
2626

27+
def is-not-valid-test-spec [spec] {
28+
not ($spec | path exists)
29+
}
30+
2731
def run-test-discoverer [module testImportScript] {
2832
run-nushell [
2933
--commands
3034
$"($testImportScript)
31-
(view source discover-tests)
35+
(inline-source-code discover-tests)
3236
discover-tests '($module)' '($testImportScript)'
3337
| to nuon"
3438
]
3539
| from nuon
3640
}
3741

42+
def inline-source-code [command] {
43+
try {
44+
view source $command
45+
} catch {
46+
view source $"nuunit ($command)"
47+
| str replace 'nuunit ' ''
48+
}
49+
}
50+
3851
export def discover-tests [module testImportScript] {
3952
scope modules
4053
| where name == $module

test-spec.nu

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ export def "test that the after each passes context to a test" [] {
114114
| verify json results
115115
}
116116

117+
export def "test that importing all nuunit commands is gracefully handled" [] {
118+
use std assert
119+
let specFile = "tests/generic-test-spec.nu"
120+
121+
let results = do {
122+
^$nu.current-exe --no-config-file -c $'use nuunit.nu; nuunit --test-spec-module-name ($specFile)'
123+
}
124+
| complete
125+
126+
assert (0 == $results.exit_code)
127+
}
128+
117129
def run-test-spec [specFile] {
118130
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
119131
| from json

0 commit comments

Comments
 (0)