bug-gnulib
[Top][All Lists]
Advanced

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

Re: exclude tests refactoring


From: Bruno Haible
Subject: Re: exclude tests refactoring
Date: Sun, 13 Nov 2011 21:31:39 +0100
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hi Jim,

> Thanks for testing and noticing that.
> However, I would like to avoid using a temporary file when using GNU diff.
> How about something like this instead?
> 
> diff_=$(diff -u "$0" "$0" < /dev/null 2> /dev/null)
> if test $? = 0; then
>   if test -z "$diff_"; then
>     compare () { diff -u "$@"; }
>   else
>     ...
>   fi
> elif ...

OK, I modified and applied the patch like this.

Note that with use of $(...) outside double-quotes, namely

  diff_out_=$( ( diff -u "$0" "$0" < /dev/null ) 2>/dev/null)

I got a syntax error on OSF/1 and Solaris:

./test-exclude1.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude1.sh
./test-exclude2.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude2.sh
./test-exclude3.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude3.sh
./test-exclude4.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude4.sh
./test-exclude5.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude5.sh
./test-exclude6.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude6.sh
./test-exclude7.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude7.sh
./test-exclude8.sh: syntax error at line 224: `diff_out_=$' unexpected
FAIL: test-exclude8.sh

The reexec magic, which comes earlier in this file, would print debugging
output like this:

  __current__ works just fine
  /bin/sh works just fine
  bash works just fine
  exec bash ./test-exclude1.sh --no-reexec 
  PASS: test-exclude1.sh

but when the 

   diff_out_=$( ( diff -u "$0" "$0" < /dev/null ) 2>/dev/null)

line is present, the execution does not even get that far. Apparently the
parts of init.sh that are parsed by the initial shell (I tried /bin/sh
and /bin/ksh) extend beyond the point of execution; possibly it includes
the entire init.sh file.

I could have written

   diff_out_="$( ( diff -u "$0" "$0" < /dev/null ) 2>/dev/null)"

This does not produce a parse error. But it is nevertheless quite dangerous
to let the initial shell parse a piece of code incorrectly, even if we know
that we will jump out of this shell before the incorrectly parsed code can
be executed.


2011-11-13  Bruno Haible  <address@hidden>
            Jim Meyering  <address@hidden>

        Silence successful tests that use 'compare' on AIX, HP-UX, Solaris.
        * tests/init.sh (compare): Remove "No differences encountered" or
        synonymous output from the 'diff' program.

--- tests/init.sh.orig  Sun Nov 13 21:20:06 2011
+++ tests/init.sh       Sun Nov 13 21:18:06 2011
@@ -221,10 +221,43 @@
 # a partition, or to undo any other global state changes.
 cleanup_ () { :; }
 
-if ( diff -u "$0" "$0" < /dev/null ) > /dev/null 2>&1; then
-  compare () { diff -u "$@"; }
-elif ( diff -c "$0" "$0" < /dev/null ) > /dev/null 2>&1; then
-  compare () { diff -c "$@"; }
+if diff_out_=`( diff -u "$0" "$0" < /dev/null ) 2>/dev/null`; then
+  if test -z "$diff_out_"; then
+    compare () { diff -u "$@"; }
+  else
+    compare ()
+    {
+      if diff -u "$@" > diff.out; then
+        # No differences were found, but Solaris 'diff' produces output
+        # "No differences encountered". Hide this output.
+        rm -f diff.out
+        true
+      else
+        cat diff.out
+        rm -f diff.out
+        false
+      fi
+    }
+  fi
+elif diff_out_=`( diff -c "$0" "$0" < /dev/null ) 2>/dev/null`; then
+  if test -z "$diff_out_"; then
+    compare () { diff -c "$@"; }
+  else
+    compare ()
+    {
+      if diff -c "$@" > diff.out; then
+        # No differences were found, but AIX and HP-UX 'diff' produce output
+        # "No differences encountered" or "There are no differences between the
+        # files.". Hide this output.
+        rm -f diff.out
+        true
+      else
+        cat diff.out
+        rm -f diff.out
+        false
+      fi
+    }
+  fi
 elif ( cmp --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then
   compare () { cmp -s "$@"; }
 else
-- 
In memoriam Bruno Binnebesel <http://de.wikipedia.org/wiki/Bruno_Binnebesel>



reply via email to

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