tests: only activate 'unset' alias if required
authorStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 21 May 2013 09:59:21 +0000 (11:59 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 21 May 2013 22:05:19 +0000 (00:05 +0200)
This makes the test logs easier to read for most shells (which do not
actually require that alias).  This is especially important now that
'unset' is used in the new 'run_make()' function, and that function is
likely going to be used more and more in the future.

* t/ax/test-lib.sh (_am_unset, unset): Only define this function and
alias if "unset VAR" returns a non-zero exit status when VAR is already
unset.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
t/ax/test-lib.sh

index ee83dcf..aa015d6 100644 (file)
@@ -105,18 +105,24 @@ alias exit=_am_exit
 # "unset VAR" returns a non-zero exit status in case the VAR variable
 # is already unset.  This doesn't interact well with our usage of
 # "set -e" in the testsuite.  This function and the alias below help
-# to work around the issue.
-_am_unset ()
-{
-  for _am_v
-  do
-    # Extra escaping (here and below) to ensure we do not call our
-    # 'unset' alias.
-    eval ${_am_v}=dummy && \unset ${_am_v} || exit 1
-  done
-  \unset _am_v
-}
-alias unset=_am_unset
+# to work around the issue.  But be sure to use them only if actually
+# needed.  The repeated unset in the check below cater to the very
+# unlikely case where the '_am_v' variable is set in the environment.
+if unset _am_v && unset _am_v; then
+  : Nothing needs to be done.
+else
+  _am_unset ()
+  {
+    for _am_v
+    do
+      # Extra escaping (here and below) to ensure we do not call our
+      # 'unset' alias.
+      eval ${_am_v}=dummy && \unset ${_am_v} || return 1
+    done
+    \unset _am_v
+  }
+  alias unset=_am_unset
+fi
 
 ## ------------------------------------ ##
 ##  General testsuite shell functions.  ##