1240116Smarcel# Copyright (c) 2007 The NetBSD Foundation, Inc. 2240116Smarcel# All rights reserved. 3240116Smarcel# 4240116Smarcel# Redistribution and use in source and binary forms, with or without 5240116Smarcel# modification, are permitted provided that the following conditions 6240116Smarcel# are met: 7240116Smarcel# 1. Redistributions of source code must retain the above copyright 8240116Smarcel# notice, this list of conditions and the following disclaimer. 9240116Smarcel# 2. Redistributions in binary form must reproduce the above copyright 10240116Smarcel# notice, this list of conditions and the following disclaimer in the 11240116Smarcel# documentation and/or other materials provided with the distribution. 12240116Smarcel# 13240116Smarcel# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14240116Smarcel# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15240116Smarcel# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16240116Smarcel# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17240116Smarcel# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18240116Smarcel# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19240116Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20240116Smarcel# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21240116Smarcel# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22240116Smarcel# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23240116Smarcel# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24240116Smarcel# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25240116Smarcel 26240116Smarcel# ------------------------------------------------------------------------- 27240116Smarcel# Helper tests for "t_atf_check". 28240116Smarcel# ------------------------------------------------------------------------- 29240116Smarcel 30240116Smarcelatf_test_case atf_check_info_ok 31240116Smarcelatf_check_info_ok_head() 32240116Smarcel{ 33240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 34240116Smarcel} 35240116Smarcelatf_check_info_ok_body() 36240116Smarcel{ 37240116Smarcel atf_check -s eq:0 -o empty -e empty true 38240116Smarcel} 39240116Smarcel 40240116Smarcelatf_test_case atf_check_info_fail 41240116Smarcelatf_check_info_fail_head() 42240116Smarcel{ 43240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 44240116Smarcel} 45240116Smarcelatf_check_info_fail_body() 46240116Smarcel{ 47240116Smarcel # In Solaris, /usr/bin/false returns 255 rather than 1. Use the 48240116Smarcel # built-in version for the check. 49240116Smarcel atf_check -s eq:1 -o empty -e empty sh -c "false" 50240116Smarcel} 51240116Smarcel 52240116Smarcelatf_test_case atf_check_expout_mismatch 53240116Smarcelatf_check_expout_mismatch_head() 54240116Smarcel{ 55240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 56240116Smarcel} 57240116Smarcelatf_check_expout_mismatch_body() 58240116Smarcel{ 59240116Smarcel cat >expout <<SECONDEOF 60240116Smarcelfoo 61240116SmarcelSECONDEOF 62240116Smarcel atf_check -s eq:0 -o file:expout -e empty echo bar 63240116Smarcel} 64240116Smarcel 65240116Smarcelatf_test_case atf_check_experr_mismatch 66240116Smarcelatf_check_experr_mismatch_head() 67240116Smarcel{ 68240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 69240116Smarcel} 70240116Smarcelatf_check_experr_mismatch_body() 71240116Smarcel{ 72240116Smarcel cat >experr <<SECONDEOF 73240116Smarcelfoo 74240116SmarcelSECONDEOF 75240116Smarcel atf_check -s eq:0 -o empty -e file:experr -x 'echo bar 1>&2' 76240116Smarcel} 77240116Smarcel 78240116Smarcelatf_test_case atf_check_null_stdout 79240116Smarcelatf_check_null_stdout_head() 80240116Smarcel{ 81240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 82240116Smarcel} 83240116Smarcelatf_check_null_stdout_body() 84240116Smarcel{ 85240116Smarcel atf_check -s eq:0 -o empty -e empty echo "These are the contents" 86240116Smarcel} 87240116Smarcel 88240116Smarcelatf_test_case atf_check_null_stderr 89240116Smarcelatf_check_null_stderr_head() 90240116Smarcel{ 91240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 92240116Smarcel} 93240116Smarcelatf_check_null_stderr_body() 94240116Smarcel{ 95240116Smarcel atf_check -s eq:0 -o empty -e empty -x 'echo "These are the contents" 1>&2' 96240116Smarcel} 97240116Smarcel 98240116Smarcelatf_test_case atf_check_equal_ok 99240116Smarcelatf_check_equal_ok_head() 100240116Smarcel{ 101240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 102240116Smarcel} 103240116Smarcelatf_check_equal_ok_body() 104240116Smarcel{ 105240116Smarcel atf_check_equal a a 106240116Smarcel} 107240116Smarcel 108240116Smarcelatf_test_case atf_check_equal_fail 109240116Smarcelatf_check_equal_fail_head() 110240116Smarcel{ 111240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 112240116Smarcel} 113240116Smarcelatf_check_equal_fail_body() 114240116Smarcel{ 115240116Smarcel atf_check_equal a b 116240116Smarcel} 117240116Smarcel 118240116Smarcelatf_test_case atf_check_equal_eval_ok 119240116Smarcelatf_check_equal_eval_ok_head() 120240116Smarcel{ 121240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 122240116Smarcel} 123240116Smarcelatf_check_equal_eval_ok_body() 124240116Smarcel{ 125240116Smarcel x=a 126240116Smarcel y=a 127240116Smarcel atf_check_equal '${x}' '${y}' 128240116Smarcel} 129240116Smarcel 130240116Smarcelatf_test_case atf_check_equal_eval_fail 131240116Smarcelatf_check_equal_eval_fail_head() 132240116Smarcel{ 133240116Smarcel atf_set "descr" "Helper test case for the t_atf_check test program" 134240116Smarcel} 135240116Smarcelatf_check_equal_eval_fail_body() 136240116Smarcel{ 137240116Smarcel x=a 138240116Smarcel y=b 139240116Smarcel atf_check_equal '${x}' '${y}' 140240116Smarcel} 141240116Smarcel 142283848Sngieatf_test_case atf_check_flush_stdout 143283848Sngieatf_check_flush_stdout_head() 144260029Sjmmv{ 145260029Sjmmv atf_set "descr" "Helper test case for the t_atf_check test program" 146283848Sngie atf_set "timeout" "30" 147260029Sjmmv} 148283848Sngieatf_check_flush_stdout_body() 149260029Sjmmv{ 150260029Sjmmv atf_check true 151283848Sngie atf_check -s exit:1 false 152283848Sngie touch "${CONTROL_FILE:-done}" 153283848Sngie while :; do 154283848Sngie sleep 1 155283848Sngie done 156260029Sjmmv} 157260029Sjmmv 158240116Smarcel# ------------------------------------------------------------------------- 159240116Smarcel# Helper tests for "t_config". 160240116Smarcel# ------------------------------------------------------------------------- 161240116Smarcel 162240116Smarcelatf_test_case config_get 163240116Smarcelconfig_get_head() 164240116Smarcel{ 165240116Smarcel atf_set "descr" "Helper test case for the t_config test program" 166240116Smarcel} 167240116Smarcelconfig_get_body() 168240116Smarcel{ 169240116Smarcel if atf_config_has ${TEST_VARIABLE}; then 170240116Smarcel echo "${TEST_VARIABLE} = $(atf_config_get ${TEST_VARIABLE})" 171240116Smarcel fi 172240116Smarcel} 173240116Smarcel 174240116Smarcelatf_test_case config_has 175240116Smarcelconfig_has_head() 176240116Smarcel{ 177240116Smarcel atf_set "descr" "Helper test case for the t_config test program" 178240116Smarcel} 179240116Smarcelconfig_has_body() 180240116Smarcel{ 181240116Smarcel if atf_config_has ${TEST_VARIABLE}; then 182240116Smarcel echo "${TEST_VARIABLE} found" 183240116Smarcel else 184240116Smarcel echo "${TEST_VARIABLE} not found" 185240116Smarcel fi 186240116Smarcel} 187240116Smarcel 188240116Smarcel# ------------------------------------------------------------------------- 189240116Smarcel# Helper tests for "t_normalize". 190240116Smarcel# ------------------------------------------------------------------------- 191240116Smarcel 192240116Smarcelatf_test_case normalize 193240116Smarcelnormalize_head() 194240116Smarcel{ 195240116Smarcel atf_set "descr" "Helper test case for the t_normalize test program" 196240116Smarcel atf_set "a.b" "test value 1" 197240116Smarcel atf_set "c-d" "test value 2" 198240116Smarcel} 199240116Smarcelnormalize_body() 200240116Smarcel{ 201240116Smarcel echo "a.b: $(atf_get a.b)" 202240116Smarcel echo "c-d: $(atf_get c-d)" 203240116Smarcel} 204240116Smarcel 205240116Smarcel# ------------------------------------------------------------------------- 206240116Smarcel# Helper tests for "t_tc". 207240116Smarcel# ------------------------------------------------------------------------- 208240116Smarcel 209240116Smarcelatf_test_case tc_pass_true 210240116Smarceltc_pass_true_head() 211240116Smarcel{ 212240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 213240116Smarcel} 214240116Smarceltc_pass_true_body() 215240116Smarcel{ 216240116Smarcel true 217240116Smarcel} 218240116Smarcel 219240116Smarcelatf_test_case tc_pass_false 220240116Smarceltc_pass_false_head() 221240116Smarcel{ 222240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 223240116Smarcel} 224240116Smarceltc_pass_false_body() 225240116Smarcel{ 226240116Smarcel false 227240116Smarcel} 228240116Smarcel 229240116Smarcelatf_test_case tc_pass_return_error 230240116Smarceltc_pass_return_error_head() 231240116Smarcel{ 232240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 233240116Smarcel} 234240116Smarceltc_pass_return_error_body() 235240116Smarcel{ 236240116Smarcel return 1 237240116Smarcel} 238240116Smarcel 239240116Smarcelatf_test_case tc_fail 240240116Smarceltc_fail_head() 241240116Smarcel{ 242240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 243240116Smarcel} 244240116Smarceltc_fail_body() 245240116Smarcel{ 246240116Smarcel echo "An error" 1>&2 247240116Smarcel exit 1 248240116Smarcel} 249240116Smarcel 250240116Smarcelatf_test_case tc_missing_body 251240116Smarceltc_missing_body_head() 252240116Smarcel{ 253240116Smarcel atf_set "descr" "Helper test case for the t_tc test program" 254240116Smarcel} 255240116Smarcel 256240116Smarcel# ------------------------------------------------------------------------- 257240116Smarcel# Helper tests for "t_tp". 258240116Smarcel# ------------------------------------------------------------------------- 259240116Smarcel 260240116Smarcelatf_test_case tp_srcdir 261240116Smarceltp_srcdir_head() 262240116Smarcel{ 263240116Smarcel atf_set "descr" "Helper test case for the t_tp test program" 264240116Smarcel} 265240116Smarceltp_srcdir_body() 266240116Smarcel{ 267240116Smarcel echo "Calling helper" 268240116Smarcel helper_subr || atf_fail "Could not call helper subroutine" 269240116Smarcel} 270240116Smarcel 271240116Smarcel# ------------------------------------------------------------------------- 272240116Smarcel# Main. 273240116Smarcel# ------------------------------------------------------------------------- 274240116Smarcel 275240116Smarcelatf_init_test_cases() 276240116Smarcel{ 277240116Smarcel # Add helper tests for t_atf_check. 278240116Smarcel atf_add_test_case atf_check_info_ok 279240116Smarcel atf_add_test_case atf_check_info_fail 280240116Smarcel atf_add_test_case atf_check_expout_mismatch 281240116Smarcel atf_add_test_case atf_check_experr_mismatch 282240116Smarcel atf_add_test_case atf_check_null_stdout 283240116Smarcel atf_add_test_case atf_check_null_stderr 284240116Smarcel atf_add_test_case atf_check_equal_ok 285240116Smarcel atf_add_test_case atf_check_equal_fail 286240116Smarcel atf_add_test_case atf_check_equal_eval_ok 287240116Smarcel atf_add_test_case atf_check_equal_eval_fail 288283848Sngie atf_add_test_case atf_check_flush_stdout 289240116Smarcel 290240116Smarcel # Add helper tests for t_config. 291240116Smarcel atf_add_test_case config_get 292240116Smarcel atf_add_test_case config_has 293240116Smarcel 294240116Smarcel # Add helper tests for t_normalize. 295240116Smarcel atf_add_test_case normalize 296240116Smarcel 297240116Smarcel # Add helper tests for t_tc. 298240116Smarcel atf_add_test_case tc_pass_true 299240116Smarcel atf_add_test_case tc_pass_false 300240116Smarcel atf_add_test_case tc_pass_return_error 301240116Smarcel atf_add_test_case tc_fail 302240116Smarcel atf_add_test_case tc_missing_body 303240116Smarcel 304240116Smarcel # Add helper tests for t_tp. 305240116Smarcel [ -f $(atf_get_srcdir)/subrs ] && . $(atf_get_srcdir)/subrs 306240116Smarcel atf_add_test_case tp_srcdir 307240116Smarcel} 308240116Smarcel 309240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 310