mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
rewrite the runner in a structured way
This commit is contained in:
parent
ec85b6fd3f
commit
9c12211564
1 changed files with 49 additions and 18 deletions
|
@ -1,28 +1,59 @@
|
||||||
use std.nu *
|
use std.nu *
|
||||||
|
|
||||||
def main [] {
|
# show a test record in a pretty way
|
||||||
for test_file in (ls ($env.FILE_PWD | path join "test_*.nu") -f | get name) {
|
#
|
||||||
let $module_name = ($test_file | path parse).stem
|
# `$in` must be a `record<file: string, module: string, name: string, pass: bool>`.
|
||||||
|
#
|
||||||
|
# the output would be like
|
||||||
|
# - "<indentation> x <module>::<test>" all in red if failed
|
||||||
|
# - "<indentation> <module>::<test>" all in green if passed
|
||||||
|
def show-pretty-test [indent: int = 4] {
|
||||||
|
let test = $in
|
||||||
|
|
||||||
log info $"Run tests in ($module_name) module"
|
[
|
||||||
|
(" " * $indent)
|
||||||
|
(if $test.pass { ansi green } else { ansi red})
|
||||||
|
(if $test.pass { " " } else { char failed})
|
||||||
|
" "
|
||||||
|
$"($test.module)::($test.name)"
|
||||||
|
ansi reset
|
||||||
|
] | str join
|
||||||
|
}
|
||||||
|
|
||||||
|
def main [] {
|
||||||
let tests = (
|
let tests = (
|
||||||
nu -c $'use ($test_file) *; $nu.scope.commands | select name module_name | to nuon'
|
ls ($env.FILE_PWD | path join "test_*.nu") | each {|row| {file: $row.name name: ($row.name | path parse | get stem)}}
|
||||||
|
| upsert test {|module|
|
||||||
|
nu -c $'use ($module.file) *; $nu.scope.commands | select name module_name | to nuon'
|
||||||
| from nuon
|
| from nuon
|
||||||
| where module_name == $module_name
|
| where module_name == $module.name
|
||||||
| where ($it.name | str starts-with "test_")
|
| where ($it.name | str starts-with "test_")
|
||||||
| get name
|
| get name
|
||||||
|
}
|
||||||
|
| flatten
|
||||||
|
| rename file module name
|
||||||
|
| upsert pass {|test|
|
||||||
|
log info $"Run test ($test.module) ($test.name)"
|
||||||
|
try {
|
||||||
|
nu -c $'use ($test.file) ($test.name); ($test.name)'
|
||||||
|
true
|
||||||
|
} catch { false }
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
for test_case in $tests {
|
if not ($tests | where not pass | is-empty) {
|
||||||
log debug $"Run test ($module_name) ($test_case)"
|
let text = ([
|
||||||
try {
|
$"(ansi purple)some tests did not pass (char lparen)see complete errors above(char rparen):(ansi reset)"
|
||||||
nu -c $'use ($test_file) ($test_case); ($test_case)'
|
""
|
||||||
} catch { error make {
|
($tests | each {|test| ($test | show-pretty-test 8)} | str join "\n")
|
||||||
msg: $"(ansi red)std::tests::test_failed(ansi reset)"
|
""
|
||||||
|
] | str join "\n")
|
||||||
|
|
||||||
|
error make {
|
||||||
|
msg: $"(ansi red)std::tests::some_tests_failed(ansi reset)"
|
||||||
label: {
|
label: {
|
||||||
text: $"($module_name)::($test_case) failed."
|
text: $text
|
||||||
}
|
}
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue