xref: /netbsd-src/tests/bin/sh/t_evaltested.sh (revision c43f84898fa03efc71f86199d80cde51303d42da)
1*c43f8489Schristos# $NetBSD: t_evaltested.sh,v 1.2 2016/03/27 14:50:01 christos Exp $
228604916Sjruoho#
328604916Sjruoho# Copyright (c) 2011 The NetBSD Foundation, Inc.
428604916Sjruoho# All rights reserved.
528604916Sjruoho#
628604916Sjruoho# Redistribution and use in source and binary forms, with or without
728604916Sjruoho# modification, are permitted provided that the following conditions
828604916Sjruoho# are met:
928604916Sjruoho# 1. Redistributions of source code must retain the above copyright
1028604916Sjruoho#    notice, this list of conditions and the following disclaimer.
1128604916Sjruoho# 2. Redistributions in binary form must reproduce the above copyright
1228604916Sjruoho#    notice, this list of conditions and the following disclaimer in the
1328604916Sjruoho#    documentation and/or other materials provided with the distribution.
1428604916Sjruoho#
1528604916Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1628604916Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1728604916Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1828604916Sjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1928604916Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2028604916Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2128604916Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2228604916Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2328604916Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2428604916Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2528604916Sjruoho# POSSIBILITY OF SUCH DAMAGE.
2628604916Sjruoho#
27*c43f8489Schristos# the implementation of "sh" to test
28*c43f8489Schristos: ${TEST_SH:="/bin/sh"}
2928604916Sjruoho
3028604916Sjruohoatf_test_case evaltested
3128604916Sjruoho
3228604916Sjruohoevaltested_head() {
3328604916Sjruoho	atf_set "descr" "Tests that eval in a tested context does not exit"
3428604916Sjruoho}
3528604916Sjruoho
3628604916Sjruohoevaltested_body() {
3728604916Sjruoho	set -e
3828604916Sjruohocat > helper.sh << EOF
3928604916Sjruohoset -e
4028604916Sjruohoif eval false
4128604916Sjruohothen
4228604916Sjruoho	echo "'eval false' returned true"
4328604916Sjruoho	exit 1
4428604916Sjruohofi
4528604916Sjruohoecho "passed"
4628604916Sjruohoexit 0
4728604916SjruohoEOF
48*c43f8489Schristos	output="$($TEST_SH helper.sh)"
4928604916Sjruoho	[ $? = 0 ] && return
5028604916Sjruoho
5128604916Sjruoho	if [ -n "$output" ]
5228604916Sjruoho	then
5328604916Sjruoho		atf_fail "$output"
5428604916Sjruoho	else
5528604916Sjruoho		atf_fail "'eval false' exited from a tested context"
5628604916Sjruoho	fi
5728604916Sjruoho
5828604916Sjruoho}
5928604916Sjruoho
6028604916Sjruohoatf_init_test_cases() {
6128604916Sjruoho	atf_add_test_case evaltested
6228604916Sjruoho}
63