aboutsummaryrefslogtreecommitdiffstats
path: root/t/test-lib.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 16:41:12 +0900
committerJunio C Hamano <gitster@pobox.com>2019-04-25 16:41:12 +0900
commit579b75ad9530827fe00740b8551963f16f279c40 (patch)
tree9beebfa6f1162d688b034923b2ba3498cf6597e5 /t/test-lib.sh
parente62e68d35949235435ea7f7d22ab6ea678fd46b0 (diff)
parent74ec8cf6747a60885e15d4c36e6b47bc37764748 (diff)
downloadgit-579b75ad9530827fe00740b8551963f16f279c40.tar.gz
Merge branch 'sg/test-atexit'
Test framework update to more robustly clean up leftover files and processes after tests are done. * sg/test-atexit: t9811-git-p4-label-import: fix pipeline negation git p4 test: disable '-x' tracing in the p4d watchdog loop git p4 test: simplify timeout handling git p4 test: clean up the p4d cleanup functions git p4 test: use 'test_atexit' to kill p4d and the watchdog process t0301-credential-cache: use 'test_atexit' to stop the credentials helper tests: use 'test_atexit' to stop httpd git-daemon: use 'test_atexit` to stop 'git-daemon' test-lib: introduce 'test_atexit' t/lib-git-daemon: make sure to kill the 'git-daemon' process test-lib: fix interrupt handling with 'dash' and '--verbose-log -x'
Diffstat (limited to 't/test-lib.sh')
-rw-r--r--t/test-lib.sh28
1 files changed, 27 insertions, 1 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index c14ebe68d3..38b157075a 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -634,6 +634,10 @@ test_external_has_tap=0
die () {
code=$?
+ # This is responsible for running the atexit commands even when a
+ # test script run with '--immediate' fails, or when the user hits
+ # ctrl-C, i.e. when 'test_done' is not invoked at all.
+ test_atexit_handler || code=$?
if test -n "$GIT_EXIT_OK"
then
exit $code
@@ -645,7 +649,10 @@ die () {
GIT_EXIT_OK=
trap 'die' EXIT
-trap 'exit $?' INT TERM HUP
+# Disable '-x' tracing, because with some shells, notably dash, it
+# prevents running the cleanup commands when a test script run with
+# '--verbose-log -x' is interrupted.
+trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
# The user-facing functions are loaded from a separate file so that
# test_perf subshells can have them too
@@ -1056,9 +1063,28 @@ write_junit_xml_testcase () {
junit_have_testcase=t
}
+test_atexit_cleanup=:
+test_atexit_handler () {
+ # In a succeeding test script 'test_atexit_handler' is invoked
+ # twice: first from 'test_done', then from 'die' in the trap on
+ # EXIT.
+ # This condition and resetting 'test_atexit_cleanup' below makes
+ # sure that the registered cleanup commands are run only once.
+ test : != "$test_atexit_cleanup" || return 0
+
+ setup_malloc_check
+ test_eval_ "$test_atexit_cleanup"
+ test_atexit_cleanup=:
+ teardown_malloc_check
+}
+
test_done () {
GIT_EXIT_OK=t
+ # Run the atexit commands _before_ the trash directory is
+ # removed, so the commands can access pidfiles and socket files.
+ test_atexit_handler
+
if test -n "$write_junit_xml" && test -n "$junit_xml_path"
then
test -n "$junit_have_testcase" || {