From 67235327cc52b680ed12865a7d359a58d7a3bb5f Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 23 Oct 2020 21:22:23 +0300 Subject: [PATCH 01/21] test: Implement t_timeout --- async_test.zsh | 2 +- test.zsh | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index 9e6d17f..ce1a113 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -510,7 +510,7 @@ test_all_options() { # Make sure worker is stopped, even if tests fail. t_defer async_stop_worker test - { sleep 15 && t_fatal "timed out" } & + t_timeout 15 local tpid=$! opts=(${(k)options}) diff --git a/test.zsh b/test.zsh index 01ded81..51dc167 100755 --- a/test.zsh +++ b/test.zsh @@ -60,7 +60,16 @@ t_runner_init() { # used to abort test execution by exec. _t_runner() { local -a _test_defer_funcs + local _test_timeout_trace _test_timeout=0 integer _test_errors=0 + TRAPALRM() { + if ((_test_timeout)); then + _t_log $_test_timeout_trace "timed out after ${_test_timeout}s" + () { return $TEST_CODE_TIMEOUT } + t_done + fi + return 0 + } while read -r; do eval "$REPLY" done @@ -84,7 +93,7 @@ t_runner_init() { # t_skip is for skipping a test. t_skip() { _t_log $funcfiletrace[1] "$*" - () { return 100 } + () { return $TEST_CODE_SKIP } t_done } @@ -97,10 +106,16 @@ t_runner_init() { # t_fatal fails the test and halts execution immediately. t_fatal() { _t_log $funcfiletrace[1] "$*" - () { return 101 } + () { return $TEST_CODE_ERROR } t_done } + t_timeout() { + _test_timeout_trace=$funcfiletrace[1] + _test_timeout=$1 + { sleep $_test_timeout && kill -ALRM $$ } & + } + # t_defer takes a function (and optionally, arguments) # to be executed after the test has completed. t_defer() { @@ -204,8 +219,8 @@ run_test_module() { case $test_exit in (0|1) state=PASS;; - (100) state=SKIP;; - (101|102) state=FAIL; mod_exit=1;; + ($TEST_CODE_SKIP) state=SKIP;; + ($TEST_CODE_ERROR|$TEST_CODE_SKIP) state=FAIL; mod_exit=1;; *) state="????";; esac From 95185a6161e785b7523682476213b793830d11d1 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 16:51:55 +0300 Subject: [PATCH 02/21] test: Add timeout to unique worker --- async_test.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index ce1a113..65fedce 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -257,9 +257,11 @@ test_async_job_unique_worker() { helper() { sleep 0.1; print $1 } + t_timeout 2 # Start a unique (job) worker. async_start_worker test -u + t_defer async_stop_worker test # Launch two jobs with the same name, the first one should be # allowed to complete whereas the second one is never run. @@ -275,8 +277,6 @@ test_async_job_unique_worker() { sleep 0.1 async_process_results test cb - async_stop_worker test - # Ensure that cb was only called once with correc output. [[ ${#result} = 6 ]] || t_error "result: want 6 elements, got" ${#result} [[ $result[3] = one ]] || t_error "output: want 'one', got" ${(Vq-)result[3]} @@ -507,10 +507,11 @@ test_all_options() { t_skip "Test is not reliable on zsh 5.0.X" fi + t_timeout 15 + # Make sure worker is stopped, even if tests fail. t_defer async_stop_worker test - t_timeout 15 local tpid=$! opts=(${(k)options}) From f8347c81a9d179238c0636eac055d45a84e675c0 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 16:58:30 +0300 Subject: [PATCH 03/21] test: Remove kill left behind --- async_test.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index 65fedce..aca56ff 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -512,8 +512,7 @@ test_all_options() { # Make sure worker is stopped, even if tests fail. t_defer async_stop_worker test - local tpid=$! - + local -a opts exclude opts=(${(k)options}) # These options can't be tested. @@ -529,8 +528,6 @@ test_all_options() { setopt_helper $opt fi done 2>/dev/null # Remove redirect to see output. - - kill $tpid # Stop timeout. } test_async_job_with_rc_expand_param() { From e4a6bab6ac574c59a604058ed741382727f106c4 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 17:27:56 +0300 Subject: [PATCH 04/21] test: Fix test timeout --- test.zsh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test.zsh b/test.zsh index 51dc167..3432ea1 100755 --- a/test.zsh +++ b/test.zsh @@ -12,13 +12,13 @@ zmodload zsh/zutil zmodload zsh/system zmodload zsh/zselect -TEST_GLOB=. -TEST_RUN= -TEST_VERBOSE=0 -TEST_TRACE=1 -TEST_CODE_SKIP=100 -TEST_CODE_ERROR=101 -TEST_CODE_TIMEOUT=102 +export TEST_GLOB=. +export TEST_RUN= +export TEST_VERBOSE=0 +export TEST_TRACE=0 +export TEST_CODE_SKIP=100 +export TEST_CODE_ERROR=101 +export TEST_CODE_TIMEOUT=102 show_help() { print "usage: ./test.zsh [-v] [-x] [-run pattern] [search pattern]" @@ -62,6 +62,7 @@ t_runner_init() { local -a _test_defer_funcs local _test_timeout_trace _test_timeout=0 integer _test_errors=0 + TRAPALRM() { if ((_test_timeout)); then _t_log $_test_timeout_trace "timed out after ${_test_timeout}s" @@ -126,7 +127,7 @@ t_runner_init() { # Can also be called manually when the test is done. t_done() { local ret=$? w=${1:-1} - (( _test_errors )) && ret=101 + (( ret < 100 && _test_errors )) && ret=101 (( w )) && wait # Wait for test children to exit. for d in $_test_defer_funcs; do @@ -220,7 +221,7 @@ run_test_module() { case $test_exit in (0|1) state=PASS;; ($TEST_CODE_SKIP) state=SKIP;; - ($TEST_CODE_ERROR|$TEST_CODE_SKIP) state=FAIL; mod_exit=1;; + ($TEST_CODE_ERROR|$TEST_CODE_TIMEOUT) state=FAIL; mod_exit=1;; *) state="????";; esac From d37f9c0d18d226a5f20320e5bf8cad59ee30cab1 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 18:09:24 +0300 Subject: [PATCH 05/21] test: Fix t_timeout timeout --- test.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test.zsh b/test.zsh index 3432ea1..3ba3efb 100755 --- a/test.zsh +++ b/test.zsh @@ -12,6 +12,7 @@ zmodload zsh/zutil zmodload zsh/system zmodload zsh/zselect +export ZTEST_DEBUG=0 export TEST_GLOB=. export TEST_RUN= export TEST_VERBOSE=0 @@ -61,10 +62,11 @@ t_runner_init() { _t_runner() { local -a _test_defer_funcs local _test_timeout_trace _test_timeout=0 - integer _test_errors=0 + integer _test_errors=0 _test_timeout_pid=0 TRAPALRM() { if ((_test_timeout)); then + _test_timeout_pid=0 _t_log $_test_timeout_trace "timed out after ${_test_timeout}s" () { return $TEST_CODE_TIMEOUT } t_done @@ -115,6 +117,7 @@ t_runner_init() { _test_timeout_trace=$funcfiletrace[1] _test_timeout=$1 { sleep $_test_timeout && kill -ALRM $$ } & + _test_timeout_pid=$! } # t_defer takes a function (and optionally, arguments) @@ -128,6 +131,7 @@ t_runner_init() { t_done() { local ret=$? w=${1:-1} (( ret < 100 && _test_errors )) && ret=101 + (( _test_timeout_pid )) && kill $_test_timeout_pid (( w )) && wait # Wait for test children to exit. for d in $_test_defer_funcs; do From 263191657348df2297a7afeb14450cb109fc2d0b Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 18:11:47 +0300 Subject: [PATCH 06/21] test: Protect test runner against posixidentifiers --- test.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.zsh b/test.zsh index 3ba3efb..3796db3 100755 --- a/test.zsh +++ b/test.zsh @@ -88,6 +88,7 @@ t_runner_init() { # t_log is for printing log output, visible in verbose (-v) mode. t_log() { + setopt localoptions noposixidentifiers local line=$funcfiletrace[1] [[ ${line%:[0-9]*} = "" ]] && line=ztest:$functrace[1] # Not from a file. _t_log $line "$*" @@ -95,6 +96,7 @@ t_runner_init() { # t_skip is for skipping a test. t_skip() { + setopt localoptions noposixidentifiers _t_log $funcfiletrace[1] "$*" () { return $TEST_CODE_SKIP } t_done @@ -102,18 +104,21 @@ t_runner_init() { # t_error logs the error and fails the test without aborting. t_error() { + setopt localoptions noposixidentifiers (( _test_errors++ )) _t_log $funcfiletrace[1] "$*" } # t_fatal fails the test and halts execution immediately. t_fatal() { + setopt localoptions noposixidentifiers _t_log $funcfiletrace[1] "$*" () { return $TEST_CODE_ERROR } t_done } t_timeout() { + setopt localoptions noposixidentifiers _test_timeout_trace=$funcfiletrace[1] _test_timeout=$1 { sleep $_test_timeout && kill -ALRM $$ } & From a0842e8fa2c3106af8a85e8e99433b0ac6c43830 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 18:12:15 +0300 Subject: [PATCH 07/21] test: Improve test all options test --- async_test.zsh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index aca56ff..975551a 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -486,7 +486,7 @@ setopt_helper() { async_start_worker test async_job test print "hello world" - while ! async_process_results test cb; do :; done + while ! async_process_results test cb; do sleep 0.001; done async_stop_worker test # At this point, ksh arrays will only mess with the test. @@ -507,7 +507,7 @@ test_all_options() { t_skip "Test is not reliable on zsh 5.0.X" fi - t_timeout 15 + t_timeout 10 # Make sure worker is stopped, even if tests fail. t_defer async_stop_worker test @@ -525,9 +525,13 @@ test_all_options() { if [[ $options[$opt] = on ]]; then setopt_helper no$opt else - setopt_helper $opt + if [[ $opt = xtrace ]] || [[ $opt = printexitvalue ]]; then + setopt_helper $opt 2>/dev/null + else + setopt_helper $opt + fi fi - done 2>/dev/null # Remove redirect to see output. + done } test_async_job_with_rc_expand_param() { From a231699fcfe153b584825dad5eb752dab674dd72 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 22 Oct 2020 23:39:56 +0300 Subject: [PATCH 08/21] Fix missing stop worker in test --- async_test.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/async_test.zsh b/async_test.zsh index 975551a..93f126f 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -298,6 +298,8 @@ test_async_job_error_and_nonzero_exit() { while ! async_process_results test cb; do :; done + async_stop_worker test + [[ $r[1] = error ]] || t_error "want 'error', got ${(Vq-)r[1]}" [[ $r[2] = 99 ]] || t_error "want exit code 99, got $r[2]" From 5e4f5190d370e4479e89b37b41fb4256bd5a67e1 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 19:27:48 +0300 Subject: [PATCH 09/21] test: Improve cleanup and add sleep --- async_test.zsh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index 93f126f..0b81657 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -268,7 +268,7 @@ test_async_job_unique_worker() { async_job test helper one async_job test helper two - while ! async_process_results test cb; do :; done + while ! async_process_results test cb; do sleep 0.05; done # If both jobs were running but only one was complete, # async_process_results() could've returned true for @@ -363,6 +363,7 @@ test_async_flush_jobs() { } async_start_worker test + t_defer async_stop_worker test # Start a job that prints 1 and starts two disowned child processes that # print 2 and 3, respectively, after a timeout. The job will not exit @@ -382,8 +383,10 @@ test_async_flush_jobs() { # Flush jobs, this kills running jobs and discards unprocessed results. # TODO: Confirm that they no longer exist in the process tree. - local output - output="${(Q)$(ASYNC_DEBUG=1 async_flush_jobs test)}" + local output line + ASYNC_DEBUG=1 async_flush_jobs test | while read -r line; do output+="$line"; done + output="${(Q)output}" + # NOTE(mafredri): First 'p' in print_four is lost when null-prefixing # _async_job output. [[ $output = *'rint_four 0 4'* ]] || { @@ -394,8 +397,6 @@ test_async_flush_jobs() { sleep 0.1 async_process_results test cb (( $#r == 0 )) || t_error "want no output, got ${(Vq-)r}" - - async_stop_worker test } test_async_worker_survives_termination_of_other_worker() { From 8ffc373bf3072ab0e9598648cb9ae95866572a5a Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:09:47 +0300 Subject: [PATCH 10/21] test: Output full result on setopt error --- async_test.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async_test.zsh b/async_test.zsh index f2f36b7..a2d327e 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -499,7 +499,7 @@ setopt_helper() { # At this point, ksh arrays will only mess with the test. setopt noksharrays - [[ $result[1] = print ]] || t_fatal "$1 want command name: print, got" $result[1] + [[ $result[1] = print ]] || t_fatal "$1 want command name: print, got" $result[1] "(${(Vq-)result})" [[ $result[2] = 0 ]] || t_fatal "$1 want exit code: 0, got" $result[2] [[ $result[3] = "hello world" ]] || { From 29a53e2ffab56e22c01bfc7db30f3bbcc3581ff0 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:12:28 +0300 Subject: [PATCH 11/21] test: Slightly slow down setopt helper, fails on actions --- async_test.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/async_test.zsh b/async_test.zsh index a2d327e..773359b 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -492,9 +492,11 @@ setopt_helper() { cb() { result=("$@") } async_start_worker test + sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. async_job test print "hello world" while ! async_process_results test cb; do sleep 0.001; done async_stop_worker test + sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. # At this point, ksh arrays will only mess with the test. setopt noksharrays From c9ae1e67e593014a4ecb17bc6c83afebea7f328a Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:21:53 +0300 Subject: [PATCH 12/21] Test better option protection for async functions --- async.zsh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/async.zsh b/async.zsh index b927c82..c756564 100644 --- a/async.zsh +++ b/async.zsh @@ -341,7 +341,7 @@ async_process_results() { # Watch worker for output _async_zle_watcher() { - setopt localoptions noshwordsplit + setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings typeset -gA ASYNC_PTYS ASYNC_CALLBACKS local worker=$ASYNC_PTYS[$1] local callback=$ASYNC_CALLBACKS[$worker] @@ -368,7 +368,7 @@ _async_zle_watcher() { } _async_send_job() { - setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings + setopt localoptions noshwordsplit local caller=$1 local worker=$2 @@ -435,7 +435,7 @@ async_worker_eval() { # This function traps notification signals and calls all registered callbacks _async_notify_trap() { - setopt localoptions noshwordsplit + setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings local k for k in ${(k)ASYNC_CALLBACKS}; do @@ -451,7 +451,7 @@ _async_notify_trap() { # async_register_callback # async_register_callback() { - setopt localoptions noshwordsplit nolocaltraps + setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings nolocaltraps typeset -gA ASYNC_PTYS ASYNC_CALLBACKS local worker=$1; shift @@ -493,7 +493,7 @@ async_unregister_callback() { # async_flush_jobs # async_flush_jobs() { - setopt localoptions noshwordsplit + setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings local worker=$1; shift @@ -531,7 +531,7 @@ async_flush_jobs() { # -p pid to notify (defaults to current pid) # async_start_worker() { - setopt localoptions noshwordsplit noclobber + setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings noclobber local worker=$1; shift local -a args @@ -613,7 +613,7 @@ async_start_worker() { # async_stop_worker [] # async_stop_worker() { - setopt localoptions noshwordsplit + setopt localoptions noshwordsplit noksharrays noposixidentifiers noposixstrings local ret=0 worker k v for worker in $@; do From caacf1d40039a3f27a6701b6d8bd4c455bd144b5 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:29:09 +0300 Subject: [PATCH 13/21] test: Rename the setopt workers --- async_test.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index 773359b..9bcbc59 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -491,11 +491,11 @@ setopt_helper() { local -a result cb() { result=("$@") } - async_start_worker test + async_start_worker ${1}_worker sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. - async_job test print "hello world" - while ! async_process_results test cb; do sleep 0.001; done - async_stop_worker test + async_job ${1}_worker print "hello world" + while ! async_process_results ${1}_worker cb; do sleep 0.001; done + async_stop_worker ${1}_worker sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. # At this point, ksh arrays will only mess with the test. From 19f06db70e7cc3af501afb7cae515cd56982a85a Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:34:37 +0300 Subject: [PATCH 14/21] test: Try to brute force setopt issue detection --- async_test.zsh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index 9bcbc59..fdf9117 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -516,7 +516,7 @@ test_all_options() { t_skip "Test is not reliable on zsh 5.0.X" fi - t_timeout 10 + t_timeout 30 # Make sure worker is stopped, even if tests fail. t_defer async_stop_worker test @@ -530,16 +530,20 @@ test_all_options() { warnnestedvar errreturn ) - for opt in ${opts:|exclude}; do - if [[ $options[$opt] = on ]]; then - setopt_helper no$opt - else - if [[ $opt = xtrace ]] || [[ $opt = printexitvalue ]]; then - setopt_helper $opt 2>/dev/null + local -a testopts=(${opts:|exclude}) + for ((i = 1; i <= $#testopts; i++)); do + t_log "Testing with ${testopts[i]} included..." + for opt in $testopts[1,$i]; do + if [[ $options[$opt] = on ]]; then + setopt_helper no$opt else - setopt_helper $opt + if [[ $opt = xtrace ]] || [[ $opt = printexitvalue ]]; then + setopt_helper $opt 2>/dev/null + else + setopt_helper $opt + fi fi - fi + done done } From 9f1f183dcf41a5861c1162f9b9de61fba84cdf2e Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:37:05 +0300 Subject: [PATCH 15/21] test: Try to disable printexitvalue --- async_test.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index fdf9117..c02591e 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -492,11 +492,11 @@ setopt_helper() { cb() { result=("$@") } async_start_worker ${1}_worker - sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. + #sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. async_job ${1}_worker print "hello world" while ! async_process_results ${1}_worker cb; do sleep 0.001; done async_stop_worker ${1}_worker - sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. + #sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. # At this point, ksh arrays will only mess with the test. setopt noksharrays @@ -527,7 +527,7 @@ test_all_options() { # These options can't be tested. exclude=( zle interactive restricted shinstdin stdin onecmd singlecommand - warnnestedvar errreturn + warnnestedvar errreturn printexitvalue ) local -a testopts=(${opts:|exclude}) From 053d880a48993ef6cc5d03171ca4e4b5efc09e90 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:39:35 +0300 Subject: [PATCH 16/21] test: Try to disable posixargzero --- async_test.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async_test.zsh b/async_test.zsh index c02591e..0d3d8d4 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -527,7 +527,7 @@ test_all_options() { # These options can't be tested. exclude=( zle interactive restricted shinstdin stdin onecmd singlecommand - warnnestedvar errreturn printexitvalue + warnnestedvar errreturn printexitvalue posixargzero ) local -a testopts=(${opts:|exclude}) From b17afa67b29ee306234f853cf58c0de6ba6c7eee Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:42:22 +0300 Subject: [PATCH 17/21] test: Try to disable autolist --- async_test.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async_test.zsh b/async_test.zsh index 0d3d8d4..2e92082 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -527,7 +527,7 @@ test_all_options() { # These options can't be tested. exclude=( zle interactive restricted shinstdin stdin onecmd singlecommand - warnnestedvar errreturn printexitvalue posixargzero + warnnestedvar errreturn printexitvalue posixargzero autolist ) local -a testopts=(${opts:|exclude}) From 3475a1f3246cfcbc729ad7e8c5b9e9b70334bfd5 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:44:26 +0300 Subject: [PATCH 18/21] test: Try to disable kshzerosubscript --- async_test.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async_test.zsh b/async_test.zsh index 2e92082..7347f02 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -527,7 +527,7 @@ test_all_options() { # These options can't be tested. exclude=( zle interactive restricted shinstdin stdin onecmd singlecommand - warnnestedvar errreturn printexitvalue posixargzero autolist + warnnestedvar errreturn printexitvalue posixargzero autolist kshzerosubscript ) local -a testopts=(${opts:|exclude}) From ee198eddc777a396b08a5d50ba6c3d0a51c9175a Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:46:34 +0300 Subject: [PATCH 19/21] test: Try to disable more... --- async_test.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/async_test.zsh b/async_test.zsh index 7347f02..153aa03 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -527,7 +527,8 @@ test_all_options() { # These options can't be tested. exclude=( zle interactive restricted shinstdin stdin onecmd singlecommand - warnnestedvar errreturn printexitvalue posixargzero autolist kshzerosubscript + warnnestedvar errreturn printexitvalue posixargzero autolist + kshzerosubscript localloops listpacked ) local -a testopts=(${opts:|exclude}) From 16c2cdb33087e1bd998df4c81c993d2ba95533ff Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 20:49:33 +0300 Subject: [PATCH 20/21] test: Try another approach --- async_test.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/async_test.zsh b/async_test.zsh index 153aa03..45f4c4c 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -492,10 +492,10 @@ setopt_helper() { cb() { result=("$@") } async_start_worker ${1}_worker + t_defer async_stop_worker ${1}_worker #sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. async_job ${1}_worker print "hello world" while ! async_process_results ${1}_worker cb; do sleep 0.001; done - async_stop_worker ${1}_worker #sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. # At this point, ksh arrays will only mess with the test. @@ -527,8 +527,7 @@ test_all_options() { # These options can't be tested. exclude=( zle interactive restricted shinstdin stdin onecmd singlecommand - warnnestedvar errreturn printexitvalue posixargzero autolist - kshzerosubscript localloops listpacked + warnnestedvar errreturn ) local -a testopts=(${opts:|exclude}) From c842ec3558ada643ddc5677ffd8e2d42e9bed134 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 21:05:07 +0300 Subject: [PATCH 21/21] test: Try another approach... --- async.zsh | 3 ++- async_test.zsh | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/async.zsh b/async.zsh index c756564..a22253f 100644 --- a/async.zsh +++ b/async.zsh @@ -181,13 +181,14 @@ _async_worker() { while :; do # Wait for jobs sent by async_job. read -r -d $'\0' request || { + local ret=$? # Unknown error occurred while reading from stdin, the zpty # worker is likely in a broken state, so we shut down. terminate_jobs # Stdin is broken and in case this was an unintended # crash, we try to report it as a last hurrah. - print -r -n $'\0'"'[async]'" $(( 127 + 3 )) "''" 0 "'$0:$LINENO: zpty fd died, exiting'"$'\0' + print -r -n $'\0'"'[async]'" $(( 127 + 3 )) "''" 0 "'$0:$LINENO: zpty fd died ($ret), exiting'"$'\0' # We use `return` to abort here because using `exit` may # result in an infinite loop that never exits and, as a diff --git a/async_test.zsh b/async_test.zsh index 45f4c4c..0a7803f 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -492,11 +492,11 @@ setopt_helper() { cb() { result=("$@") } async_start_worker ${1}_worker - t_defer async_stop_worker ${1}_worker #sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. async_job ${1}_worker print "hello world" while ! async_process_results ${1}_worker cb; do sleep 0.001; done #sleep 0.001 # Fails sporadically on GitHub Actions without a sleep here. + async_stop_worker ${1}_worker # At this point, ksh arrays will only mess with the test. setopt noksharrays @@ -519,7 +519,7 @@ test_all_options() { t_timeout 30 # Make sure worker is stopped, even if tests fail. - t_defer async_stop_worker test + #t_defer async_stop_worker test local -a opts exclude opts=(${(k)options}) @@ -529,6 +529,7 @@ test_all_options() { zle interactive restricted shinstdin stdin onecmd singlecommand warnnestedvar errreturn ) + #setopt nopromptsubst local -a testopts=(${opts:|exclude}) for ((i = 1; i <= $#testopts; i++)); do