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
|
# Assert $left == $right
|
||||||
#
|
#
|
||||||
# For more documentation see the assert command
|
# For more documentation see the assert command
|
||||||
|
@ -57,8 +57,6 @@ export def test_assert_length [] {
|
|||||||
assert error { assert length [0, 0] 3 }
|
assert error { assert length [0, 0] 3 }
|
||||||
}
|
}
|
||||||
|
|
||||||
# export def test_assert_§ [] {
|
export def test_assert_skip [] {
|
||||||
# assert §
|
assert skip # This test case is skipped on purpose
|
||||||
# assert error { assert § }
|
}
|
||||||
# }
|
|
||||||
|
|
||||||
|
@ -6,14 +6,23 @@ use std.nu *
|
|||||||
#
|
#
|
||||||
# the output would be like
|
# the output would be like
|
||||||
# - "<indentation> x <module> <test>" all in red if failed
|
# - "<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
|
# - "<indentation> <module> <test>" all in green if passed
|
||||||
def show-pretty-test [indent: int = 4] {
|
def show-pretty-test [indent: int = 4] {
|
||||||
let test = $in
|
let test = $in
|
||||||
|
|
||||||
[
|
[
|
||||||
(" " * $indent)
|
(" " * $indent)
|
||||||
(if $test.pass { ansi green } else { ansi red})
|
(match $test.result {
|
||||||
(if $test.pass { " " } else { char failed})
|
"pass" => { ansi green },
|
||||||
|
"skip" => { ansi yellow },
|
||||||
|
_ => { ansi red }
|
||||||
|
})
|
||||||
|
(match $test.result {
|
||||||
|
"pass" => " ",
|
||||||
|
"skip" => "s",
|
||||||
|
_ => { char failed }
|
||||||
|
})
|
||||||
" "
|
" "
|
||||||
$"($test.module) ($test.name)"
|
$"($test.module) ($test.name)"
|
||||||
(ansi reset)
|
(ansi reset)
|
||||||
@ -105,18 +114,33 @@ def main [
|
|||||||
log info $"Running tests in ($module.name)"
|
log info $"Running tests in ($module.name)"
|
||||||
$module.tests | each {|test|
|
$module.tests | each {|test|
|
||||||
log debug $"Running test ($test.name)"
|
log debug $"Running test ($test.name)"
|
||||||
let did_pass = (try {
|
nu -c $'
|
||||||
nu -c $'use ($test.file) ($test.name); ($test.name)'
|
use ($test.file) ($test.name)
|
||||||
true
|
try {
|
||||||
} catch { false })
|
($test.name)
|
||||||
|
} catch { |err|
|
||||||
$test | merge ({pass: $did_pass})
|
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
|
| flatten
|
||||||
)
|
)
|
||||||
|
|
||||||
if not ($tests | where not pass | is-empty) {
|
if not ($tests | where result == "fail" | is-empty) {
|
||||||
let text = ([
|
let text = ([
|
||||||
$"(ansi purple)some tests did not pass (char lparen)see complete errors above(char rparen):(ansi reset)"
|
$"(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