1# 2# Automated Testing Framework (atf) 3# 4# Copyright (c) 2007 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 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. 15# 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. 28# 29 30atf_test_case atf_run_warnings 31atf_run_warnings_head() 32{ 33 # The fact that this test case is in this test program is an abuse. 34 atf_set "descr" "Tests that the test case prints a warning because" \ 35 "it is not being run by atf-run" 36} 37atf_run_warnings_body() 38{ 39 unset __RUNNING_INSIDE_ATF_RUN 40 srcdir="$(atf_get_srcdir)" 41 for h in $(get_helpers); do 42 atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*atf-run" \ 43 "${h}" -s "${srcdir}" result_pass 44 done 45} 46 47atf_test_case result_on_stdout 48result_on_stdout_head() 49{ 50 atf_set "descr" "Tests that the test case result is printed on stdout" \ 51 "by default" 52} 53result_on_stdout_body() 54{ 55 srcdir="$(atf_get_srcdir)" 56 for h in $(get_helpers); do 57 atf_check -s eq:0 -o match:"passed" -o match:"msg" \ 58 -e ignore "${h}" -s "${srcdir}" result_pass 59 atf_check -s eq:1 -o match:"failed: Failure reason" -o match:"msg" \ 60 -e ignore "${h}" -s "${srcdir}" result_fail 61 atf_check -s eq:0 -o match:"skipped: Skipped reason" -o match:"msg" \ 62 -e ignore "${h}" -s "${srcdir}" result_skip 63 done 64} 65 66atf_test_case result_to_file 67result_to_file_head() 68{ 69 atf_set "descr" "Tests that the test case result is sent to a file if -r" \ 70 "is used" 71} 72result_to_file_body() 73{ 74 srcdir="$(atf_get_srcdir)" 75 for h in $(get_helpers); do 76 atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \ 77 -r resfile result_pass 78 atf_check -o inline:"passed\n" cat resfile 79 80 atf_check -s eq:1 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \ 81 -r resfile result_fail 82 atf_check -o inline:"failed: Failure reason\n" cat resfile 83 84 atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \ 85 -r resfile result_skip 86 atf_check -o inline:"skipped: Skipped reason\n" cat resfile 87 done 88} 89 90atf_test_case result_to_file_fail 91result_to_file_fail_head() 92{ 93 atf_set "descr" "Tests controlled failure if the test program fails to" \ 94 "create the results file" 95 atf_set "require.user" "unprivileged" 96} 97result_to_file_fail_body() 98{ 99 mkdir dir 100 chmod 444 dir 101 102 srcdir="$(atf_get_srcdir)" 103 104 for h in $(get_helpers c_helpers cpp_helpers); do 105 atf_check -s signal -o ignore \ 106 -e match:"FATAL ERROR: Cannot create.*'dir/resfile'" \ 107 "${h}" -s "${srcdir}" -r dir/resfile result_pass 108 done 109 110 for h in $(get_helpers sh_helpers); do 111 atf_check -s exit -o ignore \ 112 -e match:"ERROR: Cannot create.*'dir/resfile'" \ 113 "${h}" -s "${srcdir}" -r dir/resfile result_pass 114 done 115} 116 117atf_test_case result_exception 118result_exception_head() 119{ 120 atf_set "descr" "Tests that an unhandled exception is correctly captured" 121} 122result_exception_body() 123{ 124 for h in $(get_helpers cpp_helpers); do 125 atf_check -s exit:1 -o match:'failed: .*This is unhandled' \ 126 "${h}" -s "${srcdir}" result_exception 127 done 128} 129 130atf_init_test_cases() 131{ 132 atf_add_test_case atf_run_warnings 133 atf_add_test_case result_on_stdout 134 atf_add_test_case result_to_file 135 atf_add_test_case result_to_file_fail 136 atf_add_test_case result_exception 137} 138 139# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 140