diff options
author | Stefano Lattarini <stefano.lattarini@gmail.com> | 2013-05-21 20:22:17 +0200 |
---|---|---|
committer | Stefano Lattarini <stefano.lattarini@gmail.com> | 2013-05-22 00:05:19 +0200 |
commit | c7cfa09349bb588b71ea7adffa385034465b1b09 (patch) | |
tree | 37f3012b340ce6eb1ddb54c204db63b4fdddf36d /t/ax/am-test-lib.sh | |
parent | a422365b7cbd5cdaa8e3f36e14d5480c22f8cb6f (diff) | |
download | automake-c7cfa09349bb588b71ea7adffa385034465b1b09.tar.gz |
tests: run_make: options to do command redirection
Let's improve the API of the 'run_make()' helper shell function by
adding three new options:
-O Save the standard output from make on disk, in a regular file
named 'stdout'.
-E Save the standard error from make on disk, in a regular file
named 'stderr'.
-M Save both the standard output and standard error from make on
disk, in a regular file named 'output'. This option supersedes
both the '-O' and '-E' options.
This new API has two main advantages.
1. Its use will allow us to get rid of more cumbersome idioms
like, e.g.,
$MAKE check >stdout && { cat stdout; exit 1; }
cat stdout
That can now be substituted with a simpler one:
run_make -e FAIL -O check
2. More importantly, using the new API we will prevent any extra output
from the shell traces of the code in run_make to be redirected along
with the make stderr (where that was redirected). This problem was
present in usages like, e.g.,
run_make TESTS=foo.test check 2>stderr && exit 1
grep 'expected error message' stderr
Such usages are now to be rewritten as follows:
run_make -e FAIL -E TESTS=foo.test check
grep 'expected error message' stderr
ensuring that 'stderr' won't end up containing unrelated stuff.
Note that we do not convert in bulk the old idioms and the use of
redirected 'run_make' invocations with this patch. We only convert
some occurrences, to ensure that the new implementation of 'run_make'
is sound enough. More sweeping conversions will likely be done in
follow-up patches.
* t/ax/am-test-lib.sh (run_make): Enhance and implement the extended API.
* t/tap-xfail-tests.sh: Use the new 'run_make' API.
* t/test-driver-cond.sh: Likewise.
* t/tests-environment-fd-redirect.sh: Likewise.
* t/uninstall-fail.sh: Likewise.
* t/yacc-dist-nobuild.sh: Likewise.
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Diffstat (limited to 't/ax/am-test-lib.sh')
-rw-r--r-- | t/ax/am-test-lib.sh | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/t/ax/am-test-lib.sh b/t/ax/am-test-lib.sh index 4f5c89519..74311f3c3 100644 --- a/t/ax/am-test-lib.sh +++ b/t/ax/am-test-lib.sh @@ -159,16 +159,33 @@ is_valid_varname () return 0 } -# run_make [-e STATUS] [--] [VAR=VAL ...] [MAKE-ARGS...] -# ------------------------------------------------------ +# run_make [-e STATUS] [-O] [-E] [-M] [--] [VAR=VAL ...] [MAKE-ARGS...] +# --------------------------------------------------------------------- +# # Run $MAKE with the given command-line, and fail if it doesn't exit with # STATUS (default: 0). If STATUS is "FAIL", then any exit status > 0 is # acceptable. If STATUS is "IGNORE", any exit value is acceptable. +# +# Other options: +# +# -O save the standard output from make on disk, in a regular file +# named 'stdout'. +# +# -E save the standard error from make on disk, in a regular file +# named 'stderr'. +# +# -M save both the standard output and standard error from make on +# disk, in a regular file named 'output'. This option supersedes +# both the '-O' and '-E' options. +# # This function also handle command-line override of variable definition # in a smart way, using AM_MAKEFLAGS if a non-GNU make implementation # is in use. +# run_make () { + am__make_redirect= + am__make_flags= # Follow-up code might want to analyse these, so don't make them as # private, nor unset them later. am_make_rc_exp=0 @@ -177,12 +194,15 @@ run_make () while test $# -gt 0; do case $1 in -e) am_make_rc_exp=$2; shift;; + -O) am__make_redirect="$am__make_redirect >stdout";; + -E) am__make_redirect="$am__make_redirect 2>stderr";; + -M) am__make_redirect=">output 2>&1";; --) shift; break;; *) break;; esac shift done - am__make_flags= + if using_gmake; then # We can trust GNU make to correctly pass macro definitions given # on the command line down to sub-make invocations, and this allow @@ -221,12 +241,23 @@ run_make () done unset am__x fi + if test x"$am__make_flags" != x; then - $MAKE AM_MAKEFLAGS="$am__make_flags" ${1+"$@"} || am_make_rc_got=$? - else - $MAKE ${1+"$@"} || am_make_rc_got=$? + set AM_MAKEFLAGS="$am__make_flags" ${1+"$@"} + unset am__make_flags fi - unset am__make_flags + + eval "\$MAKE${am__make_redirect}"' ${1+"$@"}' || am_make_rc_got=$? + + case $am__make_redirect in + *output*) cat output;; + *stderr*stdout*) cat stdout && cat stderr >&2;; + *stdout*stderr*) cat stdout && cat stderr >&2;; + *stdout*) cat stdout;; + *stderr*) cat stderr >&2;; + esac \ + || fatal_ "displaying make output" + case $am_make_rc_exp in IGNORE) : Ignore exit status @@ -240,6 +271,7 @@ run_make () test $am_make_rc_exp -eq $am_make_rc_got || return 1 ;; esac + unset am__make_redirect } # AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...] |