Path: blob/main/contrib/atf/atf-sh/misc_helpers.sh
39478 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.2425# -------------------------------------------------------------------------26# Helper tests for "t_atf_check".27# -------------------------------------------------------------------------2829atf_test_case atf_check_info_ok30atf_check_info_ok_head()31{32atf_set "descr" "Helper test case for the t_atf_check test program"33}34atf_check_info_ok_body()35{36atf_check -s eq:0 -o empty -e empty true37}3839atf_test_case atf_check_info_fail40atf_check_info_fail_head()41{42atf_set "descr" "Helper test case for the t_atf_check test program"43}44atf_check_info_fail_body()45{46# In Solaris, /usr/bin/false returns 255 rather than 1. Use the47# built-in version for the check.48atf_check -s eq:1 -o empty -e empty sh -c "false"49}5051atf_test_case atf_check_expout_mismatch52atf_check_expout_mismatch_head()53{54atf_set "descr" "Helper test case for the t_atf_check test program"55}56atf_check_expout_mismatch_body()57{58cat >expout <<SECONDEOF59foo60SECONDEOF61atf_check -s eq:0 -o file:expout -e empty echo bar62}6364atf_test_case atf_check_experr_mismatch65atf_check_experr_mismatch_head()66{67atf_set "descr" "Helper test case for the t_atf_check test program"68}69atf_check_experr_mismatch_body()70{71cat >experr <<SECONDEOF72foo73SECONDEOF74atf_check -s eq:0 -o empty -e file:experr -x 'echo bar 1>&2'75}7677atf_test_case atf_check_null_stdout78atf_check_null_stdout_head()79{80atf_set "descr" "Helper test case for the t_atf_check test program"81}82atf_check_null_stdout_body()83{84atf_check -s eq:0 -o empty -e empty echo "These are the contents"85}8687atf_test_case atf_check_null_stderr88atf_check_null_stderr_head()89{90atf_set "descr" "Helper test case for the t_atf_check test program"91}92atf_check_null_stderr_body()93{94atf_check -s eq:0 -o empty -e empty -x 'echo "These are the contents" 1>&2'95}9697atf_test_case atf_check_equal_ok98atf_check_equal_ok_head()99{100atf_set "descr" "Helper test case for the t_atf_check test program"101}102atf_check_equal_ok_body()103{104atf_check_equal a a105}106107atf_test_case atf_check_equal_fail108atf_check_equal_fail_head()109{110atf_set "descr" "Helper test case for the t_atf_check test program"111}112atf_check_equal_fail_body()113{114atf_check_equal a b115}116117atf_test_case atf_check_equal_eval_ok118atf_check_equal_eval_ok_head()119{120atf_set "descr" "Helper test case for the t_atf_check test program"121}122atf_check_equal_eval_ok_body()123{124x=a125y=a126atf_check_equal '${x}' '${y}'127}128129atf_test_case atf_check_equal_eval_fail130atf_check_equal_eval_fail_head()131{132atf_set "descr" "Helper test case for the t_atf_check test program"133}134atf_check_equal_eval_fail_body()135{136x=a137y=b138atf_check_equal '${x}' '${y}'139}140141atf_test_case atf_check_not_equal_ok142atf_check_not_equal_ok_head()143{144atf_set "descr" "Helper test case for the t_atf_check test program"145}146atf_check_not_equal_ok_body()147{148atf_check_not_equal a b149}150151atf_test_case atf_check_not_equal_fail152atf_check_not_equal_fail_head()153{154atf_set "descr" "Helper test case for the t_atf_check test program"155}156atf_check_not_equal_fail_body()157{158atf_check_not_equal a a159}160161atf_test_case atf_check_not_equal_eval_ok162atf_check_not_equal_eval_ok_head()163{164atf_set "descr" "Helper test case for the t_atf_check test program"165}166atf_check_not_equal_eval_ok_body()167{168x=a169y=b170atf_check_not_equal '${x}' '${y}'171}172173atf_test_case atf_check_not_equal_eval_fail174atf_check_not_equal_eval_fail_head()175{176atf_set "descr" "Helper test case for the t_atf_check test program"177}178atf_check_not_equal_eval_fail_body()179{180x=a181y=a182atf_check_not_equal '${x}' '${y}'183}184185atf_test_case atf_check_flush_stdout186atf_check_flush_stdout_head()187{188atf_set "descr" "Helper test case for the t_atf_check test program"189atf_set "timeout" "30"190}191atf_check_flush_stdout_body()192{193atf_check true194atf_check -s exit:1 false195touch "${CONTROL_FILE:-done}"196while :; do197sleep 1198done199}200201# -------------------------------------------------------------------------202# Helper tests for "t_config".203# -------------------------------------------------------------------------204205atf_test_case config_get206config_get_head()207{208atf_set "descr" "Helper test case for the t_config test program"209}210config_get_body()211{212if atf_config_has ${TEST_VARIABLE}; then213echo "${TEST_VARIABLE} = $(atf_config_get ${TEST_VARIABLE})"214fi215}216217atf_test_case config_has218config_has_head()219{220atf_set "descr" "Helper test case for the t_config test program"221}222config_has_body()223{224if atf_config_has ${TEST_VARIABLE}; then225echo "${TEST_VARIABLE} found"226else227echo "${TEST_VARIABLE} not found"228fi229}230231# -------------------------------------------------------------------------232# Helper tests for "t_normalize".233# -------------------------------------------------------------------------234235atf_test_case normalize236normalize_head()237{238atf_set "descr" "Helper test case for the t_normalize test program"239atf_set "a.b" "test value 1"240atf_set "c-d" "test value 2"241}242normalize_body()243{244echo "a.b: $(atf_get a.b)"245echo "c-d: $(atf_get c-d)"246}247248# -------------------------------------------------------------------------249# Helper tests for "t_tc".250# -------------------------------------------------------------------------251252atf_test_case tc_pass_true253tc_pass_true_head()254{255atf_set "descr" "Helper test case for the t_tc test program"256}257tc_pass_true_body()258{259true260}261262atf_test_case tc_pass_false263tc_pass_false_head()264{265atf_set "descr" "Helper test case for the t_tc test program"266}267tc_pass_false_body()268{269false270}271272atf_test_case tc_pass_return_error273tc_pass_return_error_head()274{275atf_set "descr" "Helper test case for the t_tc test program"276}277tc_pass_return_error_body()278{279return 1280}281282atf_test_case tc_fail283tc_fail_head()284{285atf_set "descr" "Helper test case for the t_tc test program"286}287tc_fail_body()288{289echo "An error" 1>&2290exit 1291}292293atf_test_case tc_missing_body294tc_missing_body_head()295{296atf_set "descr" "Helper test case for the t_tc test program"297}298299# -------------------------------------------------------------------------300# Helper tests for "t_tp".301# -------------------------------------------------------------------------302303atf_test_case tp_srcdir304tp_srcdir_head()305{306atf_set "descr" "Helper test case for the t_tp test program"307}308tp_srcdir_body()309{310echo "Calling helper"311helper_subr || atf_fail "Could not call helper subroutine"312}313314# -------------------------------------------------------------------------315# Main.316# -------------------------------------------------------------------------317318atf_init_test_cases()319{320# Add helper tests for t_atf_check.321atf_add_test_case atf_check_info_ok322atf_add_test_case atf_check_info_fail323atf_add_test_case atf_check_expout_mismatch324atf_add_test_case atf_check_experr_mismatch325atf_add_test_case atf_check_null_stdout326atf_add_test_case atf_check_null_stderr327atf_add_test_case atf_check_equal_ok328atf_add_test_case atf_check_equal_fail329atf_add_test_case atf_check_equal_eval_ok330atf_add_test_case atf_check_equal_eval_fail331atf_add_test_case atf_check_not_equal_ok332atf_add_test_case atf_check_not_equal_fail333atf_add_test_case atf_check_not_equal_eval_ok334atf_add_test_case atf_check_not_equal_eval_fail335atf_add_test_case atf_check_flush_stdout336337# Add helper tests for t_config.338atf_add_test_case config_get339atf_add_test_case config_has340341# Add helper tests for t_normalize.342atf_add_test_case normalize343344# Add helper tests for t_tc.345atf_add_test_case tc_pass_true346atf_add_test_case tc_pass_false347atf_add_test_case tc_pass_return_error348atf_add_test_case tc_fail349atf_add_test_case tc_missing_body350351# Add helper tests for t_tp.352[ -f $(atf_get_srcdir)/subrs ] && . $(atf_get_srcdir)/subrs353atf_add_test_case tp_srcdir354}355356# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4357358359