1 # Copyright (c) 2008 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 # The Atf_Check and Atf-Shell variables are set by atf-sh.
32 echo "Running [atf-check $*] against [${cmd}]"
40 if ! ${Atf_Check} "${@}" ./script.sh >tmp; then
42 atf_fail "atf-check failed"
50 echo "Running [atf-check $*] against [${cmd}]"
58 if ${Atf_Check} "${@}" ./script.sh 2>tmp; then
60 atf_fail "atf-check succeeded but should fail"
64 atf_test_case sflag_eq_ne
67 atf_set "descr" "Tests for the -s option using the 'eq' and 'ne' qualifiers"
72 h_pass "false" -s ne:0
73 h_pass "exit 255" -s eq:255
74 h_pass "exit 0" -s ne:255
76 h_fail "exit 256" -s eq:256
77 h_fail "exit -1" -s eq:-1
78 h_fail "true" -s ne:256
79 h_fail "true" -s ne:-1
82 atf_test_case sflag_exit
85 atf_set "descr" "Tests for the -s option using the 'exit' qualifier"
89 h_pass 'true' -s exit:0
90 h_pass 'false' -s not-exit:0
91 h_pass 'exit 255' -s exit:255
92 h_pass 'exit 0' -s not-exit:255
94 h_fail 'exit 256' -s exit:256
95 h_fail 'exit -1' -s exit:-1
96 h_fail 'true' -s not-exit:256
97 h_fail 'true' -s not-exit:-1
100 h_pass 'false' -s exit
101 if ${Atf_Check} -s exit -x 'kill $$'; then
102 atf_fail "Signal detected as clean exit"
106 atf_test_case sflag_ignore
109 atf_set "descr" "Tests for the -s option using the 'ignore' qualifier"
113 h_pass 'true' -s ignore
114 h_pass 'false' -s ignore
115 if ${Atf_Check} -s ignored -x 'kill $$'; then
116 atf_fail "Signal not ignored"
120 atf_test_case sflag_signal
123 atf_set "descr" "Tests for the -s option using the 'signal' qualifier"
127 ${Atf_Check} -s signal:hup -x 'kill -1 $$' || atf_fail "Signal not detected"
128 ${Atf_Check} -s signal:sighup -x 'kill -1 $$' || atf_fail "Signal not" \
130 ${Atf_Check} -s signal:1 -x 'kill -1 $$' || atf_fail "Signal not detected"
131 ${Atf_Check} -s signal -x 'kill -1 $$' || atf_fail "Signal not detected"
133 ${Atf_Check} -s not-signal:kill -x 'kill -9 $$' && \
134 atf_fail "not-signal:kill matched kill -9"
135 ${Atf_Check} -s not-signal:kill -x 'kill -1 $$' || \
136 atf_fail "not-signal:kill did not match kill -1"
138 h_fail 'true' -s signal
139 h_fail 'false' -s signal
145 atf_set "descr" "Tests for the -x option"
149 ${Atf_Check} -s ne:0 -o ignore -e ignore "echo foo 2>&1" || \
150 atf_fail "Shell command succeeded without -x"
152 ${Atf_Check} -e inline:"foo\n" -x "echo foo 1>&2" || \
153 atf_fail "Cannot run command with -x"
155 ${Atf_Check} -o inline:"foo\n" -x echo foo || \
156 atf_fail "Using -x does not respect all provided arguments"
159 atf_test_case oflag_empty
162 atf_set "descr" "Tests for the -o option using the 'empty' argument"
166 h_pass "true" -o empty
167 h_fail "echo foo" -o empty
170 atf_test_case oflag_ignore
173 atf_set "descr" "Tests for the -o option using the 'ignore' argument"
177 h_pass "true" -o ignore
178 h_pass "echo foo" -o ignore
181 atf_test_case oflag_file
184 atf_set "descr" "Tests for the -o option using the 'file:' argument"
189 h_pass "true" -o file:empty
192 h_pass "echo foo" -o file:text
193 h_fail "echo bar" -o file:text
195 dd if=/dev/urandom of=bin bs=1k count=10
196 h_pass "cat bin" -o file:bin
199 atf_test_case oflag_inline
202 atf_set "descr" "Tests for the -o option using the 'inline:' argument"
206 h_pass "true" -o inline:
207 h_pass "echo foo bar" -o inline:"foo bar\n"
208 h_pass "printf 'foo bar'" -o inline:"foo bar"
209 h_pass "printf '\t\n\t\n'" -o inline:"\t\n\t\n"
210 h_pass "printf '\a\b\033\f\n\r\t\v'" -o inline:"\a\b\e\f\n\r\t\v"
211 h_pass "printf '\011\022\033\012'" -o inline:"\011\022\033\012"
213 h_fail "echo foo bar" -o inline:"foo bar"
214 h_fail "echo -n foo bar" -o inline:"foo bar\n"
217 atf_test_case oflag_match
220 atf_set "descr" "Tests for the -o option using the 'match:' argument"
224 h_pass "printf no-newline" -o "match:^no-newline"
225 h_pass "echo line1; echo foo bar" -o "match:^foo"
226 h_pass "echo foo bar" -o "match:o b"
227 h_fail "echo foo bar" -o "match:baz"
228 h_fail "echo foo bar" -o "match:^bar"
231 atf_test_case oflag_save
234 atf_set "descr" "Tests for the -o option using the 'save:' argument"
238 h_pass "echo foo" -o save:out
240 cmp -s out exp || atf_fail "Saved output does not match expected results"
243 atf_test_case oflag_multiple
244 oflag_multiple_head()
246 atf_set "descr" "Tests for multiple occurrences of the -o option"
248 oflag_multiple_body()
250 h_pass "echo foo bar" -o match:foo -o match:bar
251 h_pass "echo foo; echo bar" -o match:foo -o match:bar
252 h_fail "echo foo baz" -o match:bar -o match:foo
253 h_fail "echo foo; echo baz" -o match:bar -o match:foo
256 atf_test_case oflag_negated
259 atf_set "descr" "Tests for negated occurrences of the -o option"
263 h_fail "echo foo" -o empty
264 h_pass "echo foo" -o not-empty
266 h_pass "echo foo bar" -o match:foo
267 h_fail "echo foo bar" -o not-match:foo
270 atf_test_case eflag_empty
273 atf_set "descr" "Tests for the -e option using the 'empty' argument"
277 h_pass "true 1>&2" -e empty
278 h_fail "echo foo 1>&2" -e empty
281 atf_test_case eflag_ignore
284 atf_set "descr" "Tests for the -e option using the 'ignore' argument"
288 h_pass "true 1>&2" -e ignore
289 h_pass "echo foo 1>&2" -e ignore
292 atf_test_case eflag_file
295 atf_set "descr" "Tests for the -e option using the 'file:' argument"
300 h_pass "true 1>&2" -e file:empty
303 h_pass "echo foo 1>&2" -e file:text
304 h_fail "echo bar 1>&2" -e file:text
306 dd if=/dev/urandom of=bin bs=1k count=10
307 h_pass "cat bin 1>&2" -e file:bin
310 atf_test_case eflag_inline
313 atf_set "descr" "Tests for the -e option using the 'inline:' argument"
317 h_pass "true 1>&2" -e inline:
318 h_pass "echo foo bar 1>&2" -e inline:"foo bar\n"
319 h_pass "printf 'foo bar' 1>&2" -e inline:"foo bar"
320 h_pass "printf '\t\n\t\n' 1>&2" -e inline:"\t\n\t\n"
321 h_pass "printf '\a\b\033\f\n\r\t\v' 1>&2" -e inline:"\a\b\e\f\n\r\t\v"
322 h_pass "printf '\011\022\033\012' 1>&2" -e inline:"\011\022\033\012"
324 h_fail "echo foo bar 1>&2" -e inline:"foo bar"
325 h_fail "echo -n foo bar 1>&2" -e inline:"foo bar\n"
328 atf_test_case eflag_save
331 atf_set "descr" "Tests for the -e option using the 'save:' argument"
335 h_pass "echo foo 1>&2" -e save:out
337 cmp -s out exp || atf_fail "Saved output does not match expected results"
340 atf_test_case eflag_match
343 atf_set "descr" "Tests for the -e option using the 'match:' argument"
347 h_pass "printf no-newline 1>&2" -e "match:^no-newline"
348 h_pass "echo line1 1>&2; echo foo bar 1>&2" -e "match:^foo"
349 h_pass "echo foo bar 1>&2" -e "match:o b"
350 h_fail "echo foo bar 1>&2" -e "match:baz"
351 h_fail "echo foo bar 1>&2" -e "match:^bar"
354 atf_test_case eflag_multiple
355 eflag_multiple_head()
357 atf_set "descr" "Tests for multiple occurrences of the -e option"
359 eflag_multiple_body()
361 h_pass "echo foo bar 1>&2" -e match:foo -e match:bar
362 h_pass "echo foo 1>&2; echo bar 1>&2" -e match:foo -e match:bar
363 h_fail "echo foo baz 1>&2" -e match:bar -e match:foo
364 h_fail "echo foo 1>&2; echo baz 1>&2" -e match:bar -e match:foo
367 atf_test_case eflag_negated
370 atf_set "descr" "Tests for negated occurrences of the -e option"
374 h_fail "echo foo 1>&2" -e empty
375 h_pass "echo foo 1>&2" -e not-empty
377 h_pass "echo foo bar 1>&2" -e match:foo
378 h_fail "echo foo bar 1>&2" -e not-match:foo
384 atf_set "descr" "Tests that stdin is preserved"
388 echo "hello" | ${Atf_Check} -o match:"hello" cat || \
389 atf_fail "atf-check does not seem to respect stdin"
392 atf_test_case invalid_umask
395 atf_set "descr" "Tests for a correct error condition if the umask is" \
401 ${Atf_Check} false 2>stderr && \
402 atf_fail "atf-check returned 0 but it should have failed"
404 grep 'temporary.*current umask.*0222' stderr >/dev/null || \
405 atf_fail "atf-check did not report an error related to the" \
409 atf_init_test_cases()
411 atf_add_test_case sflag_eq_ne
412 atf_add_test_case sflag_exit
413 atf_add_test_case sflag_ignore
414 atf_add_test_case sflag_signal
416 atf_add_test_case xflag
418 atf_add_test_case oflag_empty
419 atf_add_test_case oflag_ignore
420 atf_add_test_case oflag_file
421 atf_add_test_case oflag_inline
422 atf_add_test_case oflag_match
423 atf_add_test_case oflag_save
424 atf_add_test_case oflag_multiple
425 atf_add_test_case oflag_negated
427 atf_add_test_case eflag_empty
428 atf_add_test_case eflag_ignore
429 atf_add_test_case eflag_file
430 atf_add_test_case eflag_inline
431 atf_add_test_case eflag_match
432 atf_add_test_case eflag_save
433 atf_add_test_case eflag_multiple
434 atf_add_test_case eflag_negated
436 atf_add_test_case stdin
438 atf_add_test_case invalid_umask
441 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4