]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/atf/atf-config/integration_test.sh
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / contrib / atf / atf-config / integration_test.sh
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
30 all_vars="atf_arch \
31           atf_build_cc \
32           atf_build_cflags \
33           atf_build_cpp \
34           atf_build_cppflags \
35           atf_build_cxx \
36           atf_build_cxxflags \
37           atf_confdir \
38           atf_includedir \
39           atf_libdir \
40           atf_libexecdir \
41           atf_machine \
42           atf_pkgdatadir \
43           atf_shell \
44           atf_workdir"
45 all_vars_no=15
46
47 atf_test_case list_all
48 list_all_head()
49 {
50     atf_set "descr" "Tests that at atf-config prints all expected" \
51                     "variables, and not more"
52 }
53 list_all_body()
54 {
55     atf_check -s eq:0 -o save:stdout -e empty atf-config
56     atf_check -s eq:0 -o empty -e empty \
57               test "$(wc -l stdout | awk '{ print $1 }')" = "${all_vars_no}"
58     for v in ${all_vars}; do
59         atf_check -s eq:0 -o ignore -e empty grep "${v}" stdout
60     done
61 }
62
63 atf_test_case query_one
64 query_one_head()
65 {
66     atf_set "descr" "Tests that querying a single variable works"
67 }
68 query_one_body()
69 {
70     for v in ${all_vars}; do
71         atf_check -s eq:0 -o save:stdout -o match:"${v}" -e empty \
72             atf-config "${v}"
73         atf_check -s eq:0 -o empty -e empty \
74                   test "$(wc -l stdout | awk '{ print $1 }')" = 1
75     done
76 }
77
78 atf_test_case query_one_terse
79 query_one_terse_head()
80 {
81     atf_set "descr" "Tests that querying a single variable in terse mode" \
82                     "works"
83 }
84 query_one_terse_body()
85 {
86     for v in ${all_vars}; do
87         atf_check -s eq:0 -o save:stdout -o match:"${v}" -e empty \
88             atf-config "${v}"
89         atf_check -s eq:0 -o empty -e empty \
90                   test "$(wc -l stdout | awk '{ print $1 }')" = 1
91         atf_check -s eq:0 -o save:stdout -e empty cut -d ' ' -f 3- stdout
92         atf_check -s eq:0 -o empty -e empty mv stdout expout
93         atf_check -s eq:0 -o file:expout -e empty atf-config -t "${v}"
94     done
95 }
96
97 atf_test_case query_multiple
98 query_multiple_head()
99 {
100     atf_set "descr" "Tests that querying multiple variables works"
101 }
102 query_multiple_body()
103 {
104     atf_check -s eq:0 -o save:stdout -o match:'atf_libexecdir' \
105         -o match:'atf_shell' -e empty atf-config atf_libexecdir atf_shell
106     atf_check -s eq:0 -o empty -e empty \
107               test "$(wc -l stdout | awk '{ print $1 }')" = 2
108 }
109
110 atf_test_case query_unknown
111 query_unknown_head()
112 {
113     atf_set "descr" "Tests that querying an unknown variable delivers" \
114                     "the correct error"
115 }
116 query_unknown_body()
117 {
118     atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \
119         atf-config non_existent
120 }
121
122 atf_test_case query_mixture
123 query_mixture_head()
124 {
125     atf_set "descr" "Tests that querying a known and an unknown variable" \
126                     "delivers the correct error"
127 }
128 query_mixture_body()
129 {
130     for v in ${all_vars}; do
131         atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \
132                   atf-config "${v}" non_existent
133         atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \
134                   atf-config non_existent "${v}"
135     done
136 }
137
138 atf_test_case override_env
139 override_env_head()
140 {
141     atf_set "descr" "Tests that build-time variables can be overriden" \
142                     "through their corresponding environment variables"
143 }
144 override_env_body()
145 {
146     for v in ${all_vars}; do
147         V=$(echo ${v} | tr '[a-z]' '[A-Z]')
148         atf_check -s eq:0 -o save:stdout -e empty -x "${V}=testval atf-config"
149         atf_check -s eq:0 -o empty -e empty mv stdout all
150
151         atf_check -s eq:0 -o save:stdout -e empty grep "^${v} : " all
152         atf_check -s eq:0 -o empty -e empty mv stdout affected
153         atf_check -s eq:0 -o save:stdout -e empty grep -v "^${v} : " all
154         atf_check -s eq:0 -o empty -e empty mv stdout unaffected
155
156         atf_check -s eq:0 -o empty -e empty \
157                   test "$(wc -l affected | awk '{ print $1 }')" = 1
158         atf_check -s eq:0 -o empty -e empty \
159                   test "$(wc -l unaffected | awk '{ print $1 }')" = \
160                    "$((${all_vars_no} -1))"
161
162         atf_check -s eq:0 -o ignore -e empty grep "^${v} : testval$" affected
163         atf_check -s eq:1 -o empty -e empty grep ' : testval$' unaffected
164     done
165 }
166
167 atf_init_test_cases()
168 {
169     atf_add_test_case list_all
170
171     atf_add_test_case query_one
172     atf_add_test_case query_one_terse
173     atf_add_test_case query_multiple
174     atf_add_test_case query_unknown
175     atf_add_test_case query_mixture
176
177     atf_add_test_case override_env
178 }
179
180 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4