]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/atf/atf-sh/integration_test.sh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / atf / atf-sh / integration_test.sh
1 # Copyright (c) 2010 The NetBSD Foundation, Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
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.
12 #
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.
25
26 : ${ATF_SH:="__ATF_SH__"}
27
28 create_test_program() {
29     local output="${1}"; shift
30     echo "#! ${ATF_SH} ${*}" >"${output}"
31     cat >>"${output}"
32     chmod +x "${output}"
33 }
34
35 atf_test_case no_args
36 no_args_body()
37 {
38     cat >experr <<EOF
39 atf-sh: ERROR: No test program provided
40 atf-sh: See atf-sh(1) for usage details.
41 EOF
42     atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}"
43 }
44
45 atf_test_case missing_script
46 missing_script_body()
47 {
48     cat >experr <<EOF
49 atf-sh: ERROR: The test program 'non-existent' does not exist
50 EOF
51     atf_check -s eq:1 -o ignore -e file:experr "${ATF_SH}" non-existent
52 }
53
54 atf_test_case arguments
55 arguments_body()
56 {
57     create_test_program tp <<EOF
58 main() {
59     echo ">>>\${0}<<<"
60     while test \${#} -gt 0; do
61         echo ">>>\${1}<<<"
62         shift
63     done
64     true
65 }
66 EOF
67
68     cat >expout <<EOF
69 >>>./tp<<<
70 >>> a b <<<
71 >>>foo<<<
72 EOF
73     atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo
74
75     cat >expout <<EOF
76 >>>tp<<<
77 >>> hello bye <<<
78 >>>foo bar<<<
79 EOF
80     atf_check -s eq:0 -o file:expout -e empty "${ATF_SH}" tp \
81         ' hello bye ' 'foo bar'
82 }
83
84 atf_test_case custom_shell__command_line
85 custom_shell__command_line_body()
86 {
87     cat >expout <<EOF
88 This is the custom shell
89 This is the test program
90 EOF
91
92     cat >custom-shell <<EOF
93 #! /bin/sh
94 echo "This is the custom shell"
95 exec /bin/sh "\${@}"
96 EOF
97     chmod +x custom-shell
98
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
101 }
102
103 atf_test_case custom_shell__shebang
104 custom_shell__shebang_body()
105 {
106     cat >expout <<EOF
107 This is the custom shell
108 This is the test program
109 EOF
110
111     cat >custom-shell <<EOF
112 #! /bin/sh
113 echo "This is the custom shell"
114 exec /bin/sh "\${@}"
115 EOF
116     chmod +x custom-shell
117
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
121 }
122
123 atf_test_case set_e
124 set_e_head()
125 {
126     atf_set "descr" "Simple test to validate that atf-sh works even when" \
127         "set -e is enabled"
128 }
129 set_e_body()
130 {
131     cat >custom-shell <<EOF
132 #! /bin/sh
133 exec /bin/sh -e "\${@}"
134 EOF
135     chmod +x custom-shell
136
137     cat >tp <<EOF
138 atf_test_case helper
139 helper_body() {
140     atf_skip "reached"
141 }
142 atf_init_test_cases() {
143     atf_add_test_case helper
144 }
145 EOF
146     atf_check -s eq:0 -o match:skipped.*reached \
147         "${ATF_SH}" -s ./custom-shell tp helper
148 }
149
150 atf_init_test_cases()
151 {
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
158 }
159
160 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4