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

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

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Jul 10, 2009, 17:10 UTC
Message-ID
<39niBtmtFs5Sy_fjtaztVpzvYMB2VqzJqRa_5SCfycpkVR-qsHwAomyoqf7KXKH-vbxIhbJxKJM@cipher.nrlssc.navy.mil>
In-Reply-To
<39niBtmtFs5Sy_fjtaztVnLg9Lrx8Lsu5hbcnz9Fsc7tFJx0Z7UST-sRmKU2bdVlCmfkGTgtbs4@cipher.nrlssc.navy.mil>
From: Brandon Casey <casey@argon.nrlssc.navy.mil>

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 in order to remove the trap which calls die() on exit. This means trap has to be called from the scripts top-level. Do so by renaming the test_done function to test_done_func, and then, remove the trap and call test_done_func from within a new alias named test_done.

Additionally, there is some strangeness with respect to aliases and sourced
script files; the alias is not available within the sourced file. So call
'trap - EXIT' directly in lib-git-svn.sh before calling the test_done_func
function.
---
 t/lib-git-svn.sh |   15 ++++++++++-----
 t/test-lib.sh    |    3 ++-
 2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
index 5654962..c49971c 100644
--- a/t/lib-git-svn.sh
+++ b/t/lib-git-svn.sh
@@ -6,11 +6,13 @@ git_svn_id=git""-svn-id
 if test -n "$NO_SVN_TESTS"
 then
 	say 'skipping git svn tests, NO_SVN_TESTS defined'
-	test_done
+	trap - EXIT
+	test_done_func
 fi
 if ! test_have_prereq PERL; then
 	say 'skipping git svn tests, perl not available'
-	test_done
+	trap - EXIT
+	test_done_func
 fi
 
 GIT_DIR=$PWD/.git
@@ -21,7 +23,8 @@ svn >/dev/null 2>&1
 if test $? -ne 1
 then
     say 'skipping git svn tests, svn not found'
-    test_done
+    trap - EXIT
+    test_done_func
 fi
 
 svnrepo=$PWD/svnrepo
@@ -46,7 +49,8 @@ then
 		err='Perl SVN libraries not found or unusable, skipping test'
 	fi
 	say "$err"
-	test_done
+	trap - EXIT
+	test_done_func
 fi
 
 rawsvnrepo="$svnrepo"
@@ -159,7 +163,8 @@ require_svnserve () {
     if test -z "$SVNSERVE_PORT"
     then
         say 'skipping svnserve test. (set $SVNSERVE_PORT to enable)'
-        test_done
+	trap - EXIT
+	test_done_func
     fi
 }
 
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 5fdc5d9..d7c12db 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -504,7 +504,7 @@ test_create_repo () {
 	cd "$owd"
 }
 
-test_done () {
+test_done_func () {
 	GIT_EXIT_OK=t
 	test_results_dir="$TEST_DIRECTORY/test-results"
 	mkdir -p "$test_results_dir"
@@ -544,6 +544,7 @@ test_done () {
 
 	esac
 }
+alias test_done='trap - EXIT && test_done_func'
 
 # Test the binaries we have just built.  The tests are kept in
 # t/ subdirectory and are run in 'trash directory' subdirectory.
-- 
1.6.4.rc0.5.g76f7cf
Previous: Brandon CaseyNext: Brandon Casey
Message 6 of 8 in “How I compile on IRIX 6.5 with the MIPSpro compiler and ksh”
  1. 0/5 How I compile on IRIX 6.5 with the MIPSpro compiler and kshBrandon Casey, Jul 10, 2009
  2. 1/5 unpack-trees.c: work around run-time array initialization flaw on IRIX 6.5Brandon Casey, Jul 10, 2009
  3. 2/5 git-compat-util.h: adjust for SGI IRIX 6.5Brandon Casey, Jul 10, 2009
  4. 3/5 Makefile: add NEEDS_LIBGEN to optionally add -lgen to compile argumentsBrandon Casey, Jul 10, 2009
  5. 4/5 Makefile: add section for SGI IRIX 6.5Brandon Casey, Jul 10, 2009
  6. 5/5 test-lib.sh: work around ksh's trap shortcomingsBrandon Casey, Jul 10, 2009
  7. 6/5 Makefile: update IRIX64 sectionBrandon Casey, Jul 10, 2009
  8. Junio C HamanoJul 11, 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.