2 # Automated Testing Framework (atf)
4 # Copyright (c) 2007 The NetBSD Foundation, Inc.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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.
47 atf_test_case list_all
50 atf_set
"descr" "Tests that at atf-config prints all expected" \
51 "variables, and not more"
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
63 atf_test_case query_one
66 atf_set
"descr" "Tests that querying a single variable works"
70 for v
in ${all_vars}; do
71 atf_check
-s eq
:0 -o save
:stdout
-o match
:"${v}" -e empty \
73 atf_check
-s eq
:0 -o empty
-e empty \
74 test "$(wc -l stdout | awk '{ print $1 }')" = 1
78 atf_test_case query_one_terse
79 query_one_terse_head
()
81 atf_set
"descr" "Tests that querying a single variable in terse mode" \
84 query_one_terse_body
()
86 for v
in ${all_vars}; do
87 atf_check
-s eq
:0 -o save
:stdout
-o match
:"${v}" -e empty \
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}"
97 atf_test_case query_multiple
100 atf_set
"descr" "Tests that querying multiple variables works"
102 query_multiple_body
()
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
110 atf_test_case query_unknown
113 atf_set
"descr" "Tests that querying an unknown variable delivers" \
118 atf_check
-s eq
:1 -o empty
-e match
:'Unknown variable.*non_existent' \
119 atf-config non_existent
122 atf_test_case query_mixture
125 atf_set
"descr" "Tests that querying a known and an unknown variable" \
126 "delivers the correct error"
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}"
138 atf_test_case override_env
141 atf_set
"descr" "Tests that build-time variables can be overriden" \
142 "through their corresponding environment variables"
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
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
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))"
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
167 atf_init_test_cases
()
169 atf_add_test_case list_all
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
177 atf_add_test_case override_env
180 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4