Skip to content

Commit

Permalink
nuUnit should be callable from the nu cli, as a nu script and as a st…
Browse files Browse the repository at this point in the history
…andalone via the shebang
  • Loading branch information
NonlinearFruit committed Apr 2, 2024
1 parent eb6bf30 commit b7811fa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nuunit.nu
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
def main [
#!/usr/bin/env nu

export def main [
--test-spec-module-name = "test-spec.nu"
--as-json
] {
Expand Down Expand Up @@ -33,7 +35,7 @@ def run-test-discoverer [module testImportScript] {
| from nuon
}

def discover-tests [module testImportScript] {
export def discover-tests [module testImportScript] {
scope modules
| where name == $module
| get commands
Expand Down
25 changes: 25 additions & 0 deletions test-spec.nu
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ export def "test output is tap compliant" [] {
| verify tap results
}

export def "test can run via nu cli" [] {
use tests/generic-test-spec.nu "verify json results"
let specFile = "tests/generic-test-spec.nu"

(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
| verify json results
}

export def "test can run via nu script" [] {
use tests/generic-test-spec.nu "verify json results"
let specFile = "tests/generic-test-spec.nu"
let script = $"use nuunit.nu *; nuunit --test-spec-module-name ($specFile) --as-json"

^$nu.current-exe --no-config-file -c $script
| verify json results
}

export def "test can run via shebang" [] {
use tests/generic-test-spec.nu "verify json results"
let specFile = "tests/generic-test-spec.nu"

^./nuunit.nu --test-spec-module-name ($specFile) --as-json
| verify json results
}

def run-test-spec [specFile] {
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
| from json
Expand Down
13 changes: 13 additions & 0 deletions tests/generic-test-spec.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export def "test 1" [] {}
export def "test 2" [] {}
export def "test 3" [] {}
export def "test 4" [] {}
export def "test 5" [] {}

export def "verify json results" [] {
let results = $in | from json
print $results
use std assert

assert equal 5 ($results | length)
}

0 comments on commit b7811fa

Please sign in to comment.