mirror of
https://github.com/zunit-zsh/zunit.git
synced 2026-09-10 06:36:15 -04:00
Add new pass, fail and error helper methods
This commit is contained in:
parent
8ccc47e697
commit
6f297fbcc7
|
|
@ -167,6 +167,7 @@ function _zunit_execute_test() {
|
|||
# The kill time has been reached, kill the child process,
|
||||
# and exit the wrapper function
|
||||
kill -9 $pid >/dev/null 2>&1
|
||||
echo "Test took too long to run. Terminated after $time_limit seconds"
|
||||
exit 78
|
||||
fi
|
||||
done
|
||||
|
|
@ -191,7 +192,7 @@ function _zunit_execute_test() {
|
|||
|
||||
return
|
||||
elif [[ $state -eq 78 ]]; then
|
||||
_zunit_error "Test took too long to run. Terminated after $time_limit seconds" $output
|
||||
_zunit_error $output
|
||||
|
||||
return
|
||||
elif [[ -z $allow_risky && $state -eq 248 ]]; then
|
||||
|
|
|
|||
|
|
@ -158,6 +158,37 @@ function assert() {
|
|||
IFS=$oldIFS
|
||||
}
|
||||
|
||||
###
|
||||
# Mark the current test as passed
|
||||
###
|
||||
function pass() {
|
||||
# Exit code 0 will end the test, and mark is as passed. The reason for
|
||||
# skipping is echoed to stdout first, so that it can be picked up by the
|
||||
# error handler
|
||||
exit 0
|
||||
}
|
||||
|
||||
###
|
||||
# Mark the current test as failed
|
||||
###
|
||||
function fail() {
|
||||
# Any non-zero exit code without special meaning will mark the test as failed.
|
||||
# The failure message is echoed to stdout first, so that it can be picked up
|
||||
# by the error handler
|
||||
echo "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
###
|
||||
# Mark the current test as skipped
|
||||
###
|
||||
function error() {
|
||||
# Exit code 78 will end the test, and report an error. The error message
|
||||
# is echoed to stdout first, so that it can be picked up by the error handler
|
||||
echo "$@"
|
||||
exit 78
|
||||
}
|
||||
|
||||
###
|
||||
# Mark the current test as skipped
|
||||
###
|
||||
|
|
|
|||
29
tests/helpers.zunit
Normal file
29
tests/helpers.zunit
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
@test 'Test pass helper' {
|
||||
run pass
|
||||
|
||||
assert $state equals 0
|
||||
assert "$output" is_empty
|
||||
}
|
||||
|
||||
@test 'Test fail helper' {
|
||||
run fail 'The failure message'
|
||||
|
||||
assert $state equals 1
|
||||
assert "$output" same_as 'The failure message'
|
||||
}
|
||||
|
||||
@test 'Test error helper' {
|
||||
run error 'The error message'
|
||||
|
||||
assert $state equals 78
|
||||
assert "$output" same_as 'The error message'
|
||||
}
|
||||
|
||||
@test 'Test skip helper' {
|
||||
run skip 'The skip message'
|
||||
|
||||
assert $state equals 48
|
||||
assert "$output" same_as 'The skip message'
|
||||
}
|
||||
Loading…
Reference in a new issue