@@ -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
0 commit comments