Skip to content

Commit

Permalink
First nuUnit test for nuUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
NonlinearFruit committed Mar 28, 2024
1 parent 9d76029 commit 733420d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
22 changes: 13 additions & 9 deletions nuunit.nu
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
def main [] {
discover-tests
def main [--test-spec-module-name = "test-spec.nu"] {
if (not ($test_spec_module_name | path exists)) {
return $"Invalid test spec module: ($test_spec_module_name)"
}
discover-tests $test_spec_module_name
| run-tests
| output-tests
}

def discover-tests [] {
def discover-tests [testSpecModuleName] {
let module = $testSpecModuleName | str replace '.nu' ''
run-nushell [
--commands
'use test-spec.nu
$"use ($testSpecModuleName)
scope modules
| where name == "test-spec"
| where name == '($module)'
| get commands
| flatten
| where name =~ "^test"
| where name =~ '^test'
| get name
| enumerate
| each {|it|
{
id: ($it.index + 1)
id: \($it.index + 1)
name: $it.item
exec: $"use test-spec.nu; try {test-spec ($it.item)} catch {|err| print -e $err.msg; exit 1}"
exec: $'use ($testSpecModuleName) *; try {\($it.item)} catch {|err| print -e $err.debug; exit 1}'
}
}
| to nuon'
| to nuon"
]
| from nuon
}
Expand Down
7 changes: 7 additions & 0 deletions test-spec.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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)
}

0 comments on commit 733420d

Please sign in to comment.