Path: blob/main/contrib/atf/test-programs/result_test.sh
39481 views
# Copyright (c) 2007 The NetBSD Foundation, Inc.1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425atf_test_case runtime_warnings26runtime_warnings_head()27{28# The fact that this test case is in this test program is an abuse.29atf_set "descr" "Tests that the test case prints a warning because" \30"it is being run outside of a runtime engine"31}32runtime_warnings_body()33{34unset __RUNNING_INSIDE_ATF_RUN35srcdir="$(atf_get_srcdir)"36for h in $(get_helpers); do37atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*kyua" \38"${h}" -s "${srcdir}" result_pass39done40}4142atf_test_case result_on_stdout43result_on_stdout_head()44{45atf_set "descr" "Tests that the test case result is printed on stdout" \46"by default"47}48result_on_stdout_body()49{50srcdir="$(atf_get_srcdir)"51for h in $(get_helpers); do52atf_check -s eq:0 -o match:"passed" -o match:"msg" \53-e ignore "${h}" -s "${srcdir}" result_pass54atf_check -s eq:1 -o match:"failed: Failure reason" -o match:"msg" \55-e ignore "${h}" -s "${srcdir}" result_fail56atf_check -s eq:0 -o match:"skipped: Skipped reason" -o match:"msg" \57-e ignore "${h}" -s "${srcdir}" result_skip58done59}6061atf_test_case result_to_file62result_to_file_head()63{64atf_set "descr" "Tests that the test case result is sent to a file if -r" \65"is used"66}67result_to_file_body()68{69srcdir="$(atf_get_srcdir)"70for h in $(get_helpers); do71atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \72-r resfile result_pass73atf_check -o inline:"passed\n" cat resfile7475atf_check -s eq:1 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \76-r resfile result_fail77atf_check -o inline:"failed: Failure reason\n" cat resfile7879atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \80-r resfile result_skip81atf_check -o inline:"skipped: Skipped reason\n" cat resfile82done83}8485atf_test_case result_to_file_fail86result_to_file_fail_head()87{88atf_set "descr" "Tests controlled failure if the test program fails to" \89"create the results file"90atf_set "require.user" "unprivileged"91}92result_to_file_fail_body()93{94mkdir dir95chmod 444 dir9697srcdir="$(atf_get_srcdir)"9899for h in $(get_helpers c_helpers cpp_helpers); do100atf_check -s signal -o ignore \101-e match:"FATAL ERROR: Cannot create.*'dir/resfile'" \102"${h}" -s "${srcdir}" -r dir/resfile result_pass103done104105for h in $(get_helpers sh_helpers); do106atf_check -s exit -o ignore \107-e match:"ERROR: Cannot create.*'dir/resfile'" \108"${h}" -s "${srcdir}" -r dir/resfile result_pass109done110}111112atf_test_case result_exception113result_exception_head()114{115atf_set "descr" "Tests that an unhandled exception is correctly captured"116}117result_exception_body()118{119for h in $(get_helpers cpp_helpers); do120atf_check -s signal -o not-match:'failed: .*This is unhandled' \121-e ignore "${h}" -s "${srcdir}" result_exception122done123}124125atf_init_test_cases()126{127atf_add_test_case runtime_warnings128atf_add_test_case result_on_stdout129atf_add_test_case result_to_file130atf_add_test_case result_to_file_fail131atf_add_test_case result_exception132}133134# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4135136137