bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] init.sh: avoid unwarranted test failure when using "set -x"


From: Jim Meyering
Subject: Re: [PATCH] init.sh: avoid unwarranted test failure when using "set -x"
Date: Thu, 22 Dec 2011 13:00:37 +0100

Stefano Lattarini wrote:

> Hi Jim.
>
> On 12/22/2011 12:44 PM, Jim Meyering wrote:
>> FYI, after updating to the latest tests/init.sh, I noticed new
>> failures in vc-dwim's "make check".  Tracked it down to this:
>>
>> From ed2ad641686263add14f2081d659da0cc3a76536 Mon Sep 17 00:00:00 2001
>> From: Jim Meyering <address@hidden>
>> Date: Thu, 22 Dec 2011 12:42:32 +0100
>> Subject: [PATCH] init.sh: avoid unwarranted test failure when using "set -x"
>>
>> * tests/init.sh (compare): Ignore nonzero exit from compare_dev_null_.
>> Otherwise, in a test script that uses "set -x" (like many in vc-dwim)
>> a use like "compare exp out" would get evoke an unconditional failure.
>> ---
>>  ChangeLog     |    7 +++++++
>>  tests/init.sh |    2 +-
>>  2 files changed, 8 insertions(+), 1 deletions(-)
>>
>> diff --git a/ChangeLog b/ChangeLog
>> index d52e398..fe6ff6a 100644
>> --- a/ChangeLog
>> +++ b/ChangeLog
>> @@ -1,3 +1,10 @@
>> +2011-12-22  Jim Meyering  <address@hidden>
>> +
>> +    init.sh: avoid unwarranted test failure when using "set -x"
>>
> s/"set -x"/"set -e"/ ?

Oops.  Good catch.

>> +    * tests/init.sh (compare): Ignore nonzero exit from compare_dev_null_.
>> +    Otherwise, in a test script that uses "set -x" (like many in vc-dwim)
>>
> Ditto.
>
>> +    a use like "compare exp out" would get evoke an unconditional failure.
>> +
>>  2011-12-21  Alfred M. Szmidt  <address@hidden>
>>
>>      bootstrap: fix it to honor $ACLOCAL_FLAGS once again
>> diff --git a/tests/init.sh b/tests/init.sh
>> index 19c0cf4..458a448 100644
>> --- a/tests/init.sh
>> +++ b/tests/init.sh
>> @@ -304,7 +304,7 @@ fi
>>  # Otherwise, propagate $? to caller: any diffs have already been printed.
>>  compare ()
>>  {
>> -  compare_dev_null_ "$@"
>> +  compare_dev_null_ "$@" || :
>>
> But this will clobber the value of $? by always setting it to zero, regardless
> of what the return status of compare_dev_null_ was, no?

Indeed.
Thank you!

I've written this (and have not tested at all),
but still have to write the commit log:

diff --git a/tests/init.sh b/tests/init.sh
index 458a448..fc4a8c0 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -304,11 +304,16 @@ fi
 # Otherwise, propagate $? to caller: any diffs have already been printed.
 compare ()
 {
-  compare_dev_null_ "$@" || :
-  case $? in
-    0|1) return $?;;
-    *) compare_ "$@";;
-  esac
+  # This is more convoluted than it should be, so that it does not
+  # provoke failure when used with set -e.
+  if compare_dev_null_ "$@"; then
+    return 0
+  else
+    case $? in
+      1) return 1;;
+      *) compare_ "$@";;
+    esac
+  fi
 }

 # An arbitrary prefix to help distinguish test directories.



reply via email to

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