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 30# ------------------------------------------------------------------------- 31# Helper tests for "t_atf_check". 32# ------------------------------------------------------------------------- 33 34atf_test_case atf_check_info_ok 35atf_check_info_ok_head() 36{ 37 atf_set "descr" "Helper test case for the t_atf_check test program" 38} 39atf_check_info_ok_body() 40{ 41 atf_check -s eq:0 -o empty -e empty true 42} 43 44atf_test_case atf_check_info_fail 45atf_check_info_fail_head() 46{ 47 atf_set "descr" "Helper test case for the t_atf_check test program" 48} 49atf_check_info_fail_body() 50{ 51 # In Solaris, /usr/bin/false returns 255 rather than 1. Use the 52 # built-in version for the check. 53 atf_check -s eq:1 -o empty -e empty sh -c "false" 54} 55 56atf_test_case atf_check_expout_mismatch 57atf_check_expout_mismatch_head() 58{ 59 atf_set "descr" "Helper test case for the t_atf_check test program" 60} 61atf_check_expout_mismatch_body() 62{ 63 cat >expout <<SECONDEOF 64foo 65SECONDEOF 66 atf_check -s eq:0 -o file:expout -e empty echo bar 67} 68 69atf_test_case atf_check_experr_mismatch 70atf_check_experr_mismatch_head() 71{ 72 atf_set "descr" "Helper test case for the t_atf_check test program" 73} 74atf_check_experr_mismatch_body() 75{ 76 cat >experr <<SECONDEOF 77foo 78SECONDEOF 79 atf_check -s eq:0 -o empty -e file:experr -x 'echo bar 1>&2' 80} 81 82atf_test_case atf_check_null_stdout 83atf_check_null_stdout_head() 84{ 85 atf_set "descr" "Helper test case for the t_atf_check test program" 86} 87atf_check_null_stdout_body() 88{ 89 atf_check -s eq:0 -o empty -e empty echo "These are the contents" 90} 91 92atf_test_case atf_check_null_stderr 93atf_check_null_stderr_head() 94{ 95 atf_set "descr" "Helper test case for the t_atf_check test program" 96} 97atf_check_null_stderr_body() 98{ 99 atf_check -s eq:0 -o empty -e empty -x 'echo "These are the contents" 1>&2' 100} 101 102atf_test_case atf_check_equal_ok 103atf_check_equal_ok_head() 104{ 105 atf_set "descr" "Helper test case for the t_atf_check test program" 106} 107atf_check_equal_ok_body() 108{ 109 atf_check_equal a a 110} 111 112atf_test_case atf_check_equal_fail 113atf_check_equal_fail_head() 114{ 115 atf_set "descr" "Helper test case for the t_atf_check test program" 116} 117atf_check_equal_fail_body() 118{ 119 atf_check_equal a b 120} 121 122atf_test_case atf_check_equal_eval_ok 123atf_check_equal_eval_ok_head() 124{ 125 atf_set "descr" "Helper test case for the t_atf_check test program" 126} 127atf_check_equal_eval_ok_body() 128{ 129 x=a 130 y=a 131 atf_check_equal '${x}' '${y}' 132} 133 134atf_test_case atf_check_equal_eval_fail 135atf_check_equal_eval_fail_head() 136{ 137 atf_set "descr" "Helper test case for the t_atf_check test program" 138} 139atf_check_equal_eval_fail_body() 140{ 141 x=a 142 y=b 143 atf_check_equal '${x}' '${y}' 144} 145 146atf_test_case atf_check_timeout 147atf_check_timeout_head() 148{ 149 atf_set "descr" "Helper test case for the t_atf_check test program" 150 atf_set "timeout" 1 151} 152atf_check_timeout_body() 153{ 154 atf_check true 155 atf_check sleep 42 156} 157 158# ------------------------------------------------------------------------- 159# Helper tests for "t_config". 160# ------------------------------------------------------------------------- 161 162atf_test_case config_get 163config_get_head() 164{ 165 atf_set "descr" "Helper test case for the t_config test program" 166} 167config_get_body() 168{ 169 if atf_config_has ${TEST_VARIABLE}; then 170 echo "${TEST_VARIABLE} = $(atf_config_get ${TEST_VARIABLE})" 171 fi 172} 173 174atf_test_case config_has 175config_has_head() 176{ 177 atf_set "descr" "Helper test case for the t_config test program" 178} 179config_has_body() 180{ 181 if atf_config_has ${TEST_VARIABLE}; then 182 echo "${TEST_VARIABLE} found" 183 else 184 echo "${TEST_VARIABLE} not found" 185 fi 186} 187 188# ------------------------------------------------------------------------- 189# Helper tests for "t_normalize". 190# ------------------------------------------------------------------------- 191 192atf_test_case normalize 193normalize_head() 194{ 195 atf_set "descr" "Helper test case for the t_normalize test program" 196 atf_set "a.b" "test value 1" 197 atf_set "c-d" "test value 2" 198} 199normalize_body() 200{ 201 echo "a.b: $(atf_get a.b)" 202 echo "c-d: $(atf_get c-d)" 203} 204 205# ------------------------------------------------------------------------- 206# Helper tests for "t_tc". 207# ------------------------------------------------------------------------- 208 209atf_test_case tc_pass_true 210tc_pass_true_head() 211{ 212 atf_set "descr" "Helper test case for the t_tc test program" 213} 214tc_pass_true_body() 215{ 216 true 217} 218 219atf_test_case tc_pass_false 220tc_pass_false_head() 221{ 222 atf_set "descr" "Helper test case for the t_tc test program" 223} 224tc_pass_false_body() 225{ 226 false 227} 228 229atf_test_case tc_pass_return_error 230tc_pass_return_error_head() 231{ 232 atf_set "descr" "Helper test case for the t_tc test program" 233} 234tc_pass_return_error_body() 235{ 236 return 1 237} 238 239atf_test_case tc_fail 240tc_fail_head() 241{ 242 atf_set "descr" "Helper test case for the t_tc test program" 243} 244tc_fail_body() 245{ 246 echo "An error" 1>&2 247 exit 1 248} 249 250atf_test_case tc_missing_body 251tc_missing_body_head() 252{ 253 atf_set "descr" "Helper test case for the t_tc test program" 254} 255 256# ------------------------------------------------------------------------- 257# Helper tests for "t_tp". 258# ------------------------------------------------------------------------- 259 260atf_test_case tp_srcdir 261tp_srcdir_head() 262{ 263 atf_set "descr" "Helper test case for the t_tp test program" 264} 265tp_srcdir_body() 266{ 267 echo "Calling helper" 268 helper_subr || atf_fail "Could not call helper subroutine" 269} 270 271# ------------------------------------------------------------------------- 272# Main. 273# ------------------------------------------------------------------------- 274 275atf_init_test_cases() 276{ 277 # Add helper tests for t_atf_check. 278 atf_add_test_case atf_check_info_ok 279 atf_add_test_case atf_check_info_fail 280 atf_add_test_case atf_check_expout_mismatch 281 atf_add_test_case atf_check_experr_mismatch 282 atf_add_test_case atf_check_null_stdout 283 atf_add_test_case atf_check_null_stderr 284 atf_add_test_case atf_check_equal_ok 285 atf_add_test_case atf_check_equal_fail 286 atf_add_test_case atf_check_equal_eval_ok 287 atf_add_test_case atf_check_equal_eval_fail 288 atf_add_test_case atf_check_timeout 289 290 # Add helper tests for t_config. 291 atf_add_test_case config_get 292 atf_add_test_case config_has 293 294 # Add helper tests for t_normalize. 295 atf_add_test_case normalize 296 297 # Add helper tests for t_tc. 298 atf_add_test_case tc_pass_true 299 atf_add_test_case tc_pass_false 300 atf_add_test_case tc_pass_return_error 301 atf_add_test_case tc_fail 302 atf_add_test_case tc_missing_body 303 304 # Add helper tests for t_tp. 305 [ -f $(atf_get_srcdir)/subrs ] && . $(atf_get_srcdir)/subrs 306 atf_add_test_case tp_srcdir 307} 308 309# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 310