From 6d06e772f7d0cb537afe2ad77313805795c6b493 Mon Sep 17 00:00:00 2001 From: jmmv Date: Fri, 29 Apr 2011 12:49:36 +0000 Subject: [PATCH] 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. --- tests/util/sh/t_exit.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/util/sh/t_exit.sh b/tests/util/sh/t_exit.sh index e3b95576579a..2c90dd58a7ed 100644 --- a/tests/util/sh/t_exit.sh +++ b/tests/util/sh/t_exit.sh @@ -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_subshell_body() { '( 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 }