srcdir_test.sh revision 240116
1193323Sed# 2193323Sed# Automated Testing Framework (atf) 3193323Sed# 4193323Sed# Copyright (c) 2007 The NetBSD Foundation, Inc. 5193323Sed# All rights reserved. 6193323Sed# 7193323Sed# Redistribution and use in source and binary forms, with or without 8193323Sed# modification, are permitted provided that the following conditions 9193323Sed# are met: 10193323Sed# 1. Redistributions of source code must retain the above copyright 11193323Sed# notice, this list of conditions and the following disclaimer. 12193323Sed# 2. Redistributions in binary form must reproduce the above copyright 13193323Sed# notice, this list of conditions and the following disclaimer in the 14193323Sed# documentation and/or other materials provided with the distribution. 15193323Sed# 16193323Sed# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17249423Sdim# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18249423Sdim# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19249423Sdim# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20249423Sdim# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21249423Sdim# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22193323Sed# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23198892Srdivacky# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24193323Sed# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25193323Sed# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26249423Sdim# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27193323Sed# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28193323Sed# 29193323Sed 30193323Sedcreate_files() 31193323Sed{ 32212904Sdim mkdir tmp 33198892Srdivacky touch tmp/datafile 34193323Sed} 35193323Sed 36218893Sdimatf_test_case default 37218893Sdimdefault_head() 38218893Sdim{ 39193323Sed atf_set "descr" "Checks that the program can find its files if" \ 40193323Sed "executed from the same directory" 41193323Sed} 42193323Seddefault_body() 43193323Sed{ 44193323Sed create_files 45212904Sdim 46193323Sed for hp in $(get_helpers); do 47193323Sed h=${hp##*/} 48193323Sed cp ${hp} tmp 49193323Sed atf_check -s eq:0 -o ignore -e ignore -x \ 50193323Sed "cd tmp && ./${h} srcdir_exists" 51193323Sed atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists 52193323Sed atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 53193323Sed done 54212904Sdim} 55193323Sed 56193323Sedatf_test_case libtool 57193323Sedlibtool_head() 58193323Sed{ 59193323Sed atf_set "descr" "Checks that the program can find its files if" \ 60193323Sed "executed from the source directory and if it" \ 61193323Sed "was built with libtool" 62193323Sed} 63193323Sedlibtool_body() 64193323Sed{ 65193323Sed create_files 66193323Sed mkdir tmp/.libs 67193323Sed 68193323Sed for hp in $(get_helpers c_helpers cpp_helpers); do 69263508Sdim h=${hp##*/} 70263508Sdim cp ${hp} tmp 71263508Sdim cp ${hp} tmp/.libs 72263508Sdim atf_check -s eq:0 -o ignore -e ignore -x \ 73263508Sdim "cd tmp && ./.libs/${h} srcdir_exists" 74263508Sdim atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists 75263508Sdim atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 76263508Sdim done 77263508Sdim 78263508Sdim for hp in $(get_helpers c_helpers cpp_helpers); do 79263508Sdim h=${hp##*/} 80263508Sdim cp ${hp} tmp 81193323Sed cp ${hp} tmp/.libs/lt-${h} 82193323Sed atf_check -s eq:0 -o ignore -e ignore -x \ 83193323Sed "cd tmp && ./.libs/lt-${h} srcdir_exists" 84212904Sdim atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists 85218893Sdim atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 86193323Sed done 87221345Sdim} 88212904Sdim 89193323Sedatf_test_case sflag 90193323Sedsflag_head() 91193323Sed{ 92193323Sed atf_set "descr" "Checks that the program can find its files when" \ 93193323Sed "using the -s flag" 94193323Sed} 95193323Sedsflag_body() 96193323Sed{ 97193323Sed create_files 98193323Sed 99193323Sed for hp in $(get_helpers); do 100193323Sed h=${hp##*/} 101193323Sed cp ${hp} tmp 102193323Sed atf_check -s eq:0 -o ignore -e ignore -x \ 103193323Sed "cd tmp && ./${h} -s $(pwd)/tmp \ 104193323Sed srcdir_exists" 105193323Sed atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists 106193323Sed atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 107193323Sed atf_check -s eq:0 -o ignore -e ignore \ 108193323Sed "${hp}" -s "$(pwd)"/tmp srcdir_exists 109193323Sed done 110193323Sed} 111198090Srdivacky 112218893Sdimatf_test_case relative 113218893Sdimrelative_head() 114198090Srdivacky{ 115198090Srdivacky atf_set "descr" "Checks that passing a relative path through -s" \ 116193323Sed "works" 117193323Sed} 118193323Sedrelative_body() 119193323Sed{ 120193323Sed create_files 121193323Sed 122193323Sed for hp in $(get_helpers); do 123193323Sed h=${hp##*/} 124193323Sed cp ${hp} tmp 125193323Sed 126193323Sed for p in tmp tmp/. ./tmp; do 127193323Sed echo "Helper is: ${h}" 128193323Sed echo "Using source directory: ${p}" 129193323Sed 130193323Sed atf_check -s eq:0 -o ignore -e ignore \ 131193323Sed "./tmp/${h}" -s "${p}" srcdir_exists 132193323Sed atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \ 133193323Sed srcdir_exists 134193323Sed atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 135193323Sed atf_check -s eq:0 -o ignore -e ignore \ 136193323Sed "${hp}" -s "${p}" srcdir_exists 137193323Sed done 138193323Sed done 139193323Sed} 140193323Sed 141202375Srdivackyatf_init_test_cases() 142193323Sed{ 143202375Srdivacky atf_add_test_case default 144193323Sed atf_add_test_case libtool 145193323Sed atf_add_test_case sflag 146202375Srdivacky atf_add_test_case relative 147193323Sed} 148193323Sed 149193323Sed# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 150193323Sed