From fec30cbe8c800dcc3615601eb2d6859de8d78da5 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Sat, 28 Mar 2020 19:34:23 +0100 Subject: [PATCH] Fix double reporting when the last command of a function fails Signed-off-by: Gilles Peskine --- tests/scripts/all.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 8b8e3dd590..cb3c8f2fb9 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -480,6 +480,11 @@ pre_setup_keep_going () { failure_count=0 # Number of failed components last_failure_status=0 # Last failure status in this component + # See err_trap + previous_failure_status=0 + previous_failed_command= + previous_failure_funcall_depth=0 + start_red= end_color= if [ -t 1 ]; then @@ -517,6 +522,21 @@ pre_setup_keep_going () { last_failure_status=$? failed_command=$BASH_COMMAND + if [[ $last_failure_status -eq $previous_failure_status && + "$failed_command" == "$previous_failed_command" && + ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]] + then + # The same command failed twice in a row, but this time one level + # less deep in the function call stack. This happens when the last + # command of a function returns a nonzero status, and the function + # returns that same status. Ignore the second failure. + previous_failure_funcall_depth=${#FUNCNAME[@]} + return + fi + previous_failure_status=$last_failure_status + previous_failed_command=$failed_command + previous_failure_funcall_depth=${#FUNCNAME[@]} + text="$current_section: $failed_command -> $last_failure_status" echo "${start_red}^^^^$text^^^^${end_color}" >&2 echo "$text" >>"$failure_summary_file"