2 # Automated Testing Framework (atf)
4 # Copyright (c) 2007 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 # -------------------------------------------------------------------------
31 # Helper tests for "t_cleanup".
32 # -------------------------------------------------------------------------
34 atf_test_case cleanup_pass cleanup
37 atf_set "descr" "Helper test case for the t_cleanup test program"
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
53 atf_set "descr" "Helper test case for the t_cleanup test program"
57 touch $(atf_config_get tmpfile)
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
70 atf_set "descr" "Helper test case for the t_cleanup test program"
74 touch $(atf_config_get tmpfile)
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
87 atf_set "descr" "Helper test case for the t_cleanup test program"
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)
107 touch $(atf_config_get tmpfile).no
109 cleanup_sigterm_cleanup()
111 rm $(atf_config_get tmpfile)
114 atf_test_case cleanup_fork cleanup
117 atf_set "descr" "Helper test case for the t_cleanup test program"
123 cleanup_fork_cleanup()
131 # -------------------------------------------------------------------------
132 # Helper tests for "t_config".
133 # -------------------------------------------------------------------------
135 atf_test_case config_unset
138 atf_set "descr" "Helper test case for the t_config test program"
142 if atf_config_has 'test'; then
143 atf_fail "Test variable already defined"
147 atf_test_case config_empty
150 atf_set "descr" "Helper test case for the t_config test program"
154 atf_check_equal "$(atf_config_get 'test')" ""
157 atf_test_case config_value
160 atf_set "descr" "Helper test case for the t_config test program"
164 atf_check_equal "$(atf_config_get 'test')" "foo"
167 atf_test_case config_multi_value
168 config_multi_value_head()
170 atf_set "descr" "Helper test case for the t_config test program"
172 config_multi_value_body()
174 atf_check_equal "$(atf_config_get 'test')" "foo bar"
177 # -------------------------------------------------------------------------
178 # Helper tests for "t_fork".
179 # -------------------------------------------------------------------------
181 atf_test_case fork_stop
184 atf_set "descr" "Helper test case for the t_fork test program"
188 echo ${$} >$(atf_config_get pidfile)
189 echo "Wrote pid file"
190 echo "Waiting for done file"
191 while ! test -f $(atf_config_get donefile); do sleep 1; done
195 # -------------------------------------------------------------------------
196 # Helper tests for "t_expect".
197 # -------------------------------------------------------------------------
199 atf_test_case expect_pass_and_pass
200 expect_pass_and_pass_body()
205 atf_test_case expect_pass_but_fail_requirement
206 expect_pass_but_fail_requirement_body()
209 atf_fail "Some reason"
212 atf_test_case expect_pass_but_fail_check
213 expect_pass_but_fail_check_body()
215 atf_fail "Non-fatal failures not implemented"
218 atf_test_case expect_fail_and_fail_requirement
219 expect_fail_and_fail_requirement_body()
221 atf_expect_fail "Fail reason"
222 atf_fail "The failure"
226 atf_test_case expect_fail_and_fail_check
227 expect_fail_and_fail_check_body()
229 atf_fail "Non-fatal failures not implemented"
232 atf_test_case expect_fail_but_pass
233 expect_fail_but_pass_body()
235 atf_expect_fail "Fail first"
239 atf_test_case expect_exit_any_and_exit
240 expect_exit_any_and_exit_body()
242 atf_expect_exit -1 "Call will exit"
246 atf_test_case expect_exit_code_and_exit
247 expect_exit_code_and_exit_body()
249 atf_expect_exit 123 "Call will exit"
253 atf_test_case expect_exit_but_pass
254 expect_exit_but_pass_body()
256 atf_expect_exit -1 "Call won't exit"
259 atf_test_case expect_signal_any_and_signal
260 expect_signal_any_and_signal_body()
262 atf_expect_signal -1 "Call will signal"
266 atf_test_case expect_signal_no_and_signal
267 expect_signal_no_and_signal_body()
269 atf_expect_signal 1 "Call will signal"
273 atf_test_case expect_signal_but_pass
274 expect_signal_but_pass_body()
276 atf_expect_signal -1 "Call won't signal"
279 atf_test_case expect_death_and_exit
280 expect_death_and_exit_body()
282 atf_expect_death "Exit case"
286 atf_test_case expect_death_and_signal
287 expect_death_and_signal_body()
289 atf_expect_death "Signal case"
293 atf_test_case expect_death_but_pass
294 expect_death_but_pass_body()
296 atf_expect_death "Call won't die"
299 atf_test_case expect_timeout_and_hang
300 expect_timeout_and_hang_head()
302 atf_set "timeout" "1"
304 expect_timeout_and_hang_body()
306 atf_expect_timeout "Will overrun"
310 atf_test_case expect_timeout_but_pass
311 expect_timeout_but_pass_head()
313 atf_set "timeout" "1"
315 expect_timeout_but_pass_body()
317 atf_expect_timeout "Will just exit"
320 # -------------------------------------------------------------------------
321 # Helper tests for "t_meta_data".
322 # -------------------------------------------------------------------------
324 atf_test_case metadata_no_descr
325 metadata_no_descr_head()
329 metadata_no_descr_body()
334 atf_test_case metadata_no_head
335 metadata_no_head_body()
340 # -------------------------------------------------------------------------
341 # Helper tests for "t_srcdir".
342 # -------------------------------------------------------------------------
344 atf_test_case srcdir_exists
347 atf_set "descr" "Helper test case for the t_srcdir test program"
351 [ -f "$(atf_get_srcdir)/datafile" ] || atf_fail "Cannot find datafile"
354 # -------------------------------------------------------------------------
355 # Helper tests for "t_result".
356 # -------------------------------------------------------------------------
358 atf_test_case result_pass
364 atf_test_case result_fail
368 atf_fail "Failure reason"
371 atf_test_case result_skip
375 atf_skip "Skipped reason"
378 # -------------------------------------------------------------------------
380 # -------------------------------------------------------------------------
382 atf_init_test_cases()
384 # Add helper tests for t_cleanup.
385 atf_add_test_case cleanup_pass
386 atf_add_test_case cleanup_fail
387 atf_add_test_case cleanup_skip
388 atf_add_test_case cleanup_curdir
389 atf_add_test_case cleanup_sigterm
390 atf_add_test_case cleanup_fork
392 # Add helper tests for t_config.
393 atf_add_test_case config_unset
394 atf_add_test_case config_empty
395 atf_add_test_case config_value
396 atf_add_test_case config_multi_value
398 # Add helper tests for t_expect.
399 atf_add_test_case expect_pass_and_pass
400 atf_add_test_case expect_pass_but_fail_requirement
401 atf_add_test_case expect_pass_but_fail_check
402 atf_add_test_case expect_fail_and_fail_requirement
403 atf_add_test_case expect_fail_and_fail_check
404 atf_add_test_case expect_fail_but_pass
405 atf_add_test_case expect_exit_any_and_exit
406 atf_add_test_case expect_exit_code_and_exit
407 atf_add_test_case expect_exit_but_pass
408 atf_add_test_case expect_signal_any_and_signal
409 atf_add_test_case expect_signal_no_and_signal
410 atf_add_test_case expect_signal_but_pass
411 atf_add_test_case expect_death_and_exit
412 atf_add_test_case expect_death_and_signal
413 atf_add_test_case expect_death_but_pass
414 atf_add_test_case expect_timeout_and_hang
415 atf_add_test_case expect_timeout_but_pass
417 # Add helper tests for t_fork.
418 atf_add_test_case fork_stop
420 # Add helper tests for t_meta_data.
421 atf_add_test_case metadata_no_descr
422 atf_add_test_case metadata_no_head
424 # Add helper tests for t_srcdir.
425 atf_add_test_case srcdir_exists
427 # Add helper tests for t_result.
428 atf_add_test_case result_pass
429 atf_add_test_case result_fail
430 atf_add_test_case result_skip
433 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4