Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / atf / dist / test-programs / sh_helpers.sh
blobeb55102dfeed73aeb7ba995f5f2ac5e303c1df92
2 # Automated Testing Framework (atf)
4 # Copyright (c) 2007 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 # -------------------------------------------------------------------------
31 # Helper tests for "t_cleanup".
32 # -------------------------------------------------------------------------
34 atf_test_case cleanup_pass cleanup
35 cleanup_pass_head()
37 atf_set "descr" "Helper test case for the t_cleanup test program"
39 cleanup_pass_body()
41 touch $(atf_config_get tmpfile)
43 cleanup_pass_cleanup()
45 if [ $(atf_config_get cleanup no) = yes ]; then
46 rm $(atf_config_get tmpfile)
50 atf_test_case cleanup_fail cleanup
51 cleanup_fail_head()
53 atf_set "descr" "Helper test case for the t_cleanup test program"
55 cleanup_fail_body()
57 touch $(atf_config_get tmpfile)
58 atf_fail "On purpose"
60 cleanup_fail_cleanup()
62 if [ $(atf_config_get cleanup no) = yes ]; then
63 rm $(atf_config_get tmpfile)
67 atf_test_case cleanup_skip cleanup
68 cleanup_skip_head()
70 atf_set "descr" "Helper test case for the t_cleanup test program"
72 cleanup_skip_body()
74 touch $(atf_config_get tmpfile)
75 atf_skip "On purpose"
77 cleanup_skip_cleanup()
79 if [ $(atf_config_get cleanup no) = yes ]; then
80 rm $(atf_config_get tmpfile)
84 atf_test_case cleanup_curdir cleanup
85 cleanup_curdir_head()
87 atf_set "descr" "Helper test case for the t_cleanup test program"
89 cleanup_curdir_body()
91 echo 1234 >oldvalue
93 cleanup_curdir_cleanup()
95 test -f oldvalue && echo "Old value: $(cat oldvalue)"
98 atf_test_case cleanup_sigterm cleanup
99 cleanup_sigterm_head()
101 atf_set "descr" "Helper test case for the t_cleanup test program"
103 cleanup_sigterm_body()
105 touch $(atf_config_get tmpfile)
106 kill $$
107 touch $(atf_config_get tmpfile).no
109 cleanup_sigterm_cleanup()
111 rm $(atf_config_get tmpfile)
114 # -------------------------------------------------------------------------
115 # Helper tests for "t_config".
116 # -------------------------------------------------------------------------
118 atf_test_case config_unset
119 config_unset_head()
121 atf_set "descr" "Helper test case for the t_config test program"
123 config_unset_body()
125 if atf_config_has 'test'; then
126 atf_fail "Test variable already defined"
130 atf_test_case config_empty
131 config_empty_head()
133 atf_set "descr" "Helper test case for the t_config test program"
135 config_empty_body()
137 atf_check_equal "$(atf_config_get 'test')" ""
140 atf_test_case config_value
141 config_value_head()
143 atf_set "descr" "Helper test case for the t_config test program"
145 config_value_body()
147 atf_check_equal "$(atf_config_get 'test')" "foo"
150 atf_test_case config_multi_value
151 config_multi_value_head()
153 atf_set "descr" "Helper test case for the t_config test program"
155 config_multi_value_body()
157 atf_check_equal "$(atf_config_get 'test')" "foo bar"
160 # -------------------------------------------------------------------------
161 # Helper tests for "t_expect".
162 # -------------------------------------------------------------------------
164 atf_test_case expect_pass_and_pass
165 expect_pass_and_pass_body()
167 atf_expect_pass
170 atf_test_case expect_pass_but_fail_requirement
171 expect_pass_but_fail_requirement_body()
173 atf_expect_pass
174 atf_fail "Some reason"
177 atf_test_case expect_pass_but_fail_check
178 expect_pass_but_fail_check_body()
180 atf_fail "Non-fatal failures not implemented"
183 atf_test_case expect_fail_and_fail_requirement
184 expect_fail_and_fail_requirement_body()
186 atf_expect_fail "Fail reason"
187 atf_fail "The failure"
188 atf_expect_pass
191 atf_test_case expect_fail_and_fail_check
192 expect_fail_and_fail_check_body()
194 atf_fail "Non-fatal failures not implemented"
197 atf_test_case expect_fail_but_pass
198 expect_fail_but_pass_body()
200 atf_expect_fail "Fail first"
201 atf_expect_pass
204 atf_test_case expect_exit_any_and_exit
205 expect_exit_any_and_exit_body()
207 atf_expect_exit -1 "Call will exit"
208 exit 0
211 atf_test_case expect_exit_code_and_exit
212 expect_exit_code_and_exit_body()
214 atf_expect_exit 123 "Call will exit"
215 exit 123
218 atf_test_case expect_exit_but_pass
219 expect_exit_but_pass_body()
221 atf_expect_exit -1 "Call won't exit"
224 atf_test_case expect_signal_any_and_signal
225 expect_signal_any_and_signal_body()
227 atf_expect_signal -1 "Call will signal"
228 kill -9 $$
231 atf_test_case expect_signal_no_and_signal
232 expect_signal_no_and_signal_body()
234 atf_expect_signal 1 "Call will signal"
235 kill -1 $$
238 atf_test_case expect_signal_but_pass
239 expect_signal_but_pass_body()
241 atf_expect_signal -1 "Call won't signal"
244 atf_test_case expect_death_and_exit
245 expect_death_and_exit_body()
247 atf_expect_death "Exit case"
248 exit 123
251 atf_test_case expect_death_and_signal
252 expect_death_and_signal_body()
254 atf_expect_death "Signal case"
255 kill -9 $$
258 atf_test_case expect_death_but_pass
259 expect_death_but_pass_body()
261 atf_expect_death "Call won't die"
264 atf_test_case expect_timeout_and_hang
265 expect_timeout_and_hang_head()
267 atf_set "timeout" "1"
269 expect_timeout_and_hang_body()
271 atf_expect_timeout "Will overrun"
272 sleep 5
275 atf_test_case expect_timeout_but_pass
276 expect_timeout_but_pass_head()
278 atf_set "timeout" "1"
280 expect_timeout_but_pass_body()
282 atf_expect_timeout "Will just exit"
285 # -------------------------------------------------------------------------
286 # Helper tests for "t_meta_data".
287 # -------------------------------------------------------------------------
289 atf_test_case metadata_no_descr
290 metadata_no_descr_head()
294 metadata_no_descr_body()
299 atf_test_case metadata_no_head
300 metadata_no_head_body()
305 # -------------------------------------------------------------------------
306 # Helper tests for "t_srcdir".
307 # -------------------------------------------------------------------------
309 atf_test_case srcdir_exists
310 srcdir_exists_head()
312 atf_set "descr" "Helper test case for the t_srcdir test program"
314 srcdir_exists_body()
316 [ -f "$(atf_get_srcdir)/datafile" ] || atf_fail "Cannot find datafile"
319 # -------------------------------------------------------------------------
320 # Helper tests for "t_result".
321 # -------------------------------------------------------------------------
323 atf_test_case result_pass
324 result_pass_body()
326 echo "msg"
329 atf_test_case result_fail
330 result_fail_body()
332 echo "msg"
333 atf_fail "Failure reason"
336 atf_test_case result_skip
337 result_skip_body()
339 echo "msg"
340 atf_skip "Skipped reason"
343 # -------------------------------------------------------------------------
344 # Main.
345 # -------------------------------------------------------------------------
347 atf_init_test_cases()
349 # Add helper tests for t_cleanup.
350 atf_add_test_case cleanup_pass
351 atf_add_test_case cleanup_fail
352 atf_add_test_case cleanup_skip
353 atf_add_test_case cleanup_curdir
354 atf_add_test_case cleanup_sigterm
356 # Add helper tests for t_config.
357 atf_add_test_case config_unset
358 atf_add_test_case config_empty
359 atf_add_test_case config_value
360 atf_add_test_case config_multi_value
362 # Add helper tests for t_expect.
363 atf_add_test_case expect_pass_and_pass
364 atf_add_test_case expect_pass_but_fail_requirement
365 atf_add_test_case expect_pass_but_fail_check
366 atf_add_test_case expect_fail_and_fail_requirement
367 atf_add_test_case expect_fail_and_fail_check
368 atf_add_test_case expect_fail_but_pass
369 atf_add_test_case expect_exit_any_and_exit
370 atf_add_test_case expect_exit_code_and_exit
371 atf_add_test_case expect_exit_but_pass
372 atf_add_test_case expect_signal_any_and_signal
373 atf_add_test_case expect_signal_no_and_signal
374 atf_add_test_case expect_signal_but_pass
375 atf_add_test_case expect_death_and_exit
376 atf_add_test_case expect_death_and_signal
377 atf_add_test_case expect_death_but_pass
378 atf_add_test_case expect_timeout_and_hang
379 atf_add_test_case expect_timeout_but_pass
381 # Add helper tests for t_meta_data.
382 atf_add_test_case metadata_no_descr
383 atf_add_test_case metadata_no_head
385 # Add helper tests for t_srcdir.
386 atf_add_test_case srcdir_exists
388 # Add helper tests for t_result.
389 atf_add_test_case result_pass
390 atf_add_test_case result_fail
391 atf_add_test_case result_skip
394 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4