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