1#
2# Automated Testing Framework (atf)
3#
4# Copyright (c) 2007, 2008, 2010 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30atf_test_case exitcode_0_0
31exitcode_0_0_head()
32{
33    atf_set "descr" "Runs a program that returns true and expects true"
34}
35exitcode_0_0_body()
36{
37    atf_check -s eq:0 -o empty -e empty true
38}
39
40atf_test_case exitcode_0_1
41exitcode_0_1_head()
42{
43    atf_set "descr" "Runs a program that returns true and expects false"
44}
45exitcode_0_1_body()
46{
47    atf_check -s eq:1 -o empty -e empty true
48}
49
50atf_test_case exitcode_1_0
51exitcode_1_0_head()
52{
53    atf_set "descr" "Runs a program that returns false and expects true"
54}
55exitcode_1_0_body()
56{
57    atf_check -s eq:0 -o empty -e empty false
58}
59
60atf_test_case exitcode_1_1
61exitcode_1_1_head()
62{
63    atf_set "descr" "Runs a program that returns false and expects false"
64}
65exitcode_1_1_body()
66{
67    # In Solaris, /usr/bin/false returns 255 rather than 1.  Use the
68    # built-in version for the check.
69    atf_check -s eq:1 -o empty -e empty sh -c "false"
70}
71
72atf_test_case stdout_expout_pass
73stdout_expout_pass_head()
74{
75    atf_set "descr" "Runs a program with stdout set to expout and passes"
76}
77stdout_expout_pass_body()
78{
79    echo foo >expout
80    atf_check -s eq:0 -o file:expout -e empty echo foo
81}
82
83atf_test_case stdout_expout_fail
84stdout_expout_fail_head()
85{
86    atf_set "descr" "Runs a program with stdout set to expout and fails"
87}
88stdout_expout_fail_body()
89{
90    echo foo >expout
91    atf_check -s eq:0 -o file:expout -e empty echo bar
92}
93
94atf_test_case stdout_ignore_empty
95stdout_ignore_empty_head()
96{
97    atf_set "descr" "Runs a program with stdout set to ignore and" \
98                    "writes nothing"
99}
100stdout_ignore_empty_body()
101{
102    atf_check -s eq:0 -o ignore -e empty true
103}
104
105atf_test_case stdout_ignore_sth
106stdout_ignore_sth_head()
107{
108    atf_set "descr" "Runs a program with stdout set to ignore and" \
109                    "writes something"
110}
111stdout_ignore_sth_body()
112{
113    atf_check -s eq:0 -o ignore -e empty echo foo
114}
115
116atf_test_case stdout_null_empty
117stdout_null_empty_head()
118{
119    atf_set "descr" "Runs a program with stdout set to null and" \
120                    "writes nothing"
121}
122stdout_null_empty_body()
123{
124    atf_check -s eq:0 -o empty -e empty true
125}
126
127atf_test_case stdout_null_sth
128stdout_null_sth_head()
129{
130    atf_set "descr" "Runs a program with stdout set to null and" \
131                    "writes something"
132}
133stdout_null_sth_body()
134{
135    atf_check -s eq:0 -o empty -e empty echo foo
136}
137
138atf_test_case stdout_stdout_written
139stdout_stdout_written_head()
140{
141    atf_set "descr" "Runs a program with stdout set to stdout and" \
142                    "writes something"
143}
144stdout_stdout_written_body()
145{
146    atf_check -s eq:0 -o save:stdout -e empty echo foo
147    echo foo >aux
148    cmp -s stdout aux || atf_fail "Test failed"
149}
150
151atf_test_case stdout_match_ok
152stdout_match_ok_head()
153{
154    atf_set "descr" "Runs a program with stdout set to match and" \
155                    "matches the regular expression"
156}
157stdout_match_ok_body()
158{
159    atf_check -s eq:0 -o 'match:bar$' -e empty -x "echo line; echo foo bar"
160}
161
162atf_test_case stdout_match_fail
163stdout_match_fail_head()
164{
165    atf_set "descr" "Runs a program with stdout set to match and" \
166                    "does not match the regular expression"
167}
168stdout_match_fail_body()
169{
170    atf_check -s eq:0 -o 'match:bar$' -e empty -x "echo line; echo foo bar baz"
171}
172
173atf_test_case stderr_experr_pass
174stderr_experr_pass_head()
175{
176    atf_set "descr" "Runs a program with stderr set to experr and passes"
177}
178stderr_experr_pass_body()
179{
180    echo foo >experr
181    atf_check -s eq:0 -o empty -e file:experr -x 'echo foo 1>&2'
182}
183
184atf_test_case stderr_experr_fail
185stderr_experr_fail_head()
186{
187    atf_set "descr" "Runs a program with stderr set to experr and fails"
188}
189stderr_experr_fail_body()
190{
191    echo foo >experr
192    atf_check -s eq:0 -o empty -e file:stderr -x 'echo bar 1>&2'
193}
194
195atf_test_case stderr_ignore_empty
196stderr_ignore_empty_head()
197{
198    atf_set "descr" "Runs a program with stderr set to ignore and" \
199                    "writes nothing"
200}
201stderr_ignore_empty_body()
202{
203    atf_check -s eq:0 -o empty -e ignore -x 'true 1>&2'
204}
205
206atf_test_case stderr_ignore_sth
207stderr_ignore_sth_head()
208{
209    atf_set "descr" "Runs a program with stderr set to ignore and" \
210                    "writes something"
211}
212stderr_ignore_sth_body()
213{
214    atf_check -s eq:0 -o empty -e ignore -x 'echo foo 1>&2'
215}
216
217atf_test_case stderr_null_empty
218stderr_null_empty_head()
219{
220    atf_set "descr" "Runs a program with stderr set to null and" \
221                    "writes nothing"
222}
223stderr_null_empty_body()
224{
225    atf_check -s eq:0 -o empty -e empty -x 'true 1>&2'
226}
227
228atf_test_case stderr_null_sth
229stderr_null_sth_head()
230{
231    atf_set "descr" "Runs a program with stderr set to null and" \
232                    "writes something"
233}
234stderr_null_sth_body()
235{
236    atf_check -s eq:0 -o empty -e empty -x 'echo foo 1>&2'
237}
238
239atf_test_case stderr_stderr_written
240stderr_stderr_written_head()
241{
242    atf_set "descr" "Runs a program with stderr set to stderr and" \
243                    "writes something"
244}
245stderr_stderr_written_body()
246{
247    atf_check -s eq:0 -o empty -e save:stderr -x 'echo foo 1>&2'
248    echo foo >aux
249    cmp -s stderr aux || atf_fail "Test failed"
250}
251
252atf_test_case stderr_match_ok
253stderr_match_ok_head()
254{
255    atf_set "descr" "Runs a program with stderr set to match and" \
256                    "matches the regular expression"
257}
258stderr_match_ok_body()
259{
260    atf_check -s eq:0 -o empty -e 'match:bar$' -x \
261        "echo line 1>&2; echo foo bar 1>&2"
262}
263
264atf_test_case stderr_match_fail
265stderr_match_fail_head()
266{
267    atf_set "descr" "Runs a program with stderr set to match and" \
268                    "does not match the regular expression"
269}
270stderr_match_fail_body()
271{
272    atf_check -s eq:0 -o empty -e 'match:bar$' -x \
273        "echo line 1>&2; echo foo bar baz 1>&2"
274}
275
276atf_init_test_cases()
277{
278    atf_add_test_case exitcode_0_0
279    atf_add_test_case exitcode_0_1
280    atf_add_test_case exitcode_1_0
281    atf_add_test_case exitcode_1_1
282
283    atf_add_test_case stdout_expout_pass
284    atf_add_test_case stdout_expout_fail
285    atf_add_test_case stdout_ignore_empty
286    atf_add_test_case stdout_ignore_sth
287    atf_add_test_case stdout_null_empty
288    atf_add_test_case stdout_null_sth
289    atf_add_test_case stdout_stdout_written
290    atf_add_test_case stdout_match_ok
291    atf_add_test_case stdout_match_fail
292
293    atf_add_test_case stderr_experr_pass
294    atf_add_test_case stderr_experr_fail
295    atf_add_test_case stderr_ignore_empty
296    atf_add_test_case stderr_ignore_sth
297    atf_add_test_case stderr_null_empty
298    atf_add_test_case stderr_null_sth
299    atf_add_test_case stderr_stderr_written
300    atf_add_test_case stderr_match_ok
301    atf_add_test_case stderr_match_fail
302}
303
304# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
305