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

2024-06-20 Thread Bruno Haible
On 2024-06-11, I did:
> 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"

This causes a test failure of the test-dfa-invalid-merge.sh test, both in the
GNU grep package and in the GNU sed package. (The same test works in a
gnulib testdir. I have no idea why??)

The test's log contains this:

...
+ LC_ALL=C returns_ 0 test-dfa-match-aux x+x+x+ xx
+ compare /dev/null out
+ compare_dev_null_ /dev/null out
+ test 2 = 2
+ test x/dev/null = x/dev/null
+ test -s out
+ emit_diff_u_header_ /dev/null out
+ printf %s\n diff -u /dev/null out --- /dev/null   1970-01-01 +++ out  
1970-01-01
diff -u /dev/null out
--- /dev/null   1970-01-01
+++ out 1970-01-01
+ sed s/^/+/ out
++ local is_tracing=+ :
+ return 1
+ return 1
+ fail=1
...

So, apparently, the tracing output of the 'local is_tracing=...' line is
causing the trouble.

This patch fixes it.


2024-06-20  Bruno Haible  

test-framework-sh: Fix side effect on dfa tests (regression 2024-06-11).
* tests/init.sh (returns_): Silence the 'local is_tracing' assignment.

diff --git a/tests/init.sh b/tests/init.sh
index 237db02fb0..87e6557649 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -598,7 +598,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`
+  local is_tracing=`{ :; } 2>&1` 2>/dev/null
   { set +x; } 2>/dev/null
 
   local exp_exit="$1"






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

2024-06-20 Thread Bruno Haible
I wrote:
> So, apparently, the tracing output of the 'local is_tracing=...' line is
> causing the trouble.
> 
> This patch fixes it.

This patch did not fix it. "make check" from grep's top-level directory
still fails. Only "make -f Makefile check" succeeds.

> This causes a test failure of the test-dfa-invalid-merge.sh test, both in the
> GNU grep package and in the GNU sed package. (The same test works in a
> gnulib testdir. I have no idea why??)

The reason is that these packages contain an 'export VERBOSE = yes' in
cfg.mk, which is included by GNUmakefile.

To reproduce the failure more easily:
  $ VERBOSE=yes make check TESTS=test-dfa-invalid-merge.sh

This fix finally works:


2024-06-20  Bruno Haible  

test-framework-sh: Fix side effect on dfa tests (regression 2024-06-11).
* tests/init.sh (returns_): Silence the 'local is_tracing' assignment
for real.

diff --git a/tests/init.sh b/tests/init.sh
index 87e6557649..c374e5f014 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -598,7 +598,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` 2>/dev/null
+  { local is_tracing=`{ :; } 2>&1`; } 2>/dev/null
   { set +x; } 2>/dev/null
 
   local exp_exit="$1"






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

2024-06-20 Thread Bruno Haible
Hi Eric,

> But as long as we're relying on Bash semantics, why not use the simpler:
> 
> local -; set -x
> 
> which will auto-restore $- (and hence set +x if needed) when the
> function exits, rather than having to futz around with $is_tracing?

Because it's not portable. It does not work with
  - bash versions < 4.0,
  - /bin/sh on macOS (because that is bash-3.2.57),
  - /bin/sh on Solaris.

I've committed the testing script with its results at
https://git.savannah.gnu.org/gitweb/?p=gnulib/maint-tools.git;a=blob;f=test-programs/sh-features

Bruno