xref: /freebsd/contrib/kyua/cli/config_test.cpp (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
1*b0d29bc4SBrooks Davis // Copyright 2011 The Kyua Authors.
2*b0d29bc4SBrooks Davis // All rights reserved.
3*b0d29bc4SBrooks Davis //
4*b0d29bc4SBrooks Davis // Redistribution and use in source and binary forms, with or without
5*b0d29bc4SBrooks Davis // modification, are permitted provided that the following conditions are
6*b0d29bc4SBrooks Davis // met:
7*b0d29bc4SBrooks Davis //
8*b0d29bc4SBrooks Davis // * Redistributions of source code must retain the above copyright
9*b0d29bc4SBrooks Davis //   notice, this list of conditions and the following disclaimer.
10*b0d29bc4SBrooks Davis // * Redistributions in binary form must reproduce the above copyright
11*b0d29bc4SBrooks Davis //   notice, this list of conditions and the following disclaimer in the
12*b0d29bc4SBrooks Davis //   documentation and/or other materials provided with the distribution.
13*b0d29bc4SBrooks Davis // * Neither the name of Google Inc. nor the names of its contributors
14*b0d29bc4SBrooks Davis //   may be used to endorse or promote products derived from this software
15*b0d29bc4SBrooks Davis //   without specific prior written permission.
16*b0d29bc4SBrooks Davis //
17*b0d29bc4SBrooks Davis // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*b0d29bc4SBrooks Davis // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*b0d29bc4SBrooks Davis // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*b0d29bc4SBrooks Davis // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*b0d29bc4SBrooks Davis // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*b0d29bc4SBrooks Davis // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*b0d29bc4SBrooks Davis // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*b0d29bc4SBrooks Davis // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*b0d29bc4SBrooks Davis // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*b0d29bc4SBrooks Davis // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*b0d29bc4SBrooks Davis // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*b0d29bc4SBrooks Davis 
29*b0d29bc4SBrooks Davis #include "cli/config.hpp"
30*b0d29bc4SBrooks Davis 
31*b0d29bc4SBrooks Davis #include <atf-c++.hpp>
32*b0d29bc4SBrooks Davis 
33*b0d29bc4SBrooks Davis #include "engine/config.hpp"
34*b0d29bc4SBrooks Davis #include "engine/exceptions.hpp"
35*b0d29bc4SBrooks Davis #include "utils/cmdline/options.hpp"
36*b0d29bc4SBrooks Davis #include "utils/cmdline/parser.ipp"
37*b0d29bc4SBrooks Davis #include "utils/config/tree.ipp"
38*b0d29bc4SBrooks Davis #include "utils/env.hpp"
39*b0d29bc4SBrooks Davis #include "utils/format/macros.hpp"
40*b0d29bc4SBrooks Davis #include "utils/fs/operations.hpp"
41*b0d29bc4SBrooks Davis #include "utils/fs/path.hpp"
42*b0d29bc4SBrooks Davis 
43*b0d29bc4SBrooks Davis namespace cmdline = utils::cmdline;
44*b0d29bc4SBrooks Davis namespace config = utils::config;
45*b0d29bc4SBrooks Davis namespace fs = utils::fs;
46*b0d29bc4SBrooks Davis 
47*b0d29bc4SBrooks Davis 
48*b0d29bc4SBrooks Davis namespace {
49*b0d29bc4SBrooks Davis 
50*b0d29bc4SBrooks Davis 
51*b0d29bc4SBrooks Davis /// Creates a configuration file for testing purposes.
52*b0d29bc4SBrooks Davis ///
53*b0d29bc4SBrooks Davis /// To ensure that the loaded file is the one created by this function, use
54*b0d29bc4SBrooks Davis /// validate_mock_config().
55*b0d29bc4SBrooks Davis ///
56*b0d29bc4SBrooks Davis /// \param name The name of the configuration file to create.
57*b0d29bc4SBrooks Davis /// \param cookie The magic value to set in the configuration file, or NULL if a
58*b0d29bc4SBrooks Davis ///     broken configuration file is desired.
59*b0d29bc4SBrooks Davis static void
create_mock_config(const char * name,const char * cookie)60*b0d29bc4SBrooks Davis create_mock_config(const char* name, const char* cookie)
61*b0d29bc4SBrooks Davis {
62*b0d29bc4SBrooks Davis     if (cookie != NULL) {
63*b0d29bc4SBrooks Davis         atf::utils::create_file(
64*b0d29bc4SBrooks Davis             name,
65*b0d29bc4SBrooks Davis             F("syntax(2)\n"
66*b0d29bc4SBrooks Davis               "test_suites.suite.magic_value = '%s'\n") % cookie);
67*b0d29bc4SBrooks Davis     } else {
68*b0d29bc4SBrooks Davis         atf::utils::create_file(name, "syntax(200)\n");
69*b0d29bc4SBrooks Davis     }
70*b0d29bc4SBrooks Davis }
71*b0d29bc4SBrooks Davis 
72*b0d29bc4SBrooks Davis 
73*b0d29bc4SBrooks Davis /// Creates an invalid system configuration.
74*b0d29bc4SBrooks Davis ///
75*b0d29bc4SBrooks Davis /// \param cookie The magic value to set in the configuration file, or NULL if a
76*b0d29bc4SBrooks Davis ///     broken configuration file is desired.
77*b0d29bc4SBrooks Davis static void
mock_system_config(const char * cookie)78*b0d29bc4SBrooks Davis mock_system_config(const char* cookie)
79*b0d29bc4SBrooks Davis {
80*b0d29bc4SBrooks Davis     fs::mkdir(fs::path("system-dir"), 0755);
81*b0d29bc4SBrooks Davis     utils::setenv("KYUA_CONFDIR", (fs::current_path() / "system-dir").str());
82*b0d29bc4SBrooks Davis     create_mock_config("system-dir/kyua.conf", cookie);
83*b0d29bc4SBrooks Davis }
84*b0d29bc4SBrooks Davis 
85*b0d29bc4SBrooks Davis 
86*b0d29bc4SBrooks Davis /// Creates an invalid user configuration.
87*b0d29bc4SBrooks Davis ///
88*b0d29bc4SBrooks Davis /// \param cookie The magic value to set in the configuration file, or NULL if a
89*b0d29bc4SBrooks Davis ///     broken configuration file is desired.
90*b0d29bc4SBrooks Davis static void
mock_user_config(const char * cookie)91*b0d29bc4SBrooks Davis mock_user_config(const char* cookie)
92*b0d29bc4SBrooks Davis {
93*b0d29bc4SBrooks Davis     fs::mkdir(fs::path("user-dir"), 0755);
94*b0d29bc4SBrooks Davis     fs::mkdir(fs::path("user-dir/.kyua"), 0755);
95*b0d29bc4SBrooks Davis     utils::setenv("HOME", (fs::current_path() / "user-dir").str());
96*b0d29bc4SBrooks Davis     create_mock_config("user-dir/.kyua/kyua.conf", cookie);
97*b0d29bc4SBrooks Davis }
98*b0d29bc4SBrooks Davis 
99*b0d29bc4SBrooks Davis 
100*b0d29bc4SBrooks Davis /// Ensures that a loaded configuration was created with create_mock_config().
101*b0d29bc4SBrooks Davis ///
102*b0d29bc4SBrooks Davis /// \param user_config The configuration to validate.
103*b0d29bc4SBrooks Davis /// \param cookie The magic value to expect in the configuration file.
104*b0d29bc4SBrooks Davis static void
validate_mock_config(const config::tree & user_config,const char * cookie)105*b0d29bc4SBrooks Davis validate_mock_config(const config::tree& user_config, const char* cookie)
106*b0d29bc4SBrooks Davis {
107*b0d29bc4SBrooks Davis     const config::properties_map& properties = user_config.all_properties(
108*b0d29bc4SBrooks Davis         "test_suites.suite", true);
109*b0d29bc4SBrooks Davis     const config::properties_map::const_iterator iter =
110*b0d29bc4SBrooks Davis         properties.find("magic_value");
111*b0d29bc4SBrooks Davis     ATF_REQUIRE(iter != properties.end());
112*b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ(cookie, (*iter).second);
113*b0d29bc4SBrooks Davis }
114*b0d29bc4SBrooks Davis 
115*b0d29bc4SBrooks Davis 
116*b0d29bc4SBrooks Davis /// Ensures that two configuration trees are equal.
117*b0d29bc4SBrooks Davis ///
118*b0d29bc4SBrooks Davis /// \param exp_tree The expected configuration tree.
119*b0d29bc4SBrooks Davis /// \param actual_tree The configuration tree being validated against exp_tree.
120*b0d29bc4SBrooks Davis static void
require_eq(const config::tree & exp_tree,const config::tree & actual_tree)121*b0d29bc4SBrooks Davis require_eq(const config::tree& exp_tree, const config::tree& actual_tree)
122*b0d29bc4SBrooks Davis {
123*b0d29bc4SBrooks Davis     ATF_REQUIRE(exp_tree.all_properties() == actual_tree.all_properties());
124*b0d29bc4SBrooks Davis }
125*b0d29bc4SBrooks Davis 
126*b0d29bc4SBrooks Davis 
127*b0d29bc4SBrooks Davis }  // anonymous namespace
128*b0d29bc4SBrooks Davis 
129*b0d29bc4SBrooks Davis 
130*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__none);
ATF_TEST_CASE_BODY(load_config__none)131*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__none)
132*b0d29bc4SBrooks Davis {
133*b0d29bc4SBrooks Davis     utils::setenv("KYUA_CONFDIR", "/the/system/does/not/exist");
134*b0d29bc4SBrooks Davis     utils::setenv("HOME", "/the/user/does/not/exist");
135*b0d29bc4SBrooks Davis 
136*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
137*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
138*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
139*b0d29bc4SBrooks Davis 
140*b0d29bc4SBrooks Davis     require_eq(engine::default_config(),
141*b0d29bc4SBrooks Davis                cli::load_config(mock_cmdline, true));
142*b0d29bc4SBrooks Davis }
143*b0d29bc4SBrooks Davis 
144*b0d29bc4SBrooks Davis 
145*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__explicit__ok);
ATF_TEST_CASE_BODY(load_config__explicit__ok)146*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__explicit__ok)
147*b0d29bc4SBrooks Davis {
148*b0d29bc4SBrooks Davis     mock_system_config(NULL);
149*b0d29bc4SBrooks Davis     mock_user_config(NULL);
150*b0d29bc4SBrooks Davis 
151*b0d29bc4SBrooks Davis     create_mock_config("test-file", "hello");
152*b0d29bc4SBrooks Davis 
153*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
154*b0d29bc4SBrooks Davis     options["config"].push_back("test-file");
155*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
156*b0d29bc4SBrooks Davis 
157*b0d29bc4SBrooks Davis     const config::tree user_config = cli::load_config(mock_cmdline, true);
158*b0d29bc4SBrooks Davis     validate_mock_config(user_config, "hello");
159*b0d29bc4SBrooks Davis }
160*b0d29bc4SBrooks Davis 
161*b0d29bc4SBrooks Davis 
162*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__explicit__disable);
ATF_TEST_CASE_BODY(load_config__explicit__disable)163*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__explicit__disable)
164*b0d29bc4SBrooks Davis {
165*b0d29bc4SBrooks Davis     mock_system_config(NULL);
166*b0d29bc4SBrooks Davis     mock_user_config(NULL);
167*b0d29bc4SBrooks Davis 
168*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
169*b0d29bc4SBrooks Davis     options["config"].push_back("none");
170*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
171*b0d29bc4SBrooks Davis 
172*b0d29bc4SBrooks Davis     require_eq(engine::default_config(),
173*b0d29bc4SBrooks Davis                cli::load_config(mock_cmdline, true));
174*b0d29bc4SBrooks Davis }
175*b0d29bc4SBrooks Davis 
176*b0d29bc4SBrooks Davis 
177*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__explicit__fail);
ATF_TEST_CASE_BODY(load_config__explicit__fail)178*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__explicit__fail)
179*b0d29bc4SBrooks Davis {
180*b0d29bc4SBrooks Davis     mock_system_config("ok1");
181*b0d29bc4SBrooks Davis     mock_user_config("ok2");
182*b0d29bc4SBrooks Davis 
183*b0d29bc4SBrooks Davis     create_mock_config("test-file", NULL);
184*b0d29bc4SBrooks Davis 
185*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
186*b0d29bc4SBrooks Davis     options["config"].push_back("test-file");
187*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
188*b0d29bc4SBrooks Davis 
189*b0d29bc4SBrooks Davis     ATF_REQUIRE_THROW_RE(engine::error, "200",
190*b0d29bc4SBrooks Davis                          cli::load_config(mock_cmdline, true));
191*b0d29bc4SBrooks Davis 
192*b0d29bc4SBrooks Davis     const config::tree config = cli::load_config(mock_cmdline, false);
193*b0d29bc4SBrooks Davis     require_eq(engine::default_config(), config);
194*b0d29bc4SBrooks Davis }
195*b0d29bc4SBrooks Davis 
196*b0d29bc4SBrooks Davis 
197*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__user__ok);
ATF_TEST_CASE_BODY(load_config__user__ok)198*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__user__ok)
199*b0d29bc4SBrooks Davis {
200*b0d29bc4SBrooks Davis     mock_system_config(NULL);
201*b0d29bc4SBrooks Davis     mock_user_config("I am the user config");
202*b0d29bc4SBrooks Davis 
203*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
204*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
205*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
206*b0d29bc4SBrooks Davis 
207*b0d29bc4SBrooks Davis     const config::tree user_config = cli::load_config(mock_cmdline, true);
208*b0d29bc4SBrooks Davis     validate_mock_config(user_config, "I am the user config");
209*b0d29bc4SBrooks Davis }
210*b0d29bc4SBrooks Davis 
211*b0d29bc4SBrooks Davis 
212*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__user__fail);
ATF_TEST_CASE_BODY(load_config__user__fail)213*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__user__fail)
214*b0d29bc4SBrooks Davis {
215*b0d29bc4SBrooks Davis     mock_system_config("valid");
216*b0d29bc4SBrooks Davis     mock_user_config(NULL);
217*b0d29bc4SBrooks Davis 
218*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
219*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
220*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
221*b0d29bc4SBrooks Davis 
222*b0d29bc4SBrooks Davis     ATF_REQUIRE_THROW_RE(engine::error, "200",
223*b0d29bc4SBrooks Davis                          cli::load_config(mock_cmdline, true));
224*b0d29bc4SBrooks Davis 
225*b0d29bc4SBrooks Davis     const config::tree config = cli::load_config(mock_cmdline, false);
226*b0d29bc4SBrooks Davis     require_eq(engine::default_config(), config);
227*b0d29bc4SBrooks Davis }
228*b0d29bc4SBrooks Davis 
229*b0d29bc4SBrooks Davis 
230*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__user__bad_home);
ATF_TEST_CASE_BODY(load_config__user__bad_home)231*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__user__bad_home)
232*b0d29bc4SBrooks Davis {
233*b0d29bc4SBrooks Davis     mock_system_config("Fallback system config");
234*b0d29bc4SBrooks Davis     utils::setenv("HOME", "");
235*b0d29bc4SBrooks Davis 
236*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
237*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
238*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
239*b0d29bc4SBrooks Davis 
240*b0d29bc4SBrooks Davis     const config::tree user_config = cli::load_config(mock_cmdline, true);
241*b0d29bc4SBrooks Davis     validate_mock_config(user_config, "Fallback system config");
242*b0d29bc4SBrooks Davis }
243*b0d29bc4SBrooks Davis 
244*b0d29bc4SBrooks Davis 
245*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__system__ok);
ATF_TEST_CASE_BODY(load_config__system__ok)246*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__system__ok)
247*b0d29bc4SBrooks Davis {
248*b0d29bc4SBrooks Davis     mock_system_config("I am the system config");
249*b0d29bc4SBrooks Davis     utils::setenv("HOME", "/the/user/does/not/exist");
250*b0d29bc4SBrooks Davis 
251*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
252*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
253*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
254*b0d29bc4SBrooks Davis 
255*b0d29bc4SBrooks Davis     const config::tree user_config = cli::load_config(mock_cmdline, true);
256*b0d29bc4SBrooks Davis     validate_mock_config(user_config, "I am the system config");
257*b0d29bc4SBrooks Davis }
258*b0d29bc4SBrooks Davis 
259*b0d29bc4SBrooks Davis 
260*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__system__fail);
ATF_TEST_CASE_BODY(load_config__system__fail)261*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__system__fail)
262*b0d29bc4SBrooks Davis {
263*b0d29bc4SBrooks Davis     mock_system_config(NULL);
264*b0d29bc4SBrooks Davis     utils::setenv("HOME", "/the/user/does/not/exist");
265*b0d29bc4SBrooks Davis 
266*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
267*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
268*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
269*b0d29bc4SBrooks Davis 
270*b0d29bc4SBrooks Davis     ATF_REQUIRE_THROW_RE(engine::error, "200",
271*b0d29bc4SBrooks Davis                          cli::load_config(mock_cmdline, true));
272*b0d29bc4SBrooks Davis 
273*b0d29bc4SBrooks Davis     const config::tree config = cli::load_config(mock_cmdline, false);
274*b0d29bc4SBrooks Davis     require_eq(engine::default_config(), config);
275*b0d29bc4SBrooks Davis }
276*b0d29bc4SBrooks Davis 
277*b0d29bc4SBrooks Davis 
278*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__overrides__no);
ATF_TEST_CASE_BODY(load_config__overrides__no)279*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__overrides__no)
280*b0d29bc4SBrooks Davis {
281*b0d29bc4SBrooks Davis     utils::setenv("KYUA_CONFDIR", fs::current_path().str());
282*b0d29bc4SBrooks Davis 
283*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
284*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
285*b0d29bc4SBrooks Davis     options["variable"].push_back("architecture=1");
286*b0d29bc4SBrooks Davis     options["variable"].push_back("platform=2");
287*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
288*b0d29bc4SBrooks Davis 
289*b0d29bc4SBrooks Davis     const config::tree user_config = cli::load_config(mock_cmdline, true);
290*b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("1",
291*b0d29bc4SBrooks Davis                    user_config.lookup< config::string_node >("architecture"));
292*b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("2",
293*b0d29bc4SBrooks Davis                    user_config.lookup< config::string_node >("platform"));
294*b0d29bc4SBrooks Davis }
295*b0d29bc4SBrooks Davis 
296*b0d29bc4SBrooks Davis 
297*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__overrides__yes);
ATF_TEST_CASE_BODY(load_config__overrides__yes)298*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__overrides__yes)
299*b0d29bc4SBrooks Davis {
300*b0d29bc4SBrooks Davis     atf::utils::create_file(
301*b0d29bc4SBrooks Davis         "config",
302*b0d29bc4SBrooks Davis         "syntax(2)\n"
303*b0d29bc4SBrooks Davis         "architecture = 'do not see me'\n"
304*b0d29bc4SBrooks Davis         "platform = 'see me'\n");
305*b0d29bc4SBrooks Davis 
306*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
307*b0d29bc4SBrooks Davis     options["config"].push_back("config");
308*b0d29bc4SBrooks Davis     options["variable"].push_back("architecture=overriden");
309*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
310*b0d29bc4SBrooks Davis 
311*b0d29bc4SBrooks Davis     const config::tree user_config = cli::load_config(mock_cmdline, true);
312*b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("overriden",
313*b0d29bc4SBrooks Davis                    user_config.lookup< config::string_node >("architecture"));
314*b0d29bc4SBrooks Davis     ATF_REQUIRE_EQ("see me",
315*b0d29bc4SBrooks Davis                    user_config.lookup< config::string_node >("platform"));
316*b0d29bc4SBrooks Davis }
317*b0d29bc4SBrooks Davis 
318*b0d29bc4SBrooks Davis 
319*b0d29bc4SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(load_config__overrides__fail);
ATF_TEST_CASE_BODY(load_config__overrides__fail)320*b0d29bc4SBrooks Davis ATF_TEST_CASE_BODY(load_config__overrides__fail)
321*b0d29bc4SBrooks Davis {
322*b0d29bc4SBrooks Davis     utils::setenv("KYUA_CONFDIR", fs::current_path().str());
323*b0d29bc4SBrooks Davis 
324*b0d29bc4SBrooks Davis     std::map< std::string, std::vector< std::string > > options;
325*b0d29bc4SBrooks Davis     options["config"].push_back(cli::config_option.default_value());
326*b0d29bc4SBrooks Davis     options["variable"].push_back(".a=d");
327*b0d29bc4SBrooks Davis     const cmdline::parsed_cmdline mock_cmdline(options, cmdline::args_vector());
328*b0d29bc4SBrooks Davis 
329*b0d29bc4SBrooks Davis     ATF_REQUIRE_THROW_RE(engine::error, "Empty component in key.*'\\.a'",
330*b0d29bc4SBrooks Davis                          cli::load_config(mock_cmdline, true));
331*b0d29bc4SBrooks Davis 
332*b0d29bc4SBrooks Davis     const config::tree config = cli::load_config(mock_cmdline, false);
333*b0d29bc4SBrooks Davis     require_eq(engine::default_config(), config);
334*b0d29bc4SBrooks Davis }
335*b0d29bc4SBrooks Davis 
336*b0d29bc4SBrooks Davis 
ATF_INIT_TEST_CASES(tcs)337*b0d29bc4SBrooks Davis ATF_INIT_TEST_CASES(tcs)
338*b0d29bc4SBrooks Davis {
339*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__none);
340*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__explicit__ok);
341*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__explicit__disable);
342*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__explicit__fail);
343*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__user__ok);
344*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__user__fail);
345*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__user__bad_home);
346*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__system__ok);
347*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__system__fail);
348*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__overrides__no);
349*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__overrides__yes);
350*b0d29bc4SBrooks Davis     ATF_ADD_TEST_CASE(tcs, load_config__overrides__fail);
351*b0d29bc4SBrooks Davis }
352