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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Brandon Casey <casey@xxxxxxxxxxxxxxxxxxxxx>

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]