Pádraig Brady wrote: > On 12/22/2011 11:44 AM, 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: >> > >> 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_ "$@" || : >> case $? in >> 0|1) return $?;; >> *) compare_ "$@";; > > Doesn't that just always set $? to 0 > What am I missing?
*You* missed nothing ;-) Here's a fix, still untested. I suppose now I owe a test module for this... >From aa9f1d090454845b6b32a16009861eddfaf3014c Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Thu, 22 Dec 2011 13:12:19 +0100 Subject: [PATCH] init.sh: correct previous change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tests/init.sh (compare): My previous change was wrong. Don't clobber "$?". Spotted by Stefano Lattarini and Pádraig Brady. --- ChangeLog | 4 ++++ tests/init.sh | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index df1f5b5..7ca5e7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2011-12-22 Jim Meyering <meyer...@redhat.com> + init.sh: correct previous change + * tests/init.sh (compare): My previous change was wrong. + Don't clobber "$?". Spotted by Stefano Lattarini and Pádraig Brady. + init.sh: avoid unwarranted test failure when using "set -e" * tests/init.sh (compare): Ignore nonzero exit from compare_dev_null_. Otherwise, in a test script that uses "set -e" (like many in vc-dwim) diff --git a/tests/init.sh b/tests/init.sh index 458a448..1e1f0e3 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -304,11 +304,17 @@ fi # Otherwise, propagate $? to caller: any diffs have already been printed. compare () { - compare_dev_null_ "$@" || : - case $? in - 0|1) return $?;; - *) compare_ "$@";; - esac + # This looks like it can be factored to use a simple "case $?" + # after unchecked compare_dev_null_ invocation, but that would + # fail in a "set -e" environment. + if compare_dev_null_ "$@"; then + return 0 + else + case $? in + 1) return 1;; + *) compare_ "$@";; + esac + fi } # An arbitrary prefix to help distinguish test directories. -- 1.7.8.385.g1d1cb