1240116Smarcel# Copyright (c) 2007 The NetBSD Foundation, Inc.
2240116Smarcel# All rights reserved.
3240116Smarcel#
4240116Smarcel# Redistribution and use in source and binary forms, with or without
5240116Smarcel# modification, are permitted provided that the following conditions
6240116Smarcel# are met:
7240116Smarcel# 1. Redistributions of source code must retain the above copyright
8240116Smarcel#    notice, this list of conditions and the following disclaimer.
9240116Smarcel# 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel#    notice, this list of conditions and the following disclaimer in the
11240116Smarcel#    documentation and/or other materials provided with the distribution.
12240116Smarcel#
13240116Smarcel# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24240116Smarcel# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25240116Smarcel
26240116Smarcelcreate_files()
27240116Smarcel{
28240116Smarcel    mkdir tmp
29240116Smarcel    touch tmp/datafile
30240116Smarcel}
31240116Smarcel
32240116Smarcelatf_test_case default
33240116Smarceldefault_head()
34240116Smarcel{
35240116Smarcel    atf_set "descr" "Checks that the program can find its files if" \
36240116Smarcel                    "executed from the same directory"
37240116Smarcel}
38240116Smarceldefault_body()
39240116Smarcel{
40240116Smarcel    create_files
41240116Smarcel
42240116Smarcel    for hp in $(get_helpers); do
43240116Smarcel        h=${hp##*/}
44240116Smarcel        cp ${hp} tmp
45240116Smarcel        atf_check -s eq:0 -o ignore -e ignore -x \
46240116Smarcel                  "cd tmp && ./${h} srcdir_exists"
47240116Smarcel        atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists
48240116Smarcel        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
49240116Smarcel    done
50240116Smarcel}
51240116Smarcel
52240116Smarcelatf_test_case libtool
53240116Smarcellibtool_head()
54240116Smarcel{
55240116Smarcel    atf_set "descr" "Checks that the program can find its files if" \
56240116Smarcel                    "executed from the source directory and if it" \
57240116Smarcel                    "was built with libtool"
58240116Smarcel}
59240116Smarcellibtool_body()
60240116Smarcel{
61240116Smarcel    create_files
62240116Smarcel    mkdir tmp/.libs
63240116Smarcel
64240116Smarcel    for hp in $(get_helpers c_helpers cpp_helpers); do
65240116Smarcel        h=${hp##*/}
66240116Smarcel        cp ${hp} tmp
67240116Smarcel        cp ${hp} tmp/.libs
68240116Smarcel        atf_check -s eq:0 -o ignore -e ignore -x \
69240116Smarcel                  "cd tmp && ./.libs/${h} srcdir_exists"
70240116Smarcel        atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists
71240116Smarcel        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
72240116Smarcel    done
73240116Smarcel
74240116Smarcel    for hp in $(get_helpers c_helpers cpp_helpers); do
75240116Smarcel        h=${hp##*/}
76240116Smarcel        cp ${hp} tmp
77240116Smarcel        cp ${hp} tmp/.libs/lt-${h}
78240116Smarcel        atf_check -s eq:0 -o ignore -e ignore -x \
79240116Smarcel                  "cd tmp && ./.libs/lt-${h} srcdir_exists"
80240116Smarcel        atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists
81240116Smarcel        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
82240116Smarcel    done
83240116Smarcel}
84240116Smarcel
85240116Smarcelatf_test_case sflag
86240116Smarcelsflag_head()
87240116Smarcel{
88240116Smarcel    atf_set "descr" "Checks that the program can find its files when" \
89240116Smarcel                    "using the -s flag"
90240116Smarcel}
91240116Smarcelsflag_body()
92240116Smarcel{
93240116Smarcel    create_files
94240116Smarcel
95240116Smarcel    for hp in $(get_helpers); do
96240116Smarcel        h=${hp##*/}
97240116Smarcel        cp ${hp} tmp
98240116Smarcel        atf_check -s eq:0 -o ignore -e ignore -x \
99240116Smarcel                  "cd tmp && ./${h} -s $(pwd)/tmp \
100240116Smarcel                   srcdir_exists"
101240116Smarcel        atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists
102240116Smarcel        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
103240116Smarcel        atf_check -s eq:0 -o ignore -e ignore \
104240116Smarcel                  "${hp}" -s "$(pwd)"/tmp srcdir_exists
105240116Smarcel    done
106240116Smarcel}
107240116Smarcel
108240116Smarcelatf_test_case relative
109240116Smarcelrelative_head()
110240116Smarcel{
111240116Smarcel    atf_set "descr" "Checks that passing a relative path through -s" \
112240116Smarcel                    "works"
113240116Smarcel}
114240116Smarcelrelative_body()
115240116Smarcel{
116240116Smarcel    create_files
117240116Smarcel
118240116Smarcel    for hp in $(get_helpers); do
119240116Smarcel        h=${hp##*/}
120240116Smarcel        cp ${hp} tmp
121240116Smarcel
122240116Smarcel        for p in tmp tmp/. ./tmp; do
123240116Smarcel            echo "Helper is: ${h}"
124240116Smarcel            echo "Using source directory: ${p}"
125240116Smarcel
126240116Smarcel            atf_check -s eq:0 -o ignore -e ignore \
127240116Smarcel                      "./tmp/${h}" -s "${p}" srcdir_exists
128240116Smarcel            atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \
129240116Smarcel                srcdir_exists
130240116Smarcel            atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
131240116Smarcel            atf_check -s eq:0 -o ignore -e ignore \
132240116Smarcel                      "${hp}" -s "${p}" srcdir_exists
133240116Smarcel        done
134240116Smarcel    done
135240116Smarcel}
136240116Smarcel
137240116Smarcelatf_init_test_cases()
138240116Smarcel{
139240116Smarcel    atf_add_test_case default
140240116Smarcel    atf_add_test_case libtool
141240116Smarcel    atf_add_test_case sflag
142240116Smarcel    atf_add_test_case relative
143240116Smarcel}
144240116Smarcel
145240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
146