xref: /minix3/external/bsd/atf/dist/tools/atf-config_test.sh (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc#
2*0a6a1f1dSLionel Sambuc# Automated Testing Framework (atf)
3*0a6a1f1dSLionel Sambuc#
4*0a6a1f1dSLionel Sambuc# Copyright (c) 2007 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc# All rights reserved.
6*0a6a1f1dSLionel Sambuc#
7*0a6a1f1dSLionel Sambuc# Redistribution and use in source and binary forms, with or without
8*0a6a1f1dSLionel Sambuc# modification, are permitted provided that the following conditions
9*0a6a1f1dSLionel Sambuc# are met:
10*0a6a1f1dSLionel Sambuc# 1. Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc#    notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc#    documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc#
16*0a6a1f1dSLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*0a6a1f1dSLionel Sambuc# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*0a6a1f1dSLionel Sambuc# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*0a6a1f1dSLionel Sambuc# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*0a6a1f1dSLionel Sambuc# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*0a6a1f1dSLionel Sambuc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*0a6a1f1dSLionel Sambuc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*0a6a1f1dSLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*0a6a1f1dSLionel Sambuc# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*0a6a1f1dSLionel Sambuc# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*0a6a1f1dSLionel Sambuc# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc#
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambucall_vars="atf_arch \
31*0a6a1f1dSLionel Sambuc          atf_build_cc \
32*0a6a1f1dSLionel Sambuc          atf_build_cflags \
33*0a6a1f1dSLionel Sambuc          atf_build_cpp \
34*0a6a1f1dSLionel Sambuc          atf_build_cppflags \
35*0a6a1f1dSLionel Sambuc          atf_build_cxx \
36*0a6a1f1dSLionel Sambuc          atf_build_cxxflags \
37*0a6a1f1dSLionel Sambuc          atf_confdir \
38*0a6a1f1dSLionel Sambuc          atf_includedir \
39*0a6a1f1dSLionel Sambuc          atf_libdir \
40*0a6a1f1dSLionel Sambuc          atf_libexecdir \
41*0a6a1f1dSLionel Sambuc          atf_machine \
42*0a6a1f1dSLionel Sambuc          atf_pkgdatadir \
43*0a6a1f1dSLionel Sambuc          atf_shell \
44*0a6a1f1dSLionel Sambuc          atf_workdir"
45*0a6a1f1dSLionel Sambucall_vars_no=15
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambucatf_test_case list_all
48*0a6a1f1dSLionel Sambuclist_all_head()
49*0a6a1f1dSLionel Sambuc{
50*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that at atf-config prints all expected" \
51*0a6a1f1dSLionel Sambuc                    "variables, and not more"
52*0a6a1f1dSLionel Sambuc}
53*0a6a1f1dSLionel Sambuclist_all_body()
54*0a6a1f1dSLionel Sambuc{
55*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o save:stdout -e empty atf-config
56*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o empty -e empty \
57*0a6a1f1dSLionel Sambuc              test "$(wc -l stdout | awk '{ print $1 }')" = "${all_vars_no}"
58*0a6a1f1dSLionel Sambuc    for v in ${all_vars}; do
59*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o ignore -e empty grep "${v}" stdout
60*0a6a1f1dSLionel Sambuc    done
61*0a6a1f1dSLionel Sambuc}
62*0a6a1f1dSLionel Sambuc
63*0a6a1f1dSLionel Sambucatf_test_case query_one
64*0a6a1f1dSLionel Sambucquery_one_head()
65*0a6a1f1dSLionel Sambuc{
66*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that querying a single variable works"
67*0a6a1f1dSLionel Sambuc}
68*0a6a1f1dSLionel Sambucquery_one_body()
69*0a6a1f1dSLionel Sambuc{
70*0a6a1f1dSLionel Sambuc    for v in ${all_vars}; do
71*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o save:stdout -o match:"${v}" -e empty \
72*0a6a1f1dSLionel Sambuc            atf-config "${v}"
73*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty \
74*0a6a1f1dSLionel Sambuc                  test "$(wc -l stdout | awk '{ print $1 }')" = 1
75*0a6a1f1dSLionel Sambuc    done
76*0a6a1f1dSLionel Sambuc}
77*0a6a1f1dSLionel Sambuc
78*0a6a1f1dSLionel Sambucatf_test_case query_one_terse
79*0a6a1f1dSLionel Sambucquery_one_terse_head()
80*0a6a1f1dSLionel Sambuc{
81*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that querying a single variable in terse mode" \
82*0a6a1f1dSLionel Sambuc                    "works"
83*0a6a1f1dSLionel Sambuc}
84*0a6a1f1dSLionel Sambucquery_one_terse_body()
85*0a6a1f1dSLionel Sambuc{
86*0a6a1f1dSLionel Sambuc    for v in ${all_vars}; do
87*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o save:stdout -o match:"${v}" -e empty \
88*0a6a1f1dSLionel Sambuc            atf-config "${v}"
89*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty \
90*0a6a1f1dSLionel Sambuc                  test "$(wc -l stdout | awk '{ print $1 }')" = 1
91*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o save:stdout -e empty cut -d ' ' -f 3- stdout
92*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty mv stdout expout
93*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o file:expout -e empty atf-config -t "${v}"
94*0a6a1f1dSLionel Sambuc    done
95*0a6a1f1dSLionel Sambuc}
96*0a6a1f1dSLionel Sambuc
97*0a6a1f1dSLionel Sambucatf_test_case query_multiple
98*0a6a1f1dSLionel Sambucquery_multiple_head()
99*0a6a1f1dSLionel Sambuc{
100*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that querying multiple variables works"
101*0a6a1f1dSLionel Sambuc}
102*0a6a1f1dSLionel Sambucquery_multiple_body()
103*0a6a1f1dSLionel Sambuc{
104*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o save:stdout -o match:'atf_libexecdir' \
105*0a6a1f1dSLionel Sambuc        -o match:'atf_shell' -e empty atf-config atf_libexecdir atf_shell
106*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o empty -e empty \
107*0a6a1f1dSLionel Sambuc              test "$(wc -l stdout | awk '{ print $1 }')" = 2
108*0a6a1f1dSLionel Sambuc}
109*0a6a1f1dSLionel Sambuc
110*0a6a1f1dSLionel Sambucatf_test_case query_unknown
111*0a6a1f1dSLionel Sambucquery_unknown_head()
112*0a6a1f1dSLionel Sambuc{
113*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that querying an unknown variable delivers" \
114*0a6a1f1dSLionel Sambuc                    "the correct error"
115*0a6a1f1dSLionel Sambuc}
116*0a6a1f1dSLionel Sambucquery_unknown_body()
117*0a6a1f1dSLionel Sambuc{
118*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \
119*0a6a1f1dSLionel Sambuc        atf-config non_existent
120*0a6a1f1dSLionel Sambuc}
121*0a6a1f1dSLionel Sambuc
122*0a6a1f1dSLionel Sambucatf_test_case query_mixture
123*0a6a1f1dSLionel Sambucquery_mixture_head()
124*0a6a1f1dSLionel Sambuc{
125*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that querying a known and an unknown variable" \
126*0a6a1f1dSLionel Sambuc                    "delivers the correct error"
127*0a6a1f1dSLionel Sambuc}
128*0a6a1f1dSLionel Sambucquery_mixture_body()
129*0a6a1f1dSLionel Sambuc{
130*0a6a1f1dSLionel Sambuc    for v in ${all_vars}; do
131*0a6a1f1dSLionel Sambuc        atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \
132*0a6a1f1dSLionel Sambuc                  atf-config "${v}" non_existent
133*0a6a1f1dSLionel Sambuc        atf_check -s eq:1 -o empty -e match:'Unknown variable.*non_existent' \
134*0a6a1f1dSLionel Sambuc                  atf-config non_existent "${v}"
135*0a6a1f1dSLionel Sambuc    done
136*0a6a1f1dSLionel Sambuc}
137*0a6a1f1dSLionel Sambuc
138*0a6a1f1dSLionel Sambucatf_test_case override_env
139*0a6a1f1dSLionel Sambucoverride_env_head()
140*0a6a1f1dSLionel Sambuc{
141*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that build-time variables can be overriden" \
142*0a6a1f1dSLionel Sambuc                    "through their corresponding environment variables"
143*0a6a1f1dSLionel Sambuc}
144*0a6a1f1dSLionel Sambucoverride_env_body()
145*0a6a1f1dSLionel Sambuc{
146*0a6a1f1dSLionel Sambuc    for v in ${all_vars}; do
147*0a6a1f1dSLionel Sambuc        V=$(echo ${v} | tr '[a-z]' '[A-Z]')
148*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o save:stdout -e empty -x "${V}=testval atf-config"
149*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty mv stdout all
150*0a6a1f1dSLionel Sambuc
151*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o save:stdout -e empty grep "^${v} : " all
152*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty mv stdout affected
153*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o save:stdout -e empty grep -v "^${v} : " all
154*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty mv stdout unaffected
155*0a6a1f1dSLionel Sambuc
156*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty \
157*0a6a1f1dSLionel Sambuc                  test "$(wc -l affected | awk '{ print $1 }')" = 1
158*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o empty -e empty \
159*0a6a1f1dSLionel Sambuc                  test "$(wc -l unaffected | awk '{ print $1 }')" = \
160*0a6a1f1dSLionel Sambuc                   "$((${all_vars_no} -1))"
161*0a6a1f1dSLionel Sambuc
162*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o ignore -e empty grep "^${v} : testval$" affected
163*0a6a1f1dSLionel Sambuc        atf_check -s eq:1 -o empty -e empty grep ' : testval$' unaffected
164*0a6a1f1dSLionel Sambuc    done
165*0a6a1f1dSLionel Sambuc}
166*0a6a1f1dSLionel Sambuc
167*0a6a1f1dSLionel Sambucatf_init_test_cases()
168*0a6a1f1dSLionel Sambuc{
169*0a6a1f1dSLionel Sambuc    atf_add_test_case list_all
170*0a6a1f1dSLionel Sambuc
171*0a6a1f1dSLionel Sambuc    atf_add_test_case query_one
172*0a6a1f1dSLionel Sambuc    atf_add_test_case query_one_terse
173*0a6a1f1dSLionel Sambuc    atf_add_test_case query_multiple
174*0a6a1f1dSLionel Sambuc    atf_add_test_case query_unknown
175*0a6a1f1dSLionel Sambuc    atf_add_test_case query_mixture
176*0a6a1f1dSLionel Sambuc
177*0a6a1f1dSLionel Sambuc    atf_add_test_case override_env
178*0a6a1f1dSLionel Sambuc}
179*0a6a1f1dSLionel Sambuc
180*0a6a1f1dSLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
181