Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / atf / dist / atf-sh / atf-check_test.sh
blob7319a2b882ba5984953ea2c92bf4336e6797e234
2 # Automated Testing Framework (atf)
4 # Copyright (c) 2008 The NetBSD Foundation, Inc.
5 # All rights reserved.
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.
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.
32 h_pass()
34 cmd="$1"; shift
36 echo "Running [atf-check $*] against [${cmd}]"
38 cat >script.sh <<EOF
39 #! ${Atf_Shell}
40 ${cmd}
41 EOF
42 chmod +x script.sh
44 if ! ${Atf_Check} "${@}" ./script.sh >tmp; then
45 cat tmp
46 atf_fail "atf-check failed"
50 h_fail()
52 cmd="$1"; shift
54 echo "Running [atf-check $*] against [${cmd}]"
56 cat >script.sh <<EOF
57 #! ${Atf_Shell}
58 ${cmd}
59 EOF
60 chmod +x script.sh
62 if ${Atf_Check} "${@}" ./script.sh 2>tmp; then
63 cat tmp
64 atf_fail "atf-check succeeded but should fail"
68 atf_test_case sflag_eq_ne
69 sflag_eq_ne_head()
71 atf_set "descr" "Tests for the -s option using the 'eq' and 'ne' qualifiers"
73 sflag_eq_ne_body()
75 h_pass "true" -s eq:0
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
87 sflag_exit_head()
89 atf_set "descr" "Tests for the -s option using the 'exit' qualifier"
91 sflag_exit_body()
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
111 sflag_ignore_head()
113 atf_set "descr" "Tests for the -s option using the 'ignore' qualifier"
115 sflag_ignore_body()
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
125 sflag_signal_head()
127 atf_set "descr" "Tests for the -s option using the 'signal' qualifier"
129 sflag_signal_body()
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" \
133 "detected"
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
146 atf_test_case xflag
147 xflag_head()
149 atf_set "descr" "Tests for the -x option"
151 xflag_body()
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
164 oflag_empty_head()
166 atf_set "descr" "Tests for the -o option using the 'empty' argument"
168 oflag_empty_body()
170 h_pass "true" -o empty
171 h_fail "echo foo" -o empty
174 atf_test_case oflag_ignore
175 oflag_ignore_head()
177 atf_set "descr" "Tests for the -o option using the 'ignore' argument"
179 oflag_ignore_body()
181 h_pass "true" -o ignore
182 h_pass "echo foo" -o ignore
185 atf_test_case oflag_file
186 oflag_file_head()
188 atf_set "descr" "Tests for the -o option using the 'file:' argument"
190 oflag_file_body()
192 touch empty
193 h_pass "true" -o file:empty
195 echo foo >text
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
204 oflag_inline_head()
206 atf_set "descr" "Tests for the -o option using the 'inline:' argument"
208 oflag_inline_body()
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.
216 case $(uname) in
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"
223 esac
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
231 oflag_match_head()
233 atf_set "descr" "Tests for the -o option using the 'match:' argument"
235 oflag_match_body()
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
245 oflag_save_head()
247 atf_set "descr" "Tests for the -o option using the 'save:' argument"
249 oflag_save_body()
251 h_pass "echo foo" -o save:out
252 echo foo >exp
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
270 oflag_negated_head()
272 atf_set "descr" "Tests for negated occurrences of the -o option"
274 oflag_negated_body()
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
284 eflag_empty_head()
286 atf_set "descr" "Tests for the -e option using the 'empty' argument"
288 eflag_empty_body()
290 h_pass "true 1>&2" -e empty
291 h_fail "echo foo 1>&2" -e empty
294 atf_test_case eflag_ignore
295 eflag_ignore_head()
297 atf_set "descr" "Tests for the -e option using the 'ignore' argument"
299 eflag_ignore_body()
301 h_pass "true 1>&2" -e ignore
302 h_pass "echo foo 1>&2" -e ignore
305 atf_test_case eflag_file
306 eflag_file_head()
308 atf_set "descr" "Tests for the -e option using the 'file:' argument"
310 eflag_file_body()
312 touch empty
313 h_pass "true 1>&2" -e file:empty
315 echo foo >text
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
324 eflag_inline_head()
326 atf_set "descr" "Tests for the -e option using the 'inline:' argument"
328 eflag_inline_body()
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.
336 case $(uname) in
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"
343 esac
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
351 eflag_save_head()
353 atf_set "descr" "Tests for the -e option using the 'save:' argument"
355 eflag_save_body()
357 h_pass "echo foo 1>&2" -e save:out
358 echo foo >exp
359 cmp -s out exp || atf_fail "Saved output does not match expected results"
362 atf_test_case eflag_match
363 eflag_match_head()
365 atf_set "descr" "Tests for the -e option using the 'match:' argument"
367 eflag_match_body()
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
390 eflag_negated_head()
392 atf_set "descr" "Tests for negated occurrences of the -e option"
394 eflag_negated_body()
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
403 atf_test_case stdin
404 stdin_head()
406 atf_set "descr" "Tests that stdin is preserved"
408 stdin_body()
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
415 invalid_umask_head()
417 atf_set "descr" "Tests for a correct error condition if the umask is" \
418 "too restrictive"
420 invalid_umask_body()
422 umask 0222
423 ${Atf_Check} false 2>stderr && \
424 atf_fail "atf-check returned 0 but it should have failed"
425 cat stderr
426 grep 'temporary.*current umask.*0222' stderr >/dev/null || \
427 atf_fail "atf-check did not report an error related to the" \
428 "current umask"
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