diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index cb3c8f2fb9..d95ca7b897 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -90,6 +90,9 @@ # # Each component must start by invoking `msg` with a short informative message. # +# Warning: due to the way bash detects errors, the failure of a command +# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'. +# # Each component is executed in a separate shell process. The component # fails if any command in it returns a non-zero status. # @@ -484,6 +487,7 @@ pre_setup_keep_going () { previous_failure_status=0 previous_failed_command= previous_failure_funcall_depth=0 + unset report_failed_command start_red= end_color= @@ -508,7 +512,7 @@ pre_setup_keep_going () { "msg "*) false;; *[!A-Za-z]"test"|*[!A-Za-z]"test"[!A-Za-z]*) true;; "tests/"*) true;; - "grep "*|"not grep "*) true;; + "grep "*|"! grep "*) true;; *) false;; esac } @@ -520,7 +524,7 @@ pre_setup_keep_going () { # Save $? (status of the failing command). This must be the very # first thing, before $? is overridden. last_failure_status=$? - failed_command=$BASH_COMMAND + failed_command=${report_failed_command-$BASH_COMMAND} if [[ $last_failure_status -eq $previous_failure_status && "$failed_command" == "$previous_failed_command" && @@ -578,8 +582,14 @@ if_build_succeeded () { "$@" } -not() { - ! "$@" +# '! true' does not trigger the ERR trap. Arrange to trigger it, with +# a reasonably informative error message (not just "$@"). +not () { + if "$@"; then + report_failed_command="! $*" + false + unset report_failed_command + fi } pre_setup_quiet_redirect () {