srcdir_test.sh revision 1.1.1.1
1#
2# Automated Testing Framework (atf)
3#
4# Copyright (c) 2007, 2008, 2010 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    atf_set "use.fs" "true"
42}
43default_body()
44{
45    create_files
46
47    for hp in $(get_helpers); do
48        h=${hp##*/}
49        cp ${hp} tmp
50        atf_check -s eq:0 -o ignore -e ignore -x \
51                  "cd tmp && ./${h} srcdir_exists"
52        atf_check -s eq:1 -o empty -e empty "${hp}" -r res srcdir_exists
53        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
54    done
55}
56
57atf_test_case libtool
58libtool_head()
59{
60    atf_set "descr" "Checks that the program can find its files if" \
61                    "executed from the source directory and if it" \
62                    "was built with libtool"
63    atf_set "use.fs" "true"
64}
65libtool_body()
66{
67    create_files
68    mkdir tmp/.libs
69
70    for hp in $(get_helpers c_helpers cpp_helpers); do
71        h=${hp##*/}
72        cp ${hp} tmp
73        cp ${hp} tmp/.libs
74        atf_check -s eq:0 -o ignore -e ignore -x \
75                  "cd tmp && ./.libs/${h} srcdir_exists"
76        atf_check -s eq:1 -o empty -e empty "${hp}" -r res srcdir_exists
77        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
78    done
79
80    for hp in $(get_helpers c_helpers cpp_helpers); do
81        h=${hp##*/}
82        cp ${hp} tmp
83        cp ${hp} tmp/.libs/lt-${h}
84        atf_check -s eq:0 -o ignore -e ignore -x \
85                  "cd tmp && ./.libs/lt-${h} srcdir_exists"
86        atf_check -s eq:1 -o empty -e empty "${hp}" -r res srcdir_exists
87        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
88    done
89}
90
91atf_test_case sflag
92sflag_head()
93{
94    atf_set "descr" "Checks that the program can find its files when" \
95                    "using the -s flag"
96    atf_set "use.fs" "true"
97}
98sflag_body()
99{
100    create_files
101
102    for hp in $(get_helpers); do
103        h=${hp##*/}
104        cp ${hp} tmp
105        atf_check -s eq:0 -o ignore -e ignore -x \
106                  "cd tmp && ./${h} -s $(pwd)/tmp \
107                   srcdir_exists"
108        atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists
109        atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
110        atf_check -s eq:0 -o ignore -e ignore \
111                  "${hp}" -s "$(pwd)"/tmp srcdir_exists
112    done
113}
114
115atf_test_case relative
116relative_head()
117{
118    atf_set "descr" "Checks that passing a relative path through -s" \
119                    "works"
120    atf_set "use.fs" "true"
121}
122relative_body()
123{
124    create_files
125
126    for hp in $(get_helpers); do
127        h=${hp##*/}
128        cp ${hp} tmp
129
130        for p in tmp tmp/. ./tmp; do
131            echo "Helper is: ${h}"
132            echo "Using source directory: ${p}"
133
134            atf_check -s eq:0 -o ignore -e ignore \
135                      "./tmp/${h}" -s "${p}" srcdir_exists
136            atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \
137                srcdir_exists
138            atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
139            atf_check -s eq:0 -o ignore -e ignore \
140                      "${hp}" -s "${p}" srcdir_exists
141        done
142    done
143}
144
145atf_init_test_cases()
146{
147    atf_add_test_case default
148    atf_add_test_case libtool
149    atf_add_test_case sflag
150    atf_add_test_case relative
151}
152
153# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
154