bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test-framework-sh: Fix 'returns_' to not turn off tracing permanentl


From: Pádraig Brady
Subject: Re: test-framework-sh: Fix 'returns_' to not turn off tracing permanently
Date: Tue, 11 Jun 2024 20:16:30 +0100
User-agent: Mozilla Thunderbird Beta

On 11/06/2024 19:54, Bruno Haible wrote:
I'm debugging a unit test that consists of a dozen of shell statement groups,
each with a 'returns_ 1 ...' invocation. The log file shows an error message,
but no indication from which of the statement groups the error came. So,
naturally, I add a 'set -x' command near the beginning of the test file.
But it doesn't work: The first 'returns_ 1 ...' command turns off the 'x'
flag! - defeating the purpose of my 'set -x'.

This patch fixes it.


2024-06-11  Bruno Haible  <bruno@clisp.org>

        test-framework-sh: Fix 'returns_' to not turn off tracing permanently.
        * tests/init.sh (returns_): Restore tracing if it was enabled before.

diff --git a/tests/init.sh b/tests/init.sh
index 4689b6b758..2724f5ab67 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -594,6 +594,7 @@ fi
  #   returns_ 1 command ... || fail
  returns_ () {
    # Disable tracing so it doesn't interfere with stderr of the wrapped command
+  local is_tracing=`{ :; } 2>&1`
    { set +x; } 2>/dev/null
local exp_exit="$1"
@@ -601,7 +602,8 @@ returns_ () {
    "$@"
    test $? -eq $exp_exit && ret_=0 || ret_=1
- if test "$VERBOSE" = yes && test "$gl_set_x_corrupts_stderr_" = false; then
+  # Restore tracing if it was enabled.
+  if test -n "$is_tracing"; then
      set -x
    fi
    { return $ret_; } 2>/dev/null

I remember being annoyed with the coupling in the original implementation.
Thanks for improving it.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]