From: Simon McVittie Date: Sun, 18 Apr 2021 11:16:45 +0000 (+0100) Subject: libtest: On failure, make it clearer what has happened X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~3^2~26^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9d48d39a4b16c4faa58488107cd0a53c8144a7ca;p=ostree.git libtest: On failure, make it clearer what has happened If we fail as a result of `set -x`, It's often not completely obvious which command failed or how. Use a trap on ERR to show the command that failed, and its exit status. Signed-off-by: Simon McVittie --- diff --git a/tests/libtest.sh b/tests/libtest.sh index eda3b921..2e9a99df 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -46,6 +46,14 @@ run_exit_cmds() { } trap run_exit_cmds EXIT +report_err () { + local exit_status="$?" + { { local BASH_XTRACEFD=3; } 2> /dev/null + echo "Unexpected nonzero exit status $exit_status while running: $BASH_COMMAND" >&2 + } 3> /dev/null +} +trap report_err ERR + save_core() { if [ -e core ]; then cp core "$test_srcdir/core"