Path: blob/main/contrib/atf/test-programs/sh_helpers.sh
39507 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_cleanup".27# -------------------------------------------------------------------------2829atf_test_case cleanup_pass cleanup30cleanup_pass_head()31{32atf_set "descr" "Helper test case for the t_cleanup test program"33}34cleanup_pass_body()35{36touch $(atf_config_get tmpfile)37}38cleanup_pass_cleanup()39{40if [ $(atf_config_get cleanup no) = yes ]; then41rm $(atf_config_get tmpfile)42fi43}4445atf_test_case cleanup_fail cleanup46cleanup_fail_head()47{48atf_set "descr" "Helper test case for the t_cleanup test program"49}50cleanup_fail_body()51{52touch $(atf_config_get tmpfile)53atf_fail "On purpose"54}55cleanup_fail_cleanup()56{57if [ $(atf_config_get cleanup no) = yes ]; then58rm $(atf_config_get tmpfile)59fi60}6162atf_test_case cleanup_skip cleanup63cleanup_skip_head()64{65atf_set "descr" "Helper test case for the t_cleanup test program"66}67cleanup_skip_body()68{69touch $(atf_config_get tmpfile)70atf_skip "On purpose"71}72cleanup_skip_cleanup()73{74if [ $(atf_config_get cleanup no) = yes ]; then75rm $(atf_config_get tmpfile)76fi77}7879atf_test_case cleanup_curdir cleanup80cleanup_curdir_head()81{82atf_set "descr" "Helper test case for the t_cleanup test program"83}84cleanup_curdir_body()85{86echo 1234 >oldvalue87}88cleanup_curdir_cleanup()89{90test -f oldvalue && echo "Old value: $(cat oldvalue)"91}9293atf_test_case cleanup_sigterm cleanup94cleanup_sigterm_head()95{96atf_set "descr" "Helper test case for the t_cleanup test program"97}98cleanup_sigterm_body()99{100touch $(atf_config_get tmpfile)101kill $$102touch $(atf_config_get tmpfile).no103}104cleanup_sigterm_cleanup()105{106rm $(atf_config_get tmpfile)107}108109# -------------------------------------------------------------------------110# Helper tests for "t_config".111# -------------------------------------------------------------------------112113atf_test_case config_unset114config_unset_head()115{116atf_set "descr" "Helper test case for the t_config test program"117}118config_unset_body()119{120if atf_config_has 'test'; then121atf_fail "Test variable already defined"122fi123}124125atf_test_case config_empty126config_empty_head()127{128atf_set "descr" "Helper test case for the t_config test program"129}130config_empty_body()131{132atf_check_equal "$(atf_config_get 'test')" ""133}134135atf_test_case config_value136config_value_head()137{138atf_set "descr" "Helper test case for the t_config test program"139}140config_value_body()141{142atf_check_equal "$(atf_config_get 'test')" "foo"143}144145atf_test_case config_multi_value146config_multi_value_head()147{148atf_set "descr" "Helper test case for the t_config test program"149}150config_multi_value_body()151{152atf_check_equal "$(atf_config_get 'test')" "foo bar"153}154155# -------------------------------------------------------------------------156# Helper tests for "t_expect".157# -------------------------------------------------------------------------158159atf_test_case expect_pass_and_pass160expect_pass_and_pass_body()161{162atf_expect_pass163}164165atf_test_case expect_pass_but_fail_requirement166expect_pass_but_fail_requirement_body()167{168atf_expect_pass169atf_fail "Some reason"170}171172atf_test_case expect_pass_but_fail_check173expect_pass_but_fail_check_body()174{175atf_fail "Non-fatal failures not implemented"176}177178atf_test_case expect_fail_and_fail_requirement179expect_fail_and_fail_requirement_body()180{181atf_expect_fail "Fail reason"182atf_fail "The failure"183atf_expect_pass184}185186atf_test_case expect_fail_and_fail_check187expect_fail_and_fail_check_body()188{189atf_fail "Non-fatal failures not implemented"190}191192atf_test_case expect_fail_but_pass193expect_fail_but_pass_body()194{195atf_expect_fail "Fail first"196atf_expect_pass197}198199atf_test_case expect_exit_any_and_exit200expect_exit_any_and_exit_body()201{202atf_expect_exit -1 "Call will exit"203exit 0204}205206atf_test_case expect_exit_code_and_exit207expect_exit_code_and_exit_body()208{209atf_expect_exit 123 "Call will exit"210exit 123211}212213atf_test_case expect_exit_but_pass214expect_exit_but_pass_body()215{216atf_expect_exit -1 "Call won't exit"217}218219atf_test_case expect_signal_any_and_signal220expect_signal_any_and_signal_body()221{222atf_expect_signal -1 "Call will signal"223kill -9 $$224}225226atf_test_case expect_signal_no_and_signal227expect_signal_no_and_signal_body()228{229atf_expect_signal 1 "Call will signal"230kill -1 $$231}232233atf_test_case expect_signal_but_pass234expect_signal_but_pass_body()235{236atf_expect_signal -1 "Call won't signal"237}238239atf_test_case expect_death_and_exit240expect_death_and_exit_body()241{242atf_expect_death "Exit case"243exit 123244}245246atf_test_case expect_death_and_signal247expect_death_and_signal_body()248{249atf_expect_death "Signal case"250kill -9 $$251}252253atf_test_case expect_death_but_pass254expect_death_but_pass_body()255{256atf_expect_death "Call won't die"257}258259atf_test_case expect_timeout_and_hang260expect_timeout_and_hang_head()261{262atf_set "timeout" "1"263}264expect_timeout_and_hang_body()265{266atf_expect_timeout "Will overrun"267sleep 5268}269270atf_test_case expect_timeout_but_pass271expect_timeout_but_pass_head()272{273atf_set "timeout" "1"274}275expect_timeout_but_pass_body()276{277atf_expect_timeout "Will just exit"278}279280# -------------------------------------------------------------------------281# Helper tests for "t_meta_data".282# -------------------------------------------------------------------------283284atf_test_case metadata_no_descr285metadata_no_descr_head()286{287:288}289metadata_no_descr_body()290{291:292}293294atf_test_case metadata_no_head295metadata_no_head_body()296{297:298}299300# -------------------------------------------------------------------------301# Helper tests for "t_srcdir".302# -------------------------------------------------------------------------303304atf_test_case srcdir_exists305srcdir_exists_head()306{307atf_set "descr" "Helper test case for the t_srcdir test program"308}309srcdir_exists_body()310{311[ -f "$(atf_get_srcdir)/datafile" ] || atf_fail "Cannot find datafile"312}313314# -------------------------------------------------------------------------315# Helper tests for "t_result".316# -------------------------------------------------------------------------317318atf_test_case result_pass319result_pass_body()320{321echo "msg"322}323324atf_test_case result_fail325result_fail_body()326{327echo "msg"328atf_fail "Failure reason"329}330331atf_test_case result_skip332result_skip_body()333{334echo "msg"335atf_skip "Skipped reason"336}337338# -------------------------------------------------------------------------339# Main.340# -------------------------------------------------------------------------341342atf_init_test_cases()343{344# Add helper tests for t_cleanup.345atf_add_test_case cleanup_pass346atf_add_test_case cleanup_fail347atf_add_test_case cleanup_skip348atf_add_test_case cleanup_curdir349atf_add_test_case cleanup_sigterm350351# Add helper tests for t_config.352atf_add_test_case config_unset353atf_add_test_case config_empty354atf_add_test_case config_value355atf_add_test_case config_multi_value356357# Add helper tests for t_expect.358atf_add_test_case expect_pass_and_pass359atf_add_test_case expect_pass_but_fail_requirement360atf_add_test_case expect_pass_but_fail_check361atf_add_test_case expect_fail_and_fail_requirement362atf_add_test_case expect_fail_and_fail_check363atf_add_test_case expect_fail_but_pass364atf_add_test_case expect_exit_any_and_exit365atf_add_test_case expect_exit_code_and_exit366atf_add_test_case expect_exit_but_pass367atf_add_test_case expect_signal_any_and_signal368atf_add_test_case expect_signal_no_and_signal369atf_add_test_case expect_signal_but_pass370atf_add_test_case expect_death_and_exit371atf_add_test_case expect_death_and_signal372atf_add_test_case expect_death_but_pass373atf_add_test_case expect_timeout_and_hang374atf_add_test_case expect_timeout_but_pass375376# Add helper tests for t_meta_data.377atf_add_test_case metadata_no_descr378atf_add_test_case metadata_no_head379380# Add helper tests for t_srcdir.381atf_add_test_case srcdir_exists382383# Add helper tests for t_result.384atf_add_test_case result_pass385atf_add_test_case result_fail386atf_add_test_case result_skip387}388389# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4390391392