Home | History | Annotate | Line # | Download | only in test-programs
      1      1.1  jmmv #
      2      1.1  jmmv # Automated Testing Framework (atf)
      3      1.1  jmmv #
      4  1.1.1.4  jmmv # Copyright (c) 2007 The NetBSD Foundation, Inc.
      5      1.1  jmmv # All rights reserved.
      6      1.1  jmmv #
      7      1.1  jmmv # Redistribution and use in source and binary forms, with or without
      8      1.1  jmmv # modification, are permitted provided that the following conditions
      9      1.1  jmmv # are met:
     10      1.1  jmmv # 1. Redistributions of source code must retain the above copyright
     11      1.1  jmmv #    notice, this list of conditions and the following disclaimer.
     12      1.1  jmmv # 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  jmmv #    notice, this list of conditions and the following disclaimer in the
     14      1.1  jmmv #    documentation and/or other materials provided with the distribution.
     15      1.1  jmmv #
     16      1.1  jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
     17      1.1  jmmv # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     18      1.1  jmmv # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19      1.1  jmmv # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20      1.1  jmmv # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
     21      1.1  jmmv # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22      1.1  jmmv # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     23      1.1  jmmv # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24      1.1  jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     25      1.1  jmmv # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     26      1.1  jmmv # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27      1.1  jmmv # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28      1.1  jmmv #
     29      1.1  jmmv 
     30  1.1.1.3  jmmv atf_test_case atf_run_warnings
     31  1.1.1.3  jmmv atf_run_warnings_head()
     32  1.1.1.3  jmmv {
     33  1.1.1.3  jmmv     # The fact that this test case is in this test program is an abuse.
     34  1.1.1.3  jmmv     atf_set "descr" "Tests that the test case prints a warning because" \
     35  1.1.1.3  jmmv                     "it is not being run by atf-run"
     36  1.1.1.3  jmmv }
     37  1.1.1.3  jmmv atf_run_warnings_body()
     38  1.1.1.3  jmmv {
     39  1.1.1.3  jmmv     unset __RUNNING_INSIDE_ATF_RUN
     40  1.1.1.3  jmmv     srcdir="$(atf_get_srcdir)"
     41  1.1.1.3  jmmv     for h in $(get_helpers); do
     42  1.1.1.3  jmmv         atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*atf-run" \
     43  1.1.1.3  jmmv             "${h}" -s "${srcdir}" result_pass
     44  1.1.1.3  jmmv     done
     45  1.1.1.3  jmmv }
     46  1.1.1.3  jmmv 
     47      1.1  jmmv atf_test_case result_on_stdout
     48      1.1  jmmv result_on_stdout_head()
     49      1.1  jmmv {
     50      1.1  jmmv     atf_set "descr" "Tests that the test case result is printed on stdout" \
     51      1.1  jmmv                     "by default"
     52      1.1  jmmv }
     53      1.1  jmmv result_on_stdout_body()
     54      1.1  jmmv {
     55      1.1  jmmv     srcdir="$(atf_get_srcdir)"
     56      1.1  jmmv     for h in $(get_helpers); do
     57      1.1  jmmv         atf_check -s eq:0 -o match:"passed" -o match:"msg" \
     58  1.1.1.3  jmmv             -e ignore "${h}" -s "${srcdir}" result_pass
     59      1.1  jmmv         atf_check -s eq:1 -o match:"failed: Failure reason" -o match:"msg" \
     60  1.1.1.3  jmmv             -e ignore "${h}" -s "${srcdir}" result_fail
     61      1.1  jmmv         atf_check -s eq:0 -o match:"skipped: Skipped reason" -o match:"msg" \
     62  1.1.1.3  jmmv             -e ignore "${h}" -s "${srcdir}" result_skip
     63      1.1  jmmv     done
     64      1.1  jmmv }
     65      1.1  jmmv 
     66      1.1  jmmv atf_test_case result_to_file
     67      1.1  jmmv result_to_file_head()
     68      1.1  jmmv {
     69      1.1  jmmv     atf_set "descr" "Tests that the test case result is sent to a file if -r" \
     70      1.1  jmmv                     "is used"
     71      1.1  jmmv }
     72      1.1  jmmv result_to_file_body()
     73      1.1  jmmv {
     74      1.1  jmmv     srcdir="$(atf_get_srcdir)"
     75      1.1  jmmv     for h in $(get_helpers); do
     76  1.1.1.3  jmmv         atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
     77      1.1  jmmv             -r resfile result_pass
     78      1.1  jmmv         atf_check -o inline:"passed\n" cat resfile
     79      1.1  jmmv 
     80  1.1.1.3  jmmv         atf_check -s eq:1 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
     81      1.1  jmmv             -r resfile result_fail
     82      1.1  jmmv         atf_check -o inline:"failed: Failure reason\n" cat resfile
     83      1.1  jmmv 
     84  1.1.1.3  jmmv         atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
     85      1.1  jmmv             -r resfile result_skip
     86      1.1  jmmv         atf_check -o inline:"skipped: Skipped reason\n" cat resfile
     87      1.1  jmmv     done
     88      1.1  jmmv }
     89      1.1  jmmv 
     90      1.1  jmmv atf_test_case result_to_file_fail
     91      1.1  jmmv result_to_file_fail_head()
     92      1.1  jmmv {
     93      1.1  jmmv     atf_set "descr" "Tests controlled failure if the test program fails to" \
     94      1.1  jmmv         "create the results file"
     95      1.1  jmmv     atf_set "require.user" "unprivileged"
     96      1.1  jmmv }
     97      1.1  jmmv result_to_file_fail_body()
     98      1.1  jmmv {
     99      1.1  jmmv     mkdir dir
    100      1.1  jmmv     chmod 444 dir
    101      1.1  jmmv 
    102      1.1  jmmv     srcdir="$(atf_get_srcdir)"
    103      1.1  jmmv 
    104      1.1  jmmv     for h in $(get_helpers c_helpers cpp_helpers); do
    105      1.1  jmmv         atf_check -s signal -o ignore \
    106      1.1  jmmv             -e match:"FATAL ERROR: Cannot create.*'dir/resfile'" \
    107      1.1  jmmv             "${h}" -s "${srcdir}" -r dir/resfile result_pass
    108      1.1  jmmv     done
    109      1.1  jmmv 
    110      1.1  jmmv     for h in $(get_helpers sh_helpers); do
    111      1.1  jmmv         atf_check -s exit -o ignore \
    112      1.1  jmmv             -e match:"ERROR: Cannot create.*'dir/resfile'" \
    113      1.1  jmmv             "${h}" -s "${srcdir}" -r dir/resfile result_pass
    114      1.1  jmmv     done
    115      1.1  jmmv }
    116      1.1  jmmv 
    117      1.1  jmmv atf_test_case result_exception
    118      1.1  jmmv result_exception_head()
    119      1.1  jmmv {
    120      1.1  jmmv     atf_set "descr" "Tests that an unhandled exception is correctly captured"
    121      1.1  jmmv }
    122      1.1  jmmv result_exception_body()
    123      1.1  jmmv {
    124      1.1  jmmv     for h in $(get_helpers cpp_helpers); do
    125      1.1  jmmv         atf_check -s exit:1 -o match:'failed: .*This is unhandled' \
    126      1.1  jmmv             "${h}" -s "${srcdir}" result_exception
    127      1.1  jmmv     done
    128      1.1  jmmv }
    129      1.1  jmmv 
    130      1.1  jmmv atf_init_test_cases()
    131      1.1  jmmv {
    132  1.1.1.3  jmmv     atf_add_test_case atf_run_warnings
    133      1.1  jmmv     atf_add_test_case result_on_stdout
    134      1.1  jmmv     atf_add_test_case result_to_file
    135      1.1  jmmv     atf_add_test_case result_to_file_fail
    136      1.1  jmmv     atf_add_test_case result_exception
    137      1.1  jmmv }
    138      1.1  jmmv 
    139      1.1  jmmv # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
    140