1# 2# Automated Testing Framework (atf) 3# 4# Copyright (c) 2007 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29 30create_files() 31{ 32 mkdir tmp 33 touch tmp/datafile 34} 35 36atf_test_case default 37default_head() 38{ 39 atf_set "descr" "Checks that the program can find its files if" \ 40 "executed from the same directory" 41} 42default_body() 43{ 44 create_files 45 46 for hp in $(get_helpers); do 47 h=${hp##*/} 48 cp ${hp} tmp 49 atf_check -s eq:0 -o ignore -e ignore -x \ 50 "cd tmp && ./${h} srcdir_exists" 51 atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists 52 atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 53 done 54} 55 56atf_test_case libtool 57libtool_head() 58{ 59 atf_set "descr" "Checks that the program can find its files if" \ 60 "executed from the source directory and if it" \ 61 "was built with libtool" 62} 63libtool_body() 64{ 65 create_files 66 mkdir tmp/.libs 67 68 for hp in $(get_helpers c_helpers cpp_helpers); do 69 h=${hp##*/} 70 cp ${hp} tmp 71 cp ${hp} tmp/.libs 72 atf_check -s eq:0 -o ignore -e ignore -x \ 73 "cd tmp && ./.libs/${h} srcdir_exists" 74 atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists 75 atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 76 done 77 78 for hp in $(get_helpers c_helpers cpp_helpers); do 79 h=${hp##*/} 80 cp ${hp} tmp 81 cp ${hp} tmp/.libs/lt-${h} 82 atf_check -s eq:0 -o ignore -e ignore -x \ 83 "cd tmp && ./.libs/lt-${h} srcdir_exists" 84 atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists 85 atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 86 done 87} 88 89atf_test_case sflag 90sflag_head() 91{ 92 atf_set "descr" "Checks that the program can find its files when" \ 93 "using the -s flag" 94} 95sflag_body() 96{ 97 create_files 98 99 for hp in $(get_helpers); do 100 h=${hp##*/} 101 cp ${hp} tmp 102 atf_check -s eq:0 -o ignore -e ignore -x \ 103 "cd tmp && ./${h} -s $(pwd)/tmp \ 104 srcdir_exists" 105 atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists 106 atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 107 atf_check -s eq:0 -o ignore -e ignore \ 108 "${hp}" -s "$(pwd)"/tmp srcdir_exists 109 done 110} 111 112atf_test_case relative 113relative_head() 114{ 115 atf_set "descr" "Checks that passing a relative path through -s" \ 116 "works" 117} 118relative_body() 119{ 120 create_files 121 122 for hp in $(get_helpers); do 123 h=${hp##*/} 124 cp ${hp} tmp 125 126 for p in tmp tmp/. ./tmp; do 127 echo "Helper is: ${h}" 128 echo "Using source directory: ${p}" 129 130 atf_check -s eq:0 -o ignore -e ignore \ 131 "./tmp/${h}" -s "${p}" srcdir_exists 132 atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \ 133 srcdir_exists 134 atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res 135 atf_check -s eq:0 -o ignore -e ignore \ 136 "${hp}" -s "${p}" srcdir_exists 137 done 138 done 139} 140 141atf_init_test_cases() 142{ 143 atf_add_test_case default 144 atf_add_test_case libtool 145 atf_add_test_case sflag 146 atf_add_test_case relative 147} 148 149# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 150