diff --git a/src/commands/run.zsh b/src/commands/run.zsh index 078f552..9207233 100644 --- a/src/commands/run.zsh +++ b/src/commands/run.zsh @@ -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 diff --git a/src/helpers.zsh b/src/helpers.zsh index 9cf55db..b634566 100644 --- a/src/helpers.zsh +++ b/src/helpers.zsh @@ -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 ### diff --git a/tests/helpers.zunit b/tests/helpers.zunit new file mode 100644 index 0000000..04d2077 --- /dev/null +++ b/tests/helpers.zunit @@ -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' +}