Source-Changes-HG archive

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

[src/trunk]: src/tests/util/sh Add test cases for PR bin/6764: 'trap ... 0' i...



details:   https://anonhg.NetBSD.org/src/rev/ed9120358ca7
branches:  trunk
changeset: 764630:ed9120358ca7
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Fri Apr 29 12:49:36 2011 +0000

description:
Add test cases for PR bin/6764: 'trap ... 0' is supposed to execute the
command when the shell exits but it does not work in ksh when the shells
exits "implicitly" (without an explicit exit/return statement).

These new tests cover both sh and ksh.  The ksh part of this does not
strictly belong to this directory, but I think it'd be nice to extend
all the tests in here to cover both interpreters whenever that makes
sense, much like we do with the file system tests.

diffstat:

 tests/util/sh/t_exit.sh |  27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diffs (43 lines):

diff -r c7a1993ae4cf -r ed9120358ca7 tests/util/sh/t_exit.sh
--- a/tests/util/sh/t_exit.sh   Fri Apr 29 10:40:46 2011 +0000
+++ b/tests/util/sh/t_exit.sh   Fri Apr 29 12:49:36 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_exit.sh,v 1.1 2009/10/20 21:58:35 jmmv Exp $
+# $NetBSD: t_exit.sh,v 1.2 2011/04/29 12:49:36 jmmv Exp $
 #
 # Copyright (c) 2007 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -62,8 +62,33 @@
            '( trap "echo exiting" EXIT; /usr/bin/true )'
 }
 
+atf_test_case trap_zero__implicit_exit
+trap_zero__implicit_exit_body() {
+       echo '( trap "echo exiting" 0 )' >helper.sh
+       atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
+       atf_expect_fail "PR bin/6764: sh works but ksh does not"
+       atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
+}
+
+atf_test_case trap_zero__explicit_exit
+trap_zero__explicit_exit_body() {
+       echo '( trap "echo exiting" 0; exit )' >helper.sh
+       atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
+       atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
+}
+
+atf_test_case trap_zero__explicit_return
+trap_zero__explicit_return_body() {
+       echo '( trap "echo exiting" 0; return )' >helper.sh
+       atf_check -s eq:0 -o match:exiting -e empty /bin/sh helper.sh
+       atf_check -s eq:0 -o match:exiting -e empty /bin/ksh helper.sh
+}
+
 atf_init_test_cases() {
        atf_add_test_case function
        atf_add_test_case readout
        atf_add_test_case trap_subshell
+       atf_add_test_case trap_zero__implicit_exit
+       atf_add_test_case trap_zero__explicit_exit
+       atf_add_test_case trap_zero__explicit_return
 }



Home | Main Index | Thread Index | Old Index