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

Re: [PATCH] test-lib.sh: work around ksh's trap shortcomings

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 18, 2008, 23:48 UTC
Message-ID
<7vbpzplw9o.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<gPlIc7E6mNDrXE6mwaHXFoin7rDpLmjvuzlhJfCp-YmuyVK3pEzqNA@cipher.nrlssc.navy.mil>
Brandon Casey <casey@nrlssc.navy.mil> writes:
> In ksh, if trap is called within a function with 0 or EXIT as its signal,
> then the trap will be executed at the time the function returns. This
> causes a problem in the test functions since 'trap - exit' is called
> within the test_done function

Your alias test_done that calls function test_done look ugly and confusing beyond words. Perhaps test_done() can instead set a global variable and die() can notice it instead, like this? I haven't bothered to change the other "trap - exit" but I think you got the idea...

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 11c0275..010bfda 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -156,10 +156,16 @@ test_count=0
 test_fixed=0
 test_broken=0
 test_success=0
+test_exit_ok=0
 
 die () {
-	echo >&5 "FATAL: Unexpected exit with code $?"
-	exit 1
+	status=$?
+	if test 1 != $test_exit_ok
+	then
+		echo >&5 "FATAL: Unexpected exit with code $status"
+		exit 1
+	fi
+	exit $status
 }
 
 trap 'die' exit
@@ -415,6 +421,7 @@ test_create_repo () {
 }
 
 test_done () {
+	test_exit_ok=1
 	trap - exit
 	test_results_dir="$TEST_DIRECTORY/test-results"
 	mkdir -p "$test_results_dir"
Previous: Brandon CaseyNext: Brandon Casey
Message 10 of 28 in “[FYI] How I compile on IRIX 6.5 with the MIPSpro compiler and ksh”
  1. Brandon CaseyAug 18, 2008
  2. Makefile: add section for SGI IRIXBrandon Casey, Aug 18, 2008
  3. git-compat-util.h: adjust for SGI IRIX 6.5Brandon Casey, Aug 18, 2008
  4. unpack-trees.c: work around run-time array initialization flaw on IRIX 6.5Brandon Casey, Aug 18, 2008
  5. templates/Makefile: work around SGI install which assumes / if ROOT not definedBrandon Casey, Aug 18, 2008
  6. Junio C HamanoAug 18, 2008
  7. Brandon CaseyAug 19, 2008
  8. templates/Makefile: install is unnecessary, just use mkdir -pBrandon Casey, Aug 22, 2008
  9. test-lib.sh: work around ksh's trap shortcomingsBrandon Casey, Aug 18, 2008
  10. Junio C HamanoAug 18, 2008
  11. Brandon CaseyAug 19, 2008
  12. Junio C HamanoAug 19, 2008
  13. Brandon CaseyAug 19, 2008
  14. Brandon CaseyAug 19, 2008
  15. Brandon CaseyAug 20, 2008
  16. Mike RalphsonAug 20, 2008
  17. t1002-read-tree-m-u-2way.sh: use 'git diff -U0' rather than 'diff -U0'Brandon Casey, Aug 18, 2008
  18. t9301-fast-export.sh: don't unset config variable while we're skipping test 4Brandon Casey, Aug 18, 2008
  19. Junio C HamanoAug 19, 2008
  20. Brandon CaseyAug 19, 2008
  21. t9301-fast-export: move unset of config variable into its own test functionBrandon Casey, Aug 22, 2008
  22. Junio C HamanoAug 22, 2008
  23. Junio C HamanoAug 22, 2008
  24. Johannes SixtAug 22, 2008
  25. Junio C HamanoAug 22, 2008
  26. Brandon CaseyAug 18, 2008
  27. Boyd Lynn GerberAug 19, 2008
  28. Brandon CaseyAug 19, 2008

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.