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

[PATCH] t0005: add test for trap handling from deeply nested function calls

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Mar 26, 2010, 16:34 UTC
Message-ID
<vm2zHZjrZOha7LnIM_9fAEAvwVZrJtZlAI9f2XI_VUsdqr51ihAMW68a5BT9tvMdRDSqk6GYlSE@cipher.nrlssc.navy.mil>
From: Brandon Casey <drafnel@gmail.com>

The /usr/xpg4/bin/sh shell on Solaris only executes a trap handler set within a function from the first-level function call made from within the function that set the trap. In other words, if func1 sets a trap, then calls func2 which triggers the trap, then the trap handler will be executed correctly. If instead of exiting, func2 calls func3, and func3 satisfies the conditions for triggering the trap, the trap handler will NOT be executed.

This trap sequence exists in git-bisect.sh and is exercised by tests t6030.12 and t6030.13 which fail when the /usr/xpg4/bin/sh shell is used.

Add a test that will fail sooner and more precisely than the t6030 tests.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
Improvements to the commit message are welcome.
-brandon
 t/t0005-signals.sh |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh
index 09f855a..cb68d1f 100755
--- a/t/t0005-signals.sh
+++ b/t/t0005-signals.sh
@@ -19,4 +19,12 @@ test_expect_success 'sigchain works' '
 	test_cmp expect actual
 '
 
+test_expect_success 'trap triggered in deeply nested function works correctly' '
+	(atrap () { exit 0; }
+	 func3 () { exit 1; }
+	 func2 () { func3; }
+	 func1 () { trap atrap EXIT; func2; }
+	 func1)
+'
+
 test_done
-- 
1.6.6.2
Next: Junio C Hamano
Message 1 of 4 in “t0005: add test for trap handling from deeply nested function calls”
  1. t0005: add test for trap handling from deeply nested function callsBrandon Casey, Mar 26, 2010
  2. Junio C HamanoMar 26, 2010
  3. Johannes SixtMar 26, 2010
  4. Brandon CaseyMar 27, 2010

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.