From a422365b7cbd5cdaa8e3f36e14d5480c22f8cb6f Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Tue, 21 May 2013 11:59:21 +0200 Subject: [PATCH] tests: only activate 'unset' alias if required 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 --- t/ax/test-lib.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/t/ax/test-lib.sh b/t/ax/test-lib.sh index ee83dcf..aa015d6 100644 --- a/t/ax/test-lib.sh +++ b/t/ax/test-lib.sh @@ -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. ## -- 2.7.4