mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-07 13:22:46 +00:00
Better not function
In the `not` function, in keep-going mode, arrange to report the failing command (rather than `"$@"`). Note that the `!` keyword should not be used, because failures with `!` are not reported properly. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
fec30cbe8c
commit
a681c59d34
@ -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 () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user