xref: /minix3/external/bsd/kyua-cli/dist/engine/test_program_test.cpp (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
111be35a1SLionel Sambuc // Copyright 2010 Google Inc.
211be35a1SLionel Sambuc // All rights reserved.
311be35a1SLionel Sambuc //
411be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
511be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
611be35a1SLionel Sambuc // met:
711be35a1SLionel Sambuc //
811be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
911be35a1SLionel Sambuc //   notice, this list of conditions and the following disclaimer.
1011be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
1111be35a1SLionel Sambuc //   notice, this list of conditions and the following disclaimer in the
1211be35a1SLionel Sambuc //   documentation and/or other materials provided with the distribution.
1311be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
1411be35a1SLionel Sambuc //   may be used to endorse or promote products derived from this software
1511be35a1SLionel Sambuc //   without specific prior written permission.
1611be35a1SLionel Sambuc //
1711be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1811be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1911be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2011be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2111be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2211be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2311be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2411be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2511be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2611be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2711be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc 
2911be35a1SLionel Sambuc #include "engine/test_program.hpp"
3011be35a1SLionel Sambuc 
31*84d9c625SLionel Sambuc extern "C" {
32*84d9c625SLionel Sambuc #include <sys/stat.h>
33*84d9c625SLionel Sambuc 
34*84d9c625SLionel Sambuc #include <signal.h>
35*84d9c625SLionel Sambuc }
36*84d9c625SLionel Sambuc 
3711be35a1SLionel Sambuc #include <sstream>
3811be35a1SLionel Sambuc 
3911be35a1SLionel Sambuc #include <atf-c++.hpp>
4011be35a1SLionel Sambuc 
4111be35a1SLionel Sambuc #include "engine/exceptions.hpp"
42*84d9c625SLionel Sambuc #include "engine/test_result.hpp"
43*84d9c625SLionel Sambuc #include "utils/env.hpp"
44*84d9c625SLionel Sambuc #include "utils/format/macros.hpp"
4511be35a1SLionel Sambuc #include "utils/fs/operations.hpp"
4611be35a1SLionel Sambuc #include "utils/fs/path.hpp"
47*84d9c625SLionel Sambuc #include "utils/optional.ipp"
4811be35a1SLionel Sambuc 
4911be35a1SLionel Sambuc namespace fs = utils::fs;
5011be35a1SLionel Sambuc 
5111be35a1SLionel Sambuc 
52*84d9c625SLionel Sambuc namespace {
53*84d9c625SLionel Sambuc 
54*84d9c625SLionel Sambuc 
55*84d9c625SLionel Sambuc /// Creates a mock tester that receives a signal.
56*84d9c625SLionel Sambuc ///
57*84d9c625SLionel Sambuc /// \param term_sig Signal to deliver to the tester.  If the tester does not
58*84d9c625SLionel Sambuc ///     exit due to this reason, it exits with an arbitrary non-zero code.
59*84d9c625SLionel Sambuc static void
create_mock_tester_signal(const int term_sig)60*84d9c625SLionel Sambuc create_mock_tester_signal(const int term_sig)
61*84d9c625SLionel Sambuc {
62*84d9c625SLionel Sambuc     const std::string tester_name = "kyua-mock-tester";
63*84d9c625SLionel Sambuc 
64*84d9c625SLionel Sambuc     atf::utils::create_file(
65*84d9c625SLionel Sambuc         tester_name,
66*84d9c625SLionel Sambuc         F("#! /bin/sh\n"
67*84d9c625SLionel Sambuc           "kill -%s $$\n"
68*84d9c625SLionel Sambuc           "exit 0\n") % term_sig);
69*84d9c625SLionel Sambuc     ATF_REQUIRE(::chmod(tester_name.c_str(), 0755) != -1);
70*84d9c625SLionel Sambuc 
71*84d9c625SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", fs::current_path().str());
72*84d9c625SLionel Sambuc }
73*84d9c625SLionel Sambuc 
74*84d9c625SLionel Sambuc 
75*84d9c625SLionel Sambuc }  // anonymous namespace
76*84d9c625SLionel Sambuc 
77*84d9c625SLionel Sambuc 
7811be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(ctor_and_getters);
ATF_TEST_CASE_BODY(ctor_and_getters)7911be35a1SLionel Sambuc ATF_TEST_CASE_BODY(ctor_and_getters)
8011be35a1SLionel Sambuc {
8111be35a1SLionel Sambuc     const engine::metadata md = engine::metadata_builder()
8211be35a1SLionel Sambuc         .add_custom("foo", "bar")
8311be35a1SLionel Sambuc         .build();
8411be35a1SLionel Sambuc     const engine::test_program test_program(
8511be35a1SLionel Sambuc         "mock", fs::path("binary"), fs::path("root"), "suite-name", md);
8611be35a1SLionel Sambuc     ATF_REQUIRE_EQ("mock", test_program.interface_name());
8711be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("binary"), test_program.relative_path());
8811be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::current_path() / "root/binary",
8911be35a1SLionel Sambuc                    test_program.absolute_path());
9011be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("root"), test_program.root());
9111be35a1SLionel Sambuc     ATF_REQUIRE_EQ("suite-name", test_program.test_suite_name());
9211be35a1SLionel Sambuc     ATF_REQUIRE_EQ(md, test_program.get_metadata());
9311be35a1SLionel Sambuc }
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc 
9611be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(find__ok);
ATF_TEST_CASE_BODY(find__ok)9711be35a1SLionel Sambuc ATF_TEST_CASE_BODY(find__ok)
9811be35a1SLionel Sambuc {
9911be35a1SLionel Sambuc     const engine::test_program test_program(
10011be35a1SLionel Sambuc         "plain", fs::path("non-existent"), fs::path("."), "suite-name",
10111be35a1SLionel Sambuc         engine::metadata_builder().build());
10211be35a1SLionel Sambuc     const engine::test_case_ptr test_case = test_program.find("main");
10311be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("non-existent"),
10411be35a1SLionel Sambuc                    test_case->container_test_program().relative_path());
10511be35a1SLionel Sambuc     ATF_REQUIRE_EQ("main", test_case->name());
10611be35a1SLionel Sambuc }
10711be35a1SLionel Sambuc 
10811be35a1SLionel Sambuc 
10911be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(find__missing);
ATF_TEST_CASE_BODY(find__missing)11011be35a1SLionel Sambuc ATF_TEST_CASE_BODY(find__missing)
11111be35a1SLionel Sambuc {
11211be35a1SLionel Sambuc     const engine::test_program test_program(
11311be35a1SLionel Sambuc         "plain", fs::path("non-existent"), fs::path("."), "suite-name",
11411be35a1SLionel Sambuc         engine::metadata_builder().build());
11511be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(engine::not_found_error,
11611be35a1SLionel Sambuc                          "case.*abc.*program.*non-existent",
11711be35a1SLionel Sambuc                          test_program.find("abc"));
11811be35a1SLionel Sambuc }
11911be35a1SLionel Sambuc 
12011be35a1SLionel Sambuc 
12111be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(test_cases__get);
ATF_TEST_CASE_BODY(test_cases__get)12211be35a1SLionel Sambuc ATF_TEST_CASE_BODY(test_cases__get)
12311be35a1SLionel Sambuc {
12411be35a1SLionel Sambuc     const engine::test_program test_program(
12511be35a1SLionel Sambuc         "plain", fs::path("non-existent"), fs::path("."), "suite-name",
12611be35a1SLionel Sambuc         engine::metadata_builder().build());
12711be35a1SLionel Sambuc     const engine::test_cases_vector& test_cases = test_program.test_cases();
12811be35a1SLionel Sambuc     ATF_REQUIRE_EQ(1, test_cases.size());
12911be35a1SLionel Sambuc     ATF_REQUIRE_EQ(fs::path("non-existent"),
13011be35a1SLionel Sambuc                    test_cases[0]->container_test_program().relative_path());
13111be35a1SLionel Sambuc     ATF_REQUIRE_EQ("main", test_cases[0]->name());
13211be35a1SLionel Sambuc }
13311be35a1SLionel Sambuc 
13411be35a1SLionel Sambuc 
13511be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(test_cases__some);
ATF_TEST_CASE_BODY(test_cases__some)13611be35a1SLionel Sambuc ATF_TEST_CASE_BODY(test_cases__some)
13711be35a1SLionel Sambuc {
13811be35a1SLionel Sambuc     engine::test_program test_program(
13911be35a1SLionel Sambuc         "plain", fs::path("non-existent"), fs::path("."), "suite-name",
14011be35a1SLionel Sambuc         engine::metadata_builder().build());
14111be35a1SLionel Sambuc 
14211be35a1SLionel Sambuc     engine::test_cases_vector exp_test_cases;
14311be35a1SLionel Sambuc     const engine::test_case test_case("plain", test_program, "main",
14411be35a1SLionel Sambuc                                       engine::metadata_builder().build());
14511be35a1SLionel Sambuc     exp_test_cases.push_back(engine::test_case_ptr(
14611be35a1SLionel Sambuc         new engine::test_case(test_case)));
14711be35a1SLionel Sambuc     test_program.set_test_cases(exp_test_cases);
14811be35a1SLionel Sambuc 
14911be35a1SLionel Sambuc     ATF_REQUIRE_EQ(exp_test_cases, test_program.test_cases());
15011be35a1SLionel Sambuc }
15111be35a1SLionel Sambuc 
15211be35a1SLionel Sambuc 
153*84d9c625SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(test_cases__tester_fails);
ATF_TEST_CASE_BODY(test_cases__tester_fails)154*84d9c625SLionel Sambuc ATF_TEST_CASE_BODY(test_cases__tester_fails)
155*84d9c625SLionel Sambuc {
156*84d9c625SLionel Sambuc     engine::test_program test_program(
157*84d9c625SLionel Sambuc         "mock", fs::path("non-existent"), fs::path("."), "suite-name",
158*84d9c625SLionel Sambuc         engine::metadata_builder().build());
159*84d9c625SLionel Sambuc     create_mock_tester_signal(SIGSEGV);
160*84d9c625SLionel Sambuc 
161*84d9c625SLionel Sambuc     const engine::test_cases_vector& test_cases = test_program.test_cases();
162*84d9c625SLionel Sambuc     ATF_REQUIRE_EQ(1, test_cases.size());
163*84d9c625SLionel Sambuc 
164*84d9c625SLionel Sambuc     const engine::test_case_ptr& test_case = test_cases[0];
165*84d9c625SLionel Sambuc     ATF_REQUIRE_EQ("__test_cases_list__", test_case->name());
166*84d9c625SLionel Sambuc 
167*84d9c625SLionel Sambuc     ATF_REQUIRE(test_case->fake_result());
168*84d9c625SLionel Sambuc     const engine::test_result result = test_case->fake_result().get();
169*84d9c625SLionel Sambuc     ATF_REQUIRE(engine::test_result::broken == result.type());
170*84d9c625SLionel Sambuc     ATF_REQUIRE_MATCH("Tester did not exit cleanly", result.reason());
171*84d9c625SLionel Sambuc }
172*84d9c625SLionel Sambuc 
173*84d9c625SLionel Sambuc 
17411be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(operators_eq_and_ne__copy);
ATF_TEST_CASE_BODY(operators_eq_and_ne__copy)17511be35a1SLionel Sambuc ATF_TEST_CASE_BODY(operators_eq_and_ne__copy)
17611be35a1SLionel Sambuc {
17711be35a1SLionel Sambuc     const engine::test_program tp1(
17811be35a1SLionel Sambuc         "plain", fs::path("non-existent"), fs::path("."), "suite-name",
17911be35a1SLionel Sambuc         engine::metadata_builder().build());
18011be35a1SLionel Sambuc     const engine::test_program tp2 = tp1;
18111be35a1SLionel Sambuc     ATF_REQUIRE(  tp1 == tp2);
18211be35a1SLionel Sambuc     ATF_REQUIRE(!(tp1 != tp2));
18311be35a1SLionel Sambuc }
18411be35a1SLionel Sambuc 
18511be35a1SLionel Sambuc 
18611be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(operators_eq_and_ne__not_copy);
ATF_TEST_CASE_BODY(operators_eq_and_ne__not_copy)18711be35a1SLionel Sambuc ATF_TEST_CASE_BODY(operators_eq_and_ne__not_copy)
18811be35a1SLionel Sambuc {
18911be35a1SLionel Sambuc     const std::string base_interface("plain");
19011be35a1SLionel Sambuc     const fs::path base_relative_path("the/test/program");
19111be35a1SLionel Sambuc     const fs::path base_root("/the/root");
19211be35a1SLionel Sambuc     const std::string base_test_suite("suite-name");
19311be35a1SLionel Sambuc     const engine::metadata base_metadata = engine::metadata_builder()
19411be35a1SLionel Sambuc         .add_custom("X-foo", "bar")
19511be35a1SLionel Sambuc         .build();
19611be35a1SLionel Sambuc 
19711be35a1SLionel Sambuc     engine::test_program base_tp(
19811be35a1SLionel Sambuc         base_interface, base_relative_path, base_root, base_test_suite,
19911be35a1SLionel Sambuc         base_metadata);
20011be35a1SLionel Sambuc 
20111be35a1SLionel Sambuc     engine::test_cases_vector base_tcs;
20211be35a1SLionel Sambuc     {
20311be35a1SLionel Sambuc         const engine::test_case tc1("plain", base_tp, "main",
20411be35a1SLionel Sambuc                                     engine::metadata_builder().build());
20511be35a1SLionel Sambuc         base_tcs.push_back(engine::test_case_ptr(new engine::test_case(tc1)));
20611be35a1SLionel Sambuc     }
20711be35a1SLionel Sambuc     base_tp.set_test_cases(base_tcs);
20811be35a1SLionel Sambuc 
20911be35a1SLionel Sambuc     // Construct with all same values.
21011be35a1SLionel Sambuc     {
21111be35a1SLionel Sambuc         engine::test_program other_tp(
21211be35a1SLionel Sambuc             base_interface, base_relative_path, base_root, base_test_suite,
21311be35a1SLionel Sambuc             base_metadata);
21411be35a1SLionel Sambuc 
21511be35a1SLionel Sambuc         engine::test_cases_vector other_tcs;
21611be35a1SLionel Sambuc         {
21711be35a1SLionel Sambuc             const engine::test_case tc1("plain", other_tp, "main",
21811be35a1SLionel Sambuc                                         engine::metadata_builder().build());
21911be35a1SLionel Sambuc             other_tcs.push_back(engine::test_case_ptr(
22011be35a1SLionel Sambuc                 new engine::test_case(tc1)));
22111be35a1SLionel Sambuc         }
22211be35a1SLionel Sambuc         other_tp.set_test_cases(other_tcs);
22311be35a1SLionel Sambuc 
22411be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp == other_tp);
22511be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp != other_tp));
22611be35a1SLionel Sambuc     }
22711be35a1SLionel Sambuc 
22811be35a1SLionel Sambuc     // Different interface.
22911be35a1SLionel Sambuc     {
23011be35a1SLionel Sambuc         engine::test_program other_tp(
23111be35a1SLionel Sambuc             "atf", base_relative_path, base_root, base_test_suite,
23211be35a1SLionel Sambuc             base_metadata);
23311be35a1SLionel Sambuc         other_tp.set_test_cases(base_tcs);
23411be35a1SLionel Sambuc 
23511be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp == other_tp));
23611be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp != other_tp);
23711be35a1SLionel Sambuc     }
23811be35a1SLionel Sambuc 
23911be35a1SLionel Sambuc     // Different relative path.
24011be35a1SLionel Sambuc     {
24111be35a1SLionel Sambuc         engine::test_program other_tp(
24211be35a1SLionel Sambuc             base_interface, fs::path("a/b/c"), base_root, base_test_suite,
24311be35a1SLionel Sambuc             base_metadata);
24411be35a1SLionel Sambuc         other_tp.set_test_cases(base_tcs);
24511be35a1SLionel Sambuc 
24611be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp == other_tp));
24711be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp != other_tp);
24811be35a1SLionel Sambuc     }
24911be35a1SLionel Sambuc 
25011be35a1SLionel Sambuc     // Different root.
25111be35a1SLionel Sambuc     {
25211be35a1SLionel Sambuc         engine::test_program other_tp(
25311be35a1SLionel Sambuc             base_interface, base_relative_path, fs::path("."), base_test_suite,
25411be35a1SLionel Sambuc             base_metadata);
25511be35a1SLionel Sambuc         other_tp.set_test_cases(base_tcs);
25611be35a1SLionel Sambuc 
25711be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp == other_tp));
25811be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp != other_tp);
25911be35a1SLionel Sambuc     }
26011be35a1SLionel Sambuc 
26111be35a1SLionel Sambuc     // Different test suite.
26211be35a1SLionel Sambuc     {
26311be35a1SLionel Sambuc         engine::test_program other_tp(
26411be35a1SLionel Sambuc             base_interface, base_relative_path, base_root, "different-suite",
26511be35a1SLionel Sambuc             base_metadata);
26611be35a1SLionel Sambuc         other_tp.set_test_cases(base_tcs);
26711be35a1SLionel Sambuc 
26811be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp == other_tp));
26911be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp != other_tp);
27011be35a1SLionel Sambuc     }
27111be35a1SLionel Sambuc 
27211be35a1SLionel Sambuc     // Different metadata.
27311be35a1SLionel Sambuc     {
27411be35a1SLionel Sambuc         engine::test_program other_tp(
27511be35a1SLionel Sambuc             base_interface, base_relative_path, base_root, base_test_suite,
27611be35a1SLionel Sambuc             engine::metadata_builder().build());
27711be35a1SLionel Sambuc         other_tp.set_test_cases(base_tcs);
27811be35a1SLionel Sambuc 
27911be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp == other_tp));
28011be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp != other_tp);
28111be35a1SLionel Sambuc     }
28211be35a1SLionel Sambuc 
28311be35a1SLionel Sambuc     // Different test cases.
28411be35a1SLionel Sambuc     {
28511be35a1SLionel Sambuc         engine::test_program other_tp(
28611be35a1SLionel Sambuc             base_interface, base_relative_path, base_root, base_test_suite,
28711be35a1SLionel Sambuc             base_metadata);
28811be35a1SLionel Sambuc 
28911be35a1SLionel Sambuc         engine::test_cases_vector other_tcs;
29011be35a1SLionel Sambuc         {
29111be35a1SLionel Sambuc             const engine::test_case tc1("atf", base_tp, "foo",
29211be35a1SLionel Sambuc                                         engine::metadata_builder().build());
29311be35a1SLionel Sambuc             other_tcs.push_back(engine::test_case_ptr(
29411be35a1SLionel Sambuc                                     new engine::test_case(tc1)));
29511be35a1SLionel Sambuc         }
29611be35a1SLionel Sambuc         other_tp.set_test_cases(other_tcs);
29711be35a1SLionel Sambuc 
29811be35a1SLionel Sambuc         ATF_REQUIRE(!(base_tp == other_tp));
29911be35a1SLionel Sambuc         ATF_REQUIRE(  base_tp != other_tp);
30011be35a1SLionel Sambuc     }
30111be35a1SLionel Sambuc }
30211be35a1SLionel Sambuc 
30311be35a1SLionel Sambuc 
30411be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(output__no_test_cases);
ATF_TEST_CASE_BODY(output__no_test_cases)30511be35a1SLionel Sambuc ATF_TEST_CASE_BODY(output__no_test_cases)
30611be35a1SLionel Sambuc {
30711be35a1SLionel Sambuc     engine::test_program tp(
30811be35a1SLionel Sambuc         "plain", fs::path("binary/path"), fs::path("/the/root"), "suite-name",
30911be35a1SLionel Sambuc         engine::metadata_builder().add_allowed_architecture("a").build());
31011be35a1SLionel Sambuc     tp.set_test_cases(engine::test_cases_vector());
31111be35a1SLionel Sambuc 
31211be35a1SLionel Sambuc     std::ostringstream str;
31311be35a1SLionel Sambuc     str << tp;
31411be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
31511be35a1SLionel Sambuc         "test_program{interface='plain', binary='binary/path', "
31611be35a1SLionel Sambuc         "root='/the/root', test_suite='suite-name', "
31711be35a1SLionel Sambuc         "metadata=metadata{allowed_architectures='a', allowed_platforms='', "
31811be35a1SLionel Sambuc         "description='', has_cleanup='false', "
31911be35a1SLionel Sambuc         "required_configs='', required_files='', required_memory='0', "
32011be35a1SLionel Sambuc         "required_programs='', required_user='', timeout='300'}, "
32111be35a1SLionel Sambuc         "test_cases=[]}",
32211be35a1SLionel Sambuc         str.str());
32311be35a1SLionel Sambuc }
32411be35a1SLionel Sambuc 
32511be35a1SLionel Sambuc 
32611be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(output__some_test_cases);
ATF_TEST_CASE_BODY(output__some_test_cases)32711be35a1SLionel Sambuc ATF_TEST_CASE_BODY(output__some_test_cases)
32811be35a1SLionel Sambuc {
32911be35a1SLionel Sambuc     engine::test_program tp(
33011be35a1SLionel Sambuc         "plain", fs::path("binary/path"), fs::path("/the/root"), "suite-name",
33111be35a1SLionel Sambuc         engine::metadata_builder().add_allowed_architecture("a").build());
33211be35a1SLionel Sambuc 
33311be35a1SLionel Sambuc     const engine::test_case_ptr tc1(new engine::test_case(
33411be35a1SLionel Sambuc         "plain", tp, "the-name", engine::metadata_builder()
33511be35a1SLionel Sambuc         .add_allowed_platform("foo").add_custom("X-bar", "baz").build()));
33611be35a1SLionel Sambuc     const engine::test_case_ptr tc2(new engine::test_case(
33711be35a1SLionel Sambuc         "plain", tp, "another-name", engine::metadata_builder().build()));
33811be35a1SLionel Sambuc     engine::test_cases_vector tcs;
33911be35a1SLionel Sambuc     tcs.push_back(tc1);
34011be35a1SLionel Sambuc     tcs.push_back(tc2);
34111be35a1SLionel Sambuc     tp.set_test_cases(tcs);
34211be35a1SLionel Sambuc 
34311be35a1SLionel Sambuc     std::ostringstream str;
34411be35a1SLionel Sambuc     str << tp;
34511be35a1SLionel Sambuc     ATF_REQUIRE_EQ(
34611be35a1SLionel Sambuc         "test_program{interface='plain', binary='binary/path', "
34711be35a1SLionel Sambuc         "root='/the/root', test_suite='suite-name', "
34811be35a1SLionel Sambuc         "metadata=metadata{allowed_architectures='a', allowed_platforms='', "
34911be35a1SLionel Sambuc         "description='', has_cleanup='false', "
35011be35a1SLionel Sambuc         "required_configs='', required_files='', required_memory='0', "
35111be35a1SLionel Sambuc         "required_programs='', required_user='', timeout='300'}, "
35211be35a1SLionel Sambuc         "test_cases=["
35311be35a1SLionel Sambuc         "test_case{interface='plain', name='the-name', "
35411be35a1SLionel Sambuc         "metadata=metadata{allowed_architectures='', allowed_platforms='foo', "
35511be35a1SLionel Sambuc         "custom.X-bar='baz', description='', has_cleanup='false', "
35611be35a1SLionel Sambuc         "required_configs='', required_files='', required_memory='0', "
35711be35a1SLionel Sambuc         "required_programs='', required_user='', timeout='300'}}, "
35811be35a1SLionel Sambuc         "test_case{interface='plain', name='another-name', "
35911be35a1SLionel Sambuc         "metadata=metadata{allowed_architectures='', allowed_platforms='', "
36011be35a1SLionel Sambuc         "description='', has_cleanup='false', "
36111be35a1SLionel Sambuc         "required_configs='', required_files='', required_memory='0', "
36211be35a1SLionel Sambuc         "required_programs='', required_user='', timeout='300'}}]}",
36311be35a1SLionel Sambuc         str.str());
36411be35a1SLionel Sambuc }
36511be35a1SLionel Sambuc 
36611be35a1SLionel Sambuc 
ATF_INIT_TEST_CASES(tcs)36711be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
36811be35a1SLionel Sambuc {
36911be35a1SLionel Sambuc     // TODO(jmmv): These tests have ceased to be realistic with the move to
37011be35a1SLionel Sambuc     // TestersDesign.  We probably should have some (few!) integration tests for
37111be35a1SLionel Sambuc     // the various known testers... or, alternatively, provide a mock tester to
37211be35a1SLionel Sambuc     // run our tests with.
37311be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, ctor_and_getters);
37411be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, find__ok);
37511be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, find__missing);
37611be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, test_cases__get);
37711be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, test_cases__some);
378*84d9c625SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, test_cases__tester_fails);
37911be35a1SLionel Sambuc 
38011be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, operators_eq_and_ne__copy);
38111be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, operators_eq_and_ne__not_copy);
38211be35a1SLionel Sambuc 
38311be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, output__no_test_cases);
38411be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, output__some_test_cases);
38511be35a1SLionel Sambuc }
386