Module Name: src
Committed By: jmmv
Date: Fri Apr 29 12:49:36 UTC 2011
Modified Files:
src/tests/util/sh: t_exit.sh
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/util/sh/t_exit.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/util/sh/t_exit.sh
diff -u src/tests/util/sh/t_exit.sh:1.1 src/tests/util/sh/t_exit.sh:1.2
--- src/tests/util/sh/t_exit.sh:1.1 Tue Oct 20 21:58:35 2009
+++ src/tests/util/sh/t_exit.sh Fri Apr 29 12:49:36 2011
@@ -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
}