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