1 // Copyright 2011 The Kyua Authors.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "cli/cmd_config.hpp"
33 #include <atf-c++.hpp>
35 #include "cli/common.ipp"
36 #include "engine/config.hpp"
37 #include "utils/cmdline/globals.hpp"
38 #include "utils/cmdline/parser.hpp"
39 #include "utils/cmdline/ui_mock.hpp"
40 #include "utils/config/tree.ipp"
41 #include "utils/optional.ipp"
43 namespace cmdline = utils::cmdline;
44 namespace config = utils::config;
46 using cli::cmd_config;
53 /// Instantiates a fake user configuration for testing purposes.
55 /// The user configuration is populated with a collection of test-suite
56 /// properties and some hardcoded values for the generic configuration options.
58 /// \return A new user configuration object.
62 config::tree user_config = engine::default_config();
63 user_config.set_string("architecture", "the-architecture");
64 user_config.set_string("parallelism", "128");
65 user_config.set_string("platform", "the-platform");
66 //user_config.set_string("unprivileged_user", "");
67 user_config.set_string("test_suites.foo.bar", "first");
68 user_config.set_string("test_suites.foo.baz", "second");
73 } // anonymous namespace
76 ATF_TEST_CASE_WITHOUT_HEAD(all);
77 ATF_TEST_CASE_BODY(all)
79 cmdline::args_vector args;
80 args.push_back("config");
84 ATF_REQUIRE_EQ(EXIT_SUCCESS, cmd.main(&ui, args, fake_config()));
86 ATF_REQUIRE_EQ(5, ui.out_log().size());
87 ATF_REQUIRE_EQ("architecture = the-architecture", ui.out_log()[0]);
88 ATF_REQUIRE_EQ("parallelism = 128", ui.out_log()[1]);
89 ATF_REQUIRE_EQ("platform = the-platform", ui.out_log()[2]);
90 ATF_REQUIRE_EQ("test_suites.foo.bar = first", ui.out_log()[3]);
91 ATF_REQUIRE_EQ("test_suites.foo.baz = second", ui.out_log()[4]);
92 ATF_REQUIRE(ui.err_log().empty());
96 ATF_TEST_CASE_WITHOUT_HEAD(some__ok);
97 ATF_TEST_CASE_BODY(some__ok)
99 cmdline::args_vector args;
100 args.push_back("config");
101 args.push_back("platform");
102 args.push_back("test_suites.foo.baz");
106 ATF_REQUIRE_EQ(EXIT_SUCCESS, cmd.main(&ui, args, fake_config()));
108 ATF_REQUIRE_EQ(2, ui.out_log().size());
109 ATF_REQUIRE_EQ("platform = the-platform", ui.out_log()[0]);
110 ATF_REQUIRE_EQ("test_suites.foo.baz = second", ui.out_log()[1]);
111 ATF_REQUIRE(ui.err_log().empty());
115 ATF_TEST_CASE_WITHOUT_HEAD(some__fail);
116 ATF_TEST_CASE_BODY(some__fail)
118 cmdline::args_vector args;
119 args.push_back("config");
120 args.push_back("platform");
121 args.push_back("unknown");
122 args.push_back("test_suites.foo.baz");
124 cmdline::init("progname");
128 ATF_REQUIRE_EQ(EXIT_FAILURE, cmd.main(&ui, args, fake_config()));
130 ATF_REQUIRE_EQ(2, ui.out_log().size());
131 ATF_REQUIRE_EQ("platform = the-platform", ui.out_log()[0]);
132 ATF_REQUIRE_EQ("test_suites.foo.baz = second", ui.out_log()[1]);
133 ATF_REQUIRE_EQ(1, ui.err_log().size());
134 ATF_REQUIRE(atf::utils::grep_string("unknown.*not defined",
139 ATF_INIT_TEST_CASES(tcs)
141 ATF_ADD_TEST_CASE(tcs, all);
142 ATF_ADD_TEST_CASE(tcs, some__ok);
143 ATF_ADD_TEST_CASE(tcs, some__fail);