libtest-core: On failure, make it clearer what has happened
authorSimon McVittie <smcv@collabora.com>
Sun, 18 Apr 2021 11:45:24 +0000 (12:45 +0100)
committerSimon McVittie <smcv@collabora.com>
Fri, 18 Jun 2021 08:49:53 +0000 (09:49 +0100)
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>
tests/kolainst/libtest-core.sh

index 471a63f01dc20383a917de7c23cacf47a0d987e5..7179a408e08f8bd657d921881cd6abecf0519f64 100644 (file)
@@ -179,3 +179,11 @@ skip() {
     echo "1..0 # SKIP" "$@"
     exit 0
 }
+
+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