Skip to content

Commit

Permalink
Merge pull request #61 from molovo/next
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
James Dinsdale authored Apr 1, 2017
2 parents a67e085 + f59f681 commit aa63f1b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .zunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ directories:
output: tests/_output
support: tests/_support
time_limit: 15
fail_fast: true
allow_risky: false
5 changes: 4 additions & 1 deletion src/commands/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ function _zunit_init() {
directories:
tests: tests
output: tests/_output
support: tests/_support"
support: tests/_support
time_limit: 0
fail_fast: false
allow_risky: false"

# An example test file
local example="#!/usr/bin/env zunit
Expand Down
49 changes: 34 additions & 15 deletions src/commands/run.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ function _zunit_run_usage() {
echo " zunit run [options] [tests...]"
echo
echo "$(color yellow 'Options:')"
echo " -h, --help Output help text and exit"
echo " -v, --version Output version information and exit"
echo " -f, --fail-fast Stop the test runner immediately after the first failure"
echo " -t, --tap Output results in a TAP compatible format"
echo " --output-text Print results to a text log, in TAP compatible format"
echo " --output-html Print results to a HTML page"
echo " --allow-risky Supress warnings generated for risky tests"
echo " -h, --help Output help text and exit"
echo " -v, --version Output version information and exit"
echo " -f, --fail-fast Stop the test runner immediately after the first failure"
echo " -t, --tap Output results in a TAP compatible format"
echo " --output-text Print results to a text log, in TAP compatible format"
echo " --output-html Print results to a HTML page"
echo " --allow-risky Supress warnings generated for risky tests"
echo " --time-limit <n> Set a time limit of n seconds for each test"
}

###
Expand Down Expand Up @@ -142,16 +143,16 @@ function _zunit_execute_test() {
# the ZSH version is at least 5.1.0, since older versions of ZSH
# are unable to handle asynchronous processes in the way we need
autoload is-at-least
if is-at-least 5.1.0 && [[ -n $zunit_config_time_limit ]]; then
if is-at-least 5.1.0 && [[ -n ${time_limit:#0} ]]; then
# Create another wrapper function around the test
__zunit_async_test_wrapper() {
local pid

# Get the current timestamp, and the time limit, and use those to
# work out the kill time for the sub process
integer time_limit=$(( ${zunit_config_time_limit:-30} * 1000 ))
# Get the current timestamp, and the time limit in ms, and use
# those to work out the kill time for the sub process
integer time_limit_ms=$(( time_limit * 1000 ))
integer time=$(( EPOCHREALTIME * 1000 ))
integer kill_time=$(( $time + $time_limit ))
integer kill_time=$(( $time + $time_limit_ms ))

# Launch the test function asynchronously and store its PID
__zunit_tmp_test_function &
Expand Down Expand Up @@ -189,7 +190,7 @@ function _zunit_execute_test() {

return
elif [[ $state -eq 78 ]]; then
_zunit_error "Test took too long to run. Terminated after ${zunit_config_time_limit:-30} seconds" $output
_zunit_error "Test took too long to run. Terminated after $time_limit seconds" $output

return
elif [[ -z $allow_risky && $state -eq 248 ]]; then
Expand Down Expand Up @@ -439,7 +440,8 @@ function _zunit_run() {
t=tap -tap=tap \
-output-text=output_text \
-output-html=output_html \
-allow-risky=allow_risky
-allow-risky=allow_risky \
-time-limit:=time_limit

# TAP output is enabled
if [[ -n $tap ]] || [[ "$zunit_config_tap" = "true" ]]; then
Expand Down Expand Up @@ -508,6 +510,23 @@ function _zunit_run() {
fi
fi

# Check if fail_fast is specified in the config or as an option
if [[ -z $fail_fast ]] && [[ "$zunit_config_fail_fast" = "true" ]]; then
fail_fast=1
fi

# Check if allow_risky is specified in the config or as an option
if [[ -z $allow_risky ]] && [[ "$zunit_config_allow_risky" = "true" ]]; then
allow_risky=1
fi

# Check if time_limit is specified in the config or as an option
if [[ -n $time_limit ]]; then
shift time_limit
elif [[ -n $zunit_config_time_limit ]]; then
time_limit=$zunit_config_time_limit
fi

arguments=("$@")
testfiles=()

Expand Down Expand Up @@ -536,7 +555,7 @@ function _zunit_run() {
# Loop through each of the test files and run them
local line
local total=0 passed=0 failed=0 errors=0 warnings=0 skipped=0
for testfile in $testfiles; do
for testfile in ${(o)testfiles}; do
_zunit_run_testfile $testfile
done

Expand Down
3 changes: 2 additions & 1 deletion src/zunit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ function _zunit_usage() {
echo " --output-text Print results to a text log, in TAP compatible format"
echo " --output-html Print results to a HTML page"
echo " --allow-risky Supress warnings generated for risky tests"
echo " --time-limit Set a time limit in seconds for each test"
}

###
# Output the version number
###
function _zunit_version() {
echo '0.6.4'
echo '0.7.0'
}

###
Expand Down
31 changes: 19 additions & 12 deletions zunit.zsh-completion
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,43 @@ _zunit() {
typeset -A opt_args
local context state line curcontext="$curcontext"

_arguments \
'1: :_zunit_cmds' \
'*::arg:->args'

_arguments \
'*:tests:_files'

_arguments -A \
'(-h --help)'{-h,--help}'[show help text and exit]' \
'(-v --version)'{-v,--version}'[show version information and exit]' \
'(-f --fail-fast)'{-f,--fail-fast}'[stop execution after the first failure]' \
'(-t --tap)'{-t,--tap}'[output results in a TAP compatible format]' \
'--output-text[Print results to a text log, in TAP compatible format]' \
'--output-html[Print results to a HTML page]' \
'--allow-risky[Supress warnings generated for risky tests]'

_arguments \
'1: :_zunit_cmds' \
'*::arg:->args'
'--output-text[print results to a text log, in TAP compatible format]' \
'--output-html[print results to a HTML page]' \
'--allow-risky[supress warnings generated for risky tests]' \
'--time-limit[set a time limit in seconds for each test]'

case "$state" in
args )
case "$words[1]" in
init )
_arguments -A \
'(-h --help)'{-h,--help}'[show help text and exit]' \
'(-v --version)'{-v,--version}'[show version information and exit]'
'(-t --travis)'{-t,--travis}'[generate a .travis.yml file]'

_arguments \
'*::arg:->args'
;;
run )
_arguments -A \
'(-h --help)'{-h,--help}'[show help text and exit]' \
'(-v --version)'{-v,--version}'[show version information and exit]' \
'(-f --fail-fast)'{-f,--fail-fast}'[stop execution after the first failure]' \
'(-t --tap)'{-t,--tap}'[output results in a TAP compatible format]' \
'--output-text[Print results to a text log, in TAP compatible format]' \
'--output-html[Print results to a HTML page]' \
'--allow-risky[Supress warnings generated for risky tests]'
'--output-text[print results to a text log, in TAP compatible format]' \
'--output-html[print results to a HTML page]' \
'--allow-risky[supress warnings generated for risky tests]' \
'--time-limit[set a time limit in seconds for each test]'

_arguments \
'*:tests:_files'
Expand Down

0 comments on commit aa63f1b

Please sign in to comment.