1 # Copyright (c) 2010 The NetBSD Foundation, Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
13 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 : ${ATF_SH:="__ATF_SH__"}
28 create_test_program() {
29 local output="${1}"; shift
30 echo "#! ${ATF_SH} ${*}" >"${output}"
39 atf-sh: ERROR: No test program provided
40 atf-sh: See atf-sh(1) for usage details.
42 atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}"
45 atf_test_case missing_script
49 atf-sh: ERROR: The test program 'non-existent' does not exist
51 atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" non-existent
54 atf_test_case arguments
57 create_test_program tp <<EOF
60 while test \${#} -gt 0; do
73 atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo
80 atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" tp \
81 ' hello bye ' 'foo bar'
84 atf_test_case custom_shell__command_line
85 custom_shell__command_line_body()
88 This is the custom shell
89 This is the test program
92 cat >custom-shell <<EOF
94 echo "This is the custom shell"
99 echo 'main() { echo "This is the test program"; }' | create_test_program tp
100 atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" -s ./custom-shell tp
103 atf_test_case custom_shell__shebang
104 custom_shell__shebang_body()
107 This is the custom shell
108 This is the test program
111 cat >custom-shell <<EOF
113 echo "This is the custom shell"
116 chmod +x custom-shell
118 echo 'main() { echo "This is the test program"; }' | create_test_program \
119 tp "-s$(pwd)/custom-shell"
120 atf_check -s eq:0 -o file:expout -e empty ./tp
126 atf_set "descr" "Simple test to validate that atf-sh works even when" \
131 cat >custom-shell <<EOF
133 exec /bin/sh -e "\${@}"
135 chmod +x custom-shell
142 atf_init_test_cases() {
143 atf_add_test_case helper
146 atf_check -s eq:0 -o match:skipped.*reached \
147 "${ATF_SH}" -s ./custom-shell tp helper
150 atf_init_test_cases()
152 atf_add_test_case no_args
153 atf_add_test_case missing_script
154 atf_add_test_case arguments
155 atf_add_test_case custom_shell__command_line
156 atf_add_test_case custom_shell__shebang
157 atf_add_test_case set_e
160 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4