From 7cf7c33cd264c565ef2557d485bb08d4fe3a73ba Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 18 Apr 2021 12:45:24 +0100 Subject: [PATCH] libtest-core: 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 --- tests/libtest-core.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/libtest-core.sh b/tests/libtest-core.sh index 0255b57..e08c4c2 100644 --- a/tests/libtest-core.sh +++ b/tests/libtest-core.sh @@ -162,3 +162,11 @@ skip() { extract_child_pid() { grep child-pid "$1" | sed "s/^.*: \([0-9]*\).*/\1/" } + +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