forked from extern/nushell
stdlib: add assert skip
command to skip test case (#8748)
This commit is contained in:
parent
8a030f3bfc
commit
74283c3ebc
@ -67,6 +67,16 @@ export def "assert error" [
|
||||
}
|
||||
}
|
||||
|
||||
# Skip the current test case
|
||||
#
|
||||
# # Examples
|
||||
#
|
||||
# if $condition { assert skip }
|
||||
export def "assert skip" [] {
|
||||
error make {msg: "ASSERT:SKIP"}
|
||||
}
|
||||
|
||||
|
||||
# Assert $left == $right
|
||||
#
|
||||
# For more documentation see the assert command
|
||||
|
@ -57,8 +57,6 @@ export def test_assert_length [] {
|
||||
assert error { assert length [0, 0] 3 }
|
||||
}
|
||||
|
||||
# export def test_assert_§ [] {
|
||||
# assert §
|
||||
# assert error { assert § }
|
||||
# }
|
||||
|
||||
export def test_assert_skip [] {
|
||||
assert skip # This test case is skipped on purpose
|
||||
}
|
||||
|
@ -6,14 +6,23 @@ use std.nu *
|
||||
#
|
||||
# the output would be like
|
||||
# - "<indentation> x <module> <test>" all in red if failed
|
||||
# - "<indentation> s <module> <test>" all in yellow if skipped
|
||||
# - "<indentation> <module> <test>" all in green if passed
|
||||
def show-pretty-test [indent: int = 4] {
|
||||
let test = $in
|
||||
|
||||
[
|
||||
(" " * $indent)
|
||||
(if $test.pass { ansi green } else { ansi red})
|
||||
(if $test.pass { " " } else { char failed})
|
||||
(match $test.result {
|
||||
"pass" => { ansi green },
|
||||
"skip" => { ansi yellow },
|
||||
_ => { ansi red }
|
||||
})
|
||||
(match $test.result {
|
||||
"pass" => " ",
|
||||
"skip" => "s",
|
||||
_ => { char failed }
|
||||
})
|
||||
" "
|
||||
$"($test.module) ($test.name)"
|
||||
(ansi reset)
|
||||
@ -105,18 +114,33 @@ def main [
|
||||
log info $"Running tests in ($module.name)"
|
||||
$module.tests | each {|test|
|
||||
log debug $"Running test ($test.name)"
|
||||
let did_pass = (try {
|
||||
nu -c $'use ($test.file) ($test.name); ($test.name)'
|
||||
true
|
||||
} catch { false })
|
||||
|
||||
$test | merge ({pass: $did_pass})
|
||||
nu -c $'
|
||||
use ($test.file) ($test.name)
|
||||
try {
|
||||
($test.name)
|
||||
} catch { |err|
|
||||
if $err.msg == "ASSERT:SKIP" {
|
||||
exit 2
|
||||
} else {
|
||||
$err | get raw
|
||||
}
|
||||
}
|
||||
'
|
||||
let result = match $env.LAST_EXIT_CODE {
|
||||
0 => "pass",
|
||||
2 => "skip",
|
||||
_ => "fail",
|
||||
}
|
||||
if $result == "skip" {
|
||||
log warning $"Test case ($test.name) is skipped"
|
||||
}
|
||||
$test | merge ({result: $result})
|
||||
}
|
||||
}
|
||||
| flatten
|
||||
)
|
||||
|
||||
if not ($tests | where not pass | is-empty) {
|
||||
if not ($tests | where result == "fail" | is-empty) {
|
||||
let text = ([
|
||||
$"(ansi purple)some tests did not pass (char lparen)see complete errors above(char rparen):(ansi reset)"
|
||||
""
|
||||
|
Loading…
Reference in New Issue
Block a user