config_test.sh revision 240116
1240116Smarcel#
2240116Smarcel# Automated Testing Framework (atf)
3240116Smarcel#
4240116Smarcel# Copyright (c) 2007 The NetBSD Foundation, Inc.
5240116Smarcel# All rights reserved.
6240116Smarcel#
7240116Smarcel# Redistribution and use in source and binary forms, with or without
8240116Smarcel# modification, are permitted provided that the following conditions
9240116Smarcel# are met:
10240116Smarcel# 1. Redistributions of source code must retain the above copyright
11240116Smarcel#    notice, this list of conditions and the following disclaimer.
12240116Smarcel# 2. Redistributions in binary form must reproduce the above copyright
13240116Smarcel#    notice, this list of conditions and the following disclaimer in the
14240116Smarcel#    documentation and/or other materials provided with the distribution.
15240116Smarcel#
16240116Smarcel# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17240116Smarcel# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18240116Smarcel# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19240116Smarcel# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20240116Smarcel# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21240116Smarcel# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22240116Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23240116Smarcel# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24240116Smarcel# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25240116Smarcel# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26240116Smarcel# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27240116Smarcel# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28240116Smarcel#
29240116Smarcel
30240116Smarcelatf_test_case has
31240116Smarcelhas_head()
32240116Smarcel{
33240116Smarcel    atf_set "descr" "Verifies that atf_config_has works"
34240116Smarcel}
35240116Smarcelhas_body()
36240116Smarcel{
37240116Smarcel    h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
38240116Smarcel
39240116Smarcel    atf_check -s eq:0 -o match:'foo not found' -e ignore -x \
40240116Smarcel              "TEST_VARIABLE=foo ${h} config_has"
41240116Smarcel
42240116Smarcel    atf_check -s eq:0 -o match:'foo found' -e ignore -x \
43240116Smarcel              "TEST_VARIABLE=foo ${h} -v foo=bar config_has"
44240116Smarcel
45240116Smarcel    echo "Checking for deprecated variables"
46240116Smarcel    atf_check -s eq:0 -o match:'workdir not found' -e ignore -x \
47240116Smarcel              "TEST_VARIABLE=workdir ${h} config_has"
48240116Smarcel}
49240116Smarcel
50240116Smarcelatf_test_case get
51240116Smarcelget_head()
52240116Smarcel{
53240116Smarcel    atf_set "descr" "Verifies that atf_config_get works"
54240116Smarcel}
55240116Smarcelget_body()
56240116Smarcel{
57240116Smarcel    h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
58240116Smarcel
59240116Smarcel    echo "Querying an undefined variable"
60240116Smarcel    ( atf_config_get "undefined" ) >out 2>err && \
61240116Smarcel        atf_fail "Getting an undefined variable succeeded"
62240116Smarcel    grep 'not find' err || \
63240116Smarcel        atf_fail "Getting an undefined variable did not report an error"
64240116Smarcel
65240116Smarcel    echo "Querying an undefined variable using a default value"
66240116Smarcel    v=$(atf_config_get "undefined" "the default value")
67240116Smarcel    [ "${v}" = "the default value" ] || \
68240116Smarcel        atf_fail "Default value does not work"
69240116Smarcel
70240116Smarcel    atf_check -s eq:0 -o match:'foo = bar' -e ignore -x \
71240116Smarcel              "TEST_VARIABLE=foo ${h} -v foo=bar config_get"
72240116Smarcel
73240116Smarcel    atf_check -s eq:0 -o match:'foo = baz' -e ignore -x \
74240116Smarcel              "TEST_VARIABLE=foo ${h} -v foo=baz config_get"
75240116Smarcel}
76240116Smarcel
77240116Smarcelatf_init_test_cases()
78240116Smarcel{
79240116Smarcel    atf_add_test_case has
80240116Smarcel    atf_add_test_case get
81240116Smarcel}
82240116Smarcel
83240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
84