From d5b7b63aabd8a3e83a14d4f325fd6eeefa6f05b7 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 15:07:14 +0300 Subject: [PATCH 1/2] Allow tracing async worker in tests --- async.zsh | 9 +++++++-- async_test.zsh | 8 ++++++++ test.zsh | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/async.zsh b/async.zsh index 2b6ed01..c49622b 100644 --- a/async.zsh +++ b/async.zsh @@ -117,6 +117,10 @@ _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 @@ -125,6 +129,7 @@ _async_worker() { exec 2>>${ASYNC_DEBUG_WORKER_STDERR} if [[ $ASYNC_DEBUG_WORKER_STDERR != /dev/null ]]; then setopt xtrace + PROMPT4="(async):${worker_name}> ${PROMPT4}" fi else exec 2>/dev/null @@ -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=$? diff --git a/async_test.zsh b/async_test.zsh index 6b58919..8b813fa 100644 --- a/async_test.zsh +++ b/async_test.zsh @@ -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 } diff --git a/test.zsh b/test.zsh index 01ded81..a26c588 100755 --- a/test.zsh +++ b/test.zsh @@ -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() { From c0ef2008867caf8a7518470e915cc54f9c137bdb Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 24 Oct 2020 16:16:27 +0300 Subject: [PATCH 2/2] Set PS4 before xtrace --- async.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async.zsh b/async.zsh index c49622b..7f61ce2 100644 --- a/async.zsh +++ b/async.zsh @@ -128,8 +128,8 @@ _async_worker() { if ((ASYNC_DEBUG)); then exec 2>>${ASYNC_DEBUG_WORKER_STDERR} if [[ $ASYNC_DEBUG_WORKER_STDERR != /dev/null ]]; then - setopt xtrace PROMPT4="(async):${worker_name}> ${PROMPT4}" + setopt xtrace fi else exec 2>/dev/null