Skip to content

Commit 733420d

Browse files
First nuUnit test for nuUnit
1 parent 9d76029 commit 733420d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

nuunit.nu

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
def main [] {
2-
discover-tests
1+
def main [--test-spec-module-name = "test-spec.nu"] {
2+
if (not ($test_spec_module_name | path exists)) {
3+
return $"Invalid test spec module: ($test_spec_module_name)"
4+
}
5+
discover-tests $test_spec_module_name
36
| run-tests
47
| output-tests
58
}
69

7-
def discover-tests [] {
10+
def discover-tests [testSpecModuleName] {
11+
let module = $testSpecModuleName | str replace '.nu' ''
812
run-nushell [
913
--commands
10-
'use test-spec.nu
14+
$"use ($testSpecModuleName)
1115
1216
scope modules
13-
| where name == "test-spec"
17+
| where name == '($module)'
1418
| get commands
1519
| flatten
16-
| where name =~ "^test"
20+
| where name =~ '^test'
1721
| get name
1822
| enumerate
1923
| each {|it|
2024
{
21-
id: ($it.index + 1)
25+
id: \($it.index + 1)
2226
name: $it.item
23-
exec: $"use test-spec.nu; try {test-spec ($it.item)} catch {|err| print -e $err.msg; exit 1}"
27+
exec: $'use ($testSpecModuleName) *; try {\($it.item)} catch {|err| print -e $err.debug; exit 1}'
2428
}
2529
}
26-
| to nuon'
30+
| to nuon"
2731
]
2832
| from nuon
2933
}

test-spec.nu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std assert
2+
3+
export def "test handles when spec does not exist" [] {
4+
let specFile = "not real"
5+
^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile
6+
| assert equal $"Invalid test spec module: ($specFile)" ($in | str trim)
7+
}

0 commit comments

Comments
 (0)