Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tracing async worker in tests #50

Open
wants to merge 2 commits into
base: more-zpty-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions async.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,18 @@ _async_worker() {
# pids of child processes.
unsetopt monitor

# Worker name, for debugging purposes.
local worker_name=$1
shift

# Redirect stderr to `/dev/null` in case unforseen errors produced by the
# worker. For example: `fork failed: resource temporarily unavailable`.
# Some older versions of zsh might also print malloc errors (know to happen
# on at least zsh 5.0.2 and 5.0.8) likely due to kill signals.
if ((ASYNC_DEBUG)); then
exec 2>>${ASYNC_DEBUG_WORKER_STDERR}
if [[ $ASYNC_DEBUG_WORKER_STDERR != /dev/null ]]; then
PROMPT4="(async):${worker_name}> ${PROMPT4}"
setopt xtrace
fi
else
Expand Down Expand Up @@ -635,9 +640,9 @@ async_start_worker() {
}

if (( errfd != -1 )); then
zpty -b $worker _async_worker -p $$ $args 2>&$errfd
zpty -b $worker _async_worker $worker -p $$ $args 2>&$errfd
else
zpty -b $worker _async_worker -p $$ $args
zpty -b $worker _async_worker $worker -p $$ $args
fi
local ret=$?

Expand Down
8 changes: 8 additions & 0 deletions async_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,14 @@ test_zle_watcher() {
test_main() {
# Load zsh-async before running each test.
zmodload zsh/datetime
if [[ -o xtrace ]]; then
typeset -g ASYNC_DEBUG ASYNC_DEBUG_WORKER_STDERR
export ASYNC_DEBUG=1
# Output to special fd from test runner.
# TODO(mafredri):
exec 9> >(cat)
export ASYNC_DEBUG_WORKER_STDERR=/dev/fd/9
fi
. ./async.zsh
async_init
}
4 changes: 2 additions & 2 deletions test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ zmodload zsh/zselect
TEST_GLOB=.
TEST_RUN=
TEST_VERBOSE=0
TEST_TRACE=1
TEST_TRACE=0
TEST_CODE_SKIP=100
TEST_CODE_ERROR=101
TEST_CODE_TIMEOUT=102

show_help() {
print "usage: ./test.zsh [-v] [-x] [-run pattern] [search pattern]"
print "usage: ./test.zsh [-h] [-v] [-x] [-d] [-run pattern] [search pattern]"
}

parse_opts() {
Expand Down