Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: test for trap EXIT fix.



Here's a test that nested EXIT traps work when exiting from within a
function.

The comment notes the following behaviour:

fn() { 
  ( trap 'print This is in the top-level function scope.' EXIT
    exit
  )
}

The subshell exits without ever leaving the scope of fn(), so the EXIT trap
isn't called in this case.

I'm not convinced this is wrong, or at least that it's inconsistent.
Exiting subshells is a bit of a special case.

Index: Test/C03traps.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C03traps.ztst,v
retrieving revision 1.1
diff -u -r1.1 C03traps.ztst
--- Test/C03traps.ztst	2001/04/02 12:32:43	1.1
+++ Test/C03traps.ztst	2001/10/01 11:56:41
@@ -45,6 +45,18 @@
 0:Nested `trap - EXIT' on `TRAPEXIT'
 >EXIT1
 
+# We can't test an EXIT trap for the shell as a whole, because
+# we're inside a function scope which we don't leave when the
+# subshell exits.  Not sure if that's the correct behaviour, but
+# it's sort of consistent.
+  ( fn1() { trap 'print Function 1 going' EXIT; exit; print Not reached; }
+    fn2() { trap 'print Function 2 going' EXIT; fn1; print Not reached; }
+    fn2
+  )
+0:EXIT traps on functions when exiting from function
+>Function 1 going
+>Function 2 going
+
   fn1() {
     trap
     trap 'print INT1' INT

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author