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