git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] test-lib: allow exit trap to be used for cleanup by tests

From
Clemens Buchacher <drizzd@aon.at>
Date
Jun 1, 2009, 12:14 UTC
Message-ID
<1243858482-6353-3-git-send-email-drizzd@aon.at>
In-Reply-To
<1243858482-6353-2-git-send-email-drizzd@aon.at>

Exit trap should not be removed in case tests require cleanup code. This is especially important if tests are executed with the --immediate option.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
---
 t/test-lib.sh |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 6e83ceb..5fdc5d9 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -147,7 +147,7 @@ fi
 
 error () {
 	say_color error "error: $*"
-	trap - EXIT
+	GIT_EXIT_OK=t
 	exit 1
 }
 
@@ -179,10 +179,17 @@ test_broken=0
 test_success=0
 
 die () {
-	echo >&5 "FATAL: Unexpected exit with code $?"
-	exit 1
+	code=$?
+	if test -n "$GIT_EXIT_OK"
+	then
+		exit $code
+	else
+		echo >&5 "FATAL: Unexpected exit with code $code"
+		exit 1
+	fi
 }
 
+GIT_EXIT_OK=
 trap 'die' EXIT
 
 # The semantics of the editor variables are that of invoking
@@ -285,7 +292,7 @@ test_failure_ () {
 	say_color error "FAIL $test_count: $1"
 	shift
 	echo "$@" | sed -e 's/^/	/'
-	test "$immediate" = "" || { trap - EXIT; exit 1; }
+	test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
 }
 
 test_known_broken_ok_ () {
@@ -347,7 +354,7 @@ test_expect_failure () {
 		then
 			test_known_broken_ok_ "$1"
 		else
-		    test_known_broken_failure_ "$1"
+			test_known_broken_failure_ "$1"
 		fi
 	fi
 	echo >&3 ""
@@ -498,7 +505,7 @@ test_create_repo () {
 }
 
 test_done () {
-	trap - EXIT
+	GIT_EXIT_OK=t
 	test_results_dir="$TEST_DIRECTORY/test-results"
 	mkdir -p "$test_results_dir"
 	test_results_path="$test_results_dir/${0%.sh}-$$"
@@ -640,7 +647,7 @@ fi
 test="trash directory.$(basename "$0" .sh)"
 test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test"
 rm -fr "$test" || {
-	trap - EXIT
+	GIT_EXIT_OK=t
 	echo >&5 "FATAL: Cannot prepare test area"
 	exit 1
 }
-- 
1.6.3.1.147.g637c3
Previous: Clemens BuchacherNext: Clemens Buchacher
Message 3 of 5 in “various fixes to the test library”
  1. Clemens BuchacherJun 1, 2009
  2. 1/3 test-lib: fail if invalid options are passedClemens Buchacher, Jun 1, 2009
  3. 2/3 test-lib: allow exit trap to be used for cleanup by testsClemens Buchacher, Jun 1, 2009
  4. 3/3 test-lib: fix http exit codesClemens Buchacher, Jun 1, 2009
  5. Clemens BuchacherJun 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.