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 <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2021-04-18 12:16:45 +01:00
parent e4d42be31f
commit 9d48d39a4b
1 changed files with 8 additions and 0 deletions

View File

@ -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"