2 # Automated Testing Framework (atf)
4 # Copyright (c) 2008 The NetBSD Foundation, Inc.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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.
30 # The Atf_Check and Atf-Shell variables are set by atf-sh.
36 echo "Running [atf-check $*] against [${cmd}]"
44 if ! ${Atf_Check} "${@}" .
/script.sh
>tmp
; then
46 atf_fail
"atf-check failed"
54 echo "Running [atf-check $*] against [${cmd}]"
62 if ${Atf_Check} "${@}" .
/script.sh
2>tmp
; then
64 atf_fail
"atf-check succeeded but should fail"
68 atf_test_case sflag_eq_ne
71 atf_set
"descr" "Tests for the -s option using the 'eq' and 'ne' qualifiers"
76 h_pass
"false" -s ne
:0
77 h_pass
"exit 255" -s eq
:255
78 h_pass
"exit 0" -s ne
:255
80 h_fail
"exit 256" -s eq
:256
81 h_fail
"exit -1" -s eq
:-1
82 h_fail
"true" -s ne
:256
83 h_fail
"true" -s ne
:-1
86 atf_test_case sflag_exit
89 atf_set
"descr" "Tests for the -s option using the 'exit' qualifier"
93 h_pass
'true' -s exit:0
94 h_pass
'false' -s not-exit
:0
95 h_pass
'exit 255' -s exit:255
96 h_pass
'exit 0' -s not-exit
:255
98 h_fail
'exit 256' -s exit:256
99 h_fail
'exit -1' -s exit:-1
100 h_fail
'true' -s not-exit
:256
101 h_fail
'true' -s not-exit
:-1
103 h_pass
'true' -s exit
104 h_pass
'false' -s exit
105 if ${Atf_Check} -s exit -x 'kill $$'; then
106 atf_fail
"Signal detected as clean exit"
110 atf_test_case sflag_ignore
113 atf_set
"descr" "Tests for the -s option using the 'ignore' qualifier"
117 h_pass
'true' -s ignore
118 h_pass
'false' -s ignore
119 if ${Atf_Check} -s ignored
-x 'kill $$'; then
120 atf_fail
"Signal not ignored"
124 atf_test_case sflag_signal
127 atf_set
"descr" "Tests for the -s option using the 'signal' qualifier"
131 ${Atf_Check} -s signal
:hup
-x 'kill -1 $$' || atf_fail
"Signal not detected"
132 ${Atf_Check} -s signal
:sighup
-x 'kill -1 $$' || atf_fail
"Signal not" \
134 ${Atf_Check} -s signal
:1 -x 'kill -1 $$' || atf_fail
"Signal not detected"
135 ${Atf_Check} -s signal
-x 'kill -1 $$' || atf_fail
"Signal not detected"
137 ${Atf_Check} -s not-signal
:kill -x 'kill -9 $$' && \
138 atf_fail
"not-signal:kill matched kill -9"
139 ${Atf_Check} -s not-signal
:kill -x 'kill -1 $$' || \
140 atf_fail
"not-signal:kill did not match kill -1"
142 h_fail
'true' -s signal
143 h_fail
'false' -s signal
149 atf_set
"descr" "Tests for the -x option"
153 ${Atf_Check} -s ne
:0 -o ignore
-e ignore
"echo foo 2>&1" || \
154 atf_fail
"Shell command succeeded without -x"
156 ${Atf_Check} -e inline
:"foo\n" -x "echo foo 1>&2" || \
157 atf_fail
"Cannot run command with -x"
159 ${Atf_Check} -o inline
:"foo\n" -x echo foo || \
160 atf_fail
"Using -x does not respect all provided arguments"
163 atf_test_case oflag_empty
166 atf_set
"descr" "Tests for the -o option using the 'empty' argument"
170 h_pass
"true" -o empty
171 h_fail
"echo foo" -o empty
174 atf_test_case oflag_ignore
177 atf_set
"descr" "Tests for the -o option using the 'ignore' argument"
181 h_pass
"true" -o ignore
182 h_pass
"echo foo" -o ignore
185 atf_test_case oflag_file
188 atf_set
"descr" "Tests for the -o option using the 'file:' argument"
193 h_pass
"true" -o file:empty
196 h_pass
"echo foo" -o file:text
197 h_fail
"echo bar" -o file:text
199 dd if=/dev
/urandom of
=bin bs
=1k count
=10
200 h_pass
"cat bin" -o file:bin
203 atf_test_case oflag_inline
206 atf_set
"descr" "Tests for the -o option using the 'inline:' argument"
210 h_pass
"true" -o inline
:
211 h_pass
"echo foo bar" -o inline
:"foo bar\n"
212 h_pass
"printf 'foo bar'" -o inline
:"foo bar"
213 h_pass
"printf '\t\n\t\n'" -o inline
:"\t\n\t\n"
214 # XXX Ugly hack to workaround the lack of \e in FreeBSD. Also, \e doesn't
215 # seem to work as expected in Linux. Look for a nicer solution.
217 Darwin|FreeBSD|Linux
)
218 h_pass
"printf '\a\b\f\n\r\t\v'" -o inline
:"\a\b\f\n\r\t\v"
221 h_pass
"printf '\a\b\e\f\n\r\t\v'" -o inline
:"\a\b\e\f\n\r\t\v"
224 h_pass
"printf '\011\022\033\012'" -o inline
:"\011\022\033\012"
226 h_fail
"echo foo bar" -o inline
:"foo bar"
227 h_fail
"echo -n foo bar" -o inline
:"foo bar\n"
230 atf_test_case oflag_match
233 atf_set
"descr" "Tests for the -o option using the 'match:' argument"
237 h_pass
"printf no-newline" -o "match:^no-newline"
238 h_pass
"echo line1; echo foo bar" -o "match:^foo"
239 h_pass
"echo foo bar" -o "match:o b"
240 h_fail
"echo foo bar" -o "match:baz"
241 h_fail
"echo foo bar" -o "match:^bar"
244 atf_test_case oflag_save
247 atf_set
"descr" "Tests for the -o option using the 'save:' argument"
251 h_pass
"echo foo" -o save
:out
253 cmp -s out exp || atf_fail
"Saved output does not match expected results"
256 atf_test_case oflag_multiple
257 oflag_multiple_head
()
259 atf_set
"descr" "Tests for multiple occurrences of the -o option"
261 oflag_multiple_body
()
263 h_pass
"echo foo bar" -o match
:foo
-o match
:bar
264 h_pass
"echo foo; echo bar" -o match
:foo
-o match
:bar
265 h_fail
"echo foo baz" -o match
:bar
-o match
:foo
266 h_fail
"echo foo; echo baz" -o match
:bar
-o match
:foo
269 atf_test_case oflag_negated
272 atf_set
"descr" "Tests for negated occurrences of the -o option"
276 h_fail
"echo foo" -o empty
277 h_pass
"echo foo" -o not-empty
279 h_pass
"echo foo bar" -o match
:foo
280 h_fail
"echo foo bar" -o not-match
:foo
283 atf_test_case eflag_empty
286 atf_set
"descr" "Tests for the -e option using the 'empty' argument"
290 h_pass
"true 1>&2" -e empty
291 h_fail
"echo foo 1>&2" -e empty
294 atf_test_case eflag_ignore
297 atf_set
"descr" "Tests for the -e option using the 'ignore' argument"
301 h_pass
"true 1>&2" -e ignore
302 h_pass
"echo foo 1>&2" -e ignore
305 atf_test_case eflag_file
308 atf_set
"descr" "Tests for the -e option using the 'file:' argument"
313 h_pass
"true 1>&2" -e file:empty
316 h_pass
"echo foo 1>&2" -e file:text
317 h_fail
"echo bar 1>&2" -e file:text
319 dd if=/dev
/urandom of
=bin bs
=1k count
=10
320 h_pass
"cat bin 1>&2" -e file:bin
323 atf_test_case eflag_inline
326 atf_set
"descr" "Tests for the -e option using the 'inline:' argument"
330 h_pass
"true 1>&2" -e inline
:
331 h_pass
"echo foo bar 1>&2" -e inline
:"foo bar\n"
332 h_pass
"printf 'foo bar' 1>&2" -e inline
:"foo bar"
333 h_pass
"printf '\t\n\t\n' 1>&2" -e inline
:"\t\n\t\n"
334 # XXX Ugly hack to workaround the lack of \e in FreeBSD. Also, \e doesn't
335 # seem to work as expected in Linux. Look for a nicer solution.
337 Darwin|FreeBSD|Linux
)
338 h_pass
"printf '\a\b\f\n\r\t\v' 1>&2" -e inline
:"\a\b\f\n\r\t\v"
341 h_pass
"printf '\a\b\e\f\n\r\t\v' 1>&2" -e inline
:"\a\b\e\f\n\r\t\v"
344 h_pass
"printf '\011\022\033\012' 1>&2" -e inline
:"\011\022\033\012"
346 h_fail
"echo foo bar 1>&2" -e inline
:"foo bar"
347 h_fail
"echo -n foo bar 1>&2" -e inline
:"foo bar\n"
350 atf_test_case eflag_save
353 atf_set
"descr" "Tests for the -e option using the 'save:' argument"
357 h_pass
"echo foo 1>&2" -e save
:out
359 cmp -s out exp || atf_fail
"Saved output does not match expected results"
362 atf_test_case eflag_match
365 atf_set
"descr" "Tests for the -e option using the 'match:' argument"
369 h_pass
"printf no-newline 1>&2" -e "match:^no-newline"
370 h_pass
"echo line1 1>&2; echo foo bar 1>&2" -e "match:^foo"
371 h_pass
"echo foo bar 1>&2" -e "match:o b"
372 h_fail
"echo foo bar 1>&2" -e "match:baz"
373 h_fail
"echo foo bar 1>&2" -e "match:^bar"
376 atf_test_case eflag_multiple
377 eflag_multiple_head
()
379 atf_set
"descr" "Tests for multiple occurrences of the -e option"
381 eflag_multiple_body
()
383 h_pass
"echo foo bar 1>&2" -e match
:foo
-e match
:bar
384 h_pass
"echo foo 1>&2; echo bar 1>&2" -e match
:foo
-e match
:bar
385 h_fail
"echo foo baz 1>&2" -e match
:bar
-e match
:foo
386 h_fail
"echo foo 1>&2; echo baz 1>&2" -e match
:bar
-e match
:foo
389 atf_test_case eflag_negated
392 atf_set
"descr" "Tests for negated occurrences of the -e option"
396 h_fail
"echo foo 1>&2" -e empty
397 h_pass
"echo foo 1>&2" -e not-empty
399 h_pass
"echo foo bar 1>&2" -e match
:foo
400 h_fail
"echo foo bar 1>&2" -e not-match
:foo
406 atf_set
"descr" "Tests that stdin is preserved"
410 echo "hello" |
${Atf_Check} -o match
:"hello" cat || \
411 atf_fail
"atf-check does not seem to respect stdin"
414 atf_test_case invalid_umask
417 atf_set
"descr" "Tests for a correct error condition if the umask is" \
423 ${Atf_Check} false
2>stderr
&& \
424 atf_fail
"atf-check returned 0 but it should have failed"
426 grep 'temporary.*current umask.*0222' stderr
>/dev
/null || \
427 atf_fail
"atf-check did not report an error related to the" \
431 atf_init_test_cases
()
433 atf_add_test_case sflag_eq_ne
434 atf_add_test_case sflag_exit
435 atf_add_test_case sflag_ignore
436 atf_add_test_case sflag_signal
438 atf_add_test_case xflag
440 atf_add_test_case oflag_empty
441 atf_add_test_case oflag_ignore
442 atf_add_test_case oflag_file
443 atf_add_test_case oflag_inline
444 atf_add_test_case oflag_match
445 atf_add_test_case oflag_save
446 atf_add_test_case oflag_multiple
447 atf_add_test_case oflag_negated
449 atf_add_test_case eflag_empty
450 atf_add_test_case eflag_ignore
451 atf_add_test_case eflag_file
452 atf_add_test_case eflag_inline
453 atf_add_test_case eflag_match
454 atf_add_test_case eflag_save
455 atf_add_test_case eflag_multiple
456 atf_add_test_case eflag_negated
458 atf_add_test_case stdin
460 atf_add_test_case invalid_umask
463 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4