Path: blob/main/contrib/atf/test-programs/srcdir_test.sh
39534 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.2425create_files()26{27mkdir tmp28touch tmp/datafile29}3031atf_test_case default32default_head()33{34atf_set "descr" "Checks that the program can find its files if" \35"executed from the same directory"36}37default_body()38{39create_files4041for hp in $(get_helpers); do42h=${hp##*/}43cp ${hp} tmp44atf_check -s eq:0 -o ignore -e ignore -x \45"cd tmp && ./${h} srcdir_exists"46atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists47atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res48done49}5051atf_test_case libtool52libtool_head()53{54atf_set "descr" "Checks that the program can find its files if" \55"executed from the source directory and if it" \56"was built with libtool"57}58libtool_body()59{60create_files61mkdir tmp/.libs6263for hp in $(get_helpers c_helpers cpp_helpers); do64h=${hp##*/}65cp ${hp} tmp66cp ${hp} tmp/.libs67atf_check -s eq:0 -o ignore -e ignore -x \68"cd tmp && ./.libs/${h} srcdir_exists"69atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists70atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res71done7273for hp in $(get_helpers c_helpers cpp_helpers); do74h=${hp##*/}75cp ${hp} tmp76cp ${hp} tmp/.libs/lt-${h}77atf_check -s eq:0 -o ignore -e ignore -x \78"cd tmp && ./.libs/lt-${h} srcdir_exists"79atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists80atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res81done82}8384atf_test_case sflag85sflag_head()86{87atf_set "descr" "Checks that the program can find its files when" \88"using the -s flag"89}90sflag_body()91{92create_files9394for hp in $(get_helpers); do95h=${hp##*/}96cp ${hp} tmp97atf_check -s eq:0 -o ignore -e ignore -x \98"cd tmp && ./${h} -s $(pwd)/tmp \99srcdir_exists"100atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists101atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res102atf_check -s eq:0 -o ignore -e ignore \103"${hp}" -s "$(pwd)"/tmp srcdir_exists104done105}106107atf_test_case relative108relative_head()109{110atf_set "descr" "Checks that passing a relative path through -s" \111"works"112}113relative_body()114{115create_files116117for hp in $(get_helpers); do118h=${hp##*/}119cp ${hp} tmp120121for p in tmp tmp/. ./tmp; do122echo "Helper is: ${h}"123echo "Using source directory: ${p}"124125atf_check -s eq:0 -o ignore -e ignore \126"./tmp/${h}" -s "${p}" srcdir_exists127atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \128srcdir_exists129atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res130atf_check -s eq:0 -o ignore -e ignore \131"${hp}" -s "${p}" srcdir_exists132done133done134}135136atf_init_test_cases()137{138atf_add_test_case default139atf_add_test_case libtool140atf_add_test_case sflag141atf_add_test_case relative142}143144# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4145146147