Skip to content

Commit aa63f1b

Browse files
author
James Dinsdale
authored
Merge pull request #61 from molovo/next
v0.7.0
2 parents a67e085 + f59f681 commit aa63f1b

5 files changed

Lines changed: 61 additions & 29 deletions

File tree

.zunit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ directories:
44
output: tests/_output
55
support: tests/_support
66
time_limit: 15
7+
fail_fast: true
8+
allow_risky: false

src/commands/init.zsh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ function _zunit_init() {
4747
directories:
4848
tests: tests
4949
output: tests/_output
50-
support: tests/_support"
50+
support: tests/_support
51+
time_limit: 0
52+
fail_fast: false
53+
allow_risky: false"
5154

5255
# An example test file
5356
local example="#!/usr/bin/env zunit

src/commands/run.zsh

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ function _zunit_run_usage() {
1010
echo " zunit run [options] [tests...]"
1111
echo
1212
echo "$(color yellow 'Options:')"
13-
echo " -h, --help Output help text and exit"
14-
echo " -v, --version Output version information and exit"
15-
echo " -f, --fail-fast Stop the test runner immediately after the first failure"
16-
echo " -t, --tap Output results in a TAP compatible format"
17-
echo " --output-text Print results to a text log, in TAP compatible format"
18-
echo " --output-html Print results to a HTML page"
19-
echo " --allow-risky Supress warnings generated for risky tests"
13+
echo " -h, --help Output help text and exit"
14+
echo " -v, --version Output version information and exit"
15+
echo " -f, --fail-fast Stop the test runner immediately after the first failure"
16+
echo " -t, --tap Output results in a TAP compatible format"
17+
echo " --output-text Print results to a text log, in TAP compatible format"
18+
echo " --output-html Print results to a HTML page"
19+
echo " --allow-risky Supress warnings generated for risky tests"
20+
echo " --time-limit <n> Set a time limit of n seconds for each test"
2021
}
2122

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

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

156157
# Launch the test function asynchronously and store its PID
157158
__zunit_tmp_test_function &
@@ -189,7 +190,7 @@ function _zunit_execute_test() {
189190

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

194195
return
195196
elif [[ -z $allow_risky && $state -eq 248 ]]; then
@@ -439,7 +440,8 @@ function _zunit_run() {
439440
t=tap -tap=tap \
440441
-output-text=output_text \
441442
-output-html=output_html \
442-
-allow-risky=allow_risky
443+
-allow-risky=allow_risky \
444+
-time-limit:=time_limit
443445

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

513+
# Check if fail_fast is specified in the config or as an option
514+
if [[ -z $fail_fast ]] && [[ "$zunit_config_fail_fast" = "true" ]]; then
515+
fail_fast=1
516+
fi
517+
518+
# Check if allow_risky is specified in the config or as an option
519+
if [[ -z $allow_risky ]] && [[ "$zunit_config_allow_risky" = "true" ]]; then
520+
allow_risky=1
521+
fi
522+
523+
# Check if time_limit is specified in the config or as an option
524+
if [[ -n $time_limit ]]; then
525+
shift time_limit
526+
elif [[ -n $zunit_config_time_limit ]]; then
527+
time_limit=$zunit_config_time_limit
528+
fi
529+
511530
arguments=("$@")
512531
testfiles=()
513532

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

src/zunit.zsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ function _zunit_usage() {
2323
echo " --output-text Print results to a text log, in TAP compatible format"
2424
echo " --output-html Print results to a HTML page"
2525
echo " --allow-risky Supress warnings generated for risky tests"
26+
echo " --time-limit Set a time limit in seconds for each test"
2627
}
2728

2829
###
2930
# Output the version number
3031
###
3132
function _zunit_version() {
32-
echo '0.6.4'
33+
echo '0.7.0'
3334
}
3435

3536
###

zunit.zsh-completion

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,43 @@ _zunit() {
99
typeset -A opt_args
1010
local context state line curcontext="$curcontext"
1111

12+
_arguments \
13+
'1: :_zunit_cmds' \
14+
'*::arg:->args'
15+
16+
_arguments \
17+
'*:tests:_files'
18+
1219
_arguments -A \
1320
'(-h --help)'{-h,--help}'[show help text and exit]' \
1421
'(-v --version)'{-v,--version}'[show version information and exit]' \
1522
'(-f --fail-fast)'{-f,--fail-fast}'[stop execution after the first failure]' \
1623
'(-t --tap)'{-t,--tap}'[output results in a TAP compatible format]' \
17-
'--output-text[Print results to a text log, in TAP compatible format]' \
18-
'--output-html[Print results to a HTML page]' \
19-
'--allow-risky[Supress warnings generated for risky tests]'
20-
21-
_arguments \
22-
'1: :_zunit_cmds' \
23-
'*::arg:->args'
24+
'--output-text[print results to a text log, in TAP compatible format]' \
25+
'--output-html[print results to a HTML page]' \
26+
'--allow-risky[supress warnings generated for risky tests]' \
27+
'--time-limit[set a time limit in seconds for each test]'
2428

2529
case "$state" in
2630
args )
2731
case "$words[1]" in
2832
init )
2933
_arguments -A \
3034
'(-h --help)'{-h,--help}'[show help text and exit]' \
31-
'(-v --version)'{-v,--version}'[show version information and exit]'
35+
'(-t --travis)'{-t,--travis}'[generate a .travis.yml file]'
36+
37+
_arguments \
38+
'*::arg:->args'
3239
;;
3340
run )
3441
_arguments -A \
3542
'(-h --help)'{-h,--help}'[show help text and exit]' \
36-
'(-v --version)'{-v,--version}'[show version information and exit]' \
3743
'(-f --fail-fast)'{-f,--fail-fast}'[stop execution after the first failure]' \
3844
'(-t --tap)'{-t,--tap}'[output results in a TAP compatible format]' \
39-
'--output-text[Print results to a text log, in TAP compatible format]' \
40-
'--output-html[Print results to a HTML page]' \
41-
'--allow-risky[Supress warnings generated for risky tests]'
45+
'--output-text[print results to a text log, in TAP compatible format]' \
46+
'--output-html[print results to a HTML page]' \
47+
'--allow-risky[supress warnings generated for risky tests]' \
48+
'--time-limit[set a time limit in seconds for each test]'
4249

4350
_arguments \
4451
'*:tests:_files'

0 commit comments

Comments
 (0)