xref: /minix3/external/bsd/kyua-cli/dist/engine/testers_test.cpp (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
111be35a1SLionel Sambuc // Copyright 2012 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/testers.hpp"
3011be35a1SLionel Sambuc 
3111be35a1SLionel Sambuc extern "C" {
3211be35a1SLionel Sambuc #include <sys/stat.h>
33*84d9c625SLionel Sambuc 
34*84d9c625SLionel Sambuc #include <signal.h>
3511be35a1SLionel Sambuc }
3611be35a1SLionel Sambuc 
3711be35a1SLionel Sambuc #include <cstdlib>
3811be35a1SLionel Sambuc 
3911be35a1SLionel Sambuc #include <atf-c++.hpp>
4011be35a1SLionel Sambuc 
4111be35a1SLionel Sambuc #include "engine/exceptions.hpp"
4211be35a1SLionel Sambuc #include "utils/datetime.hpp"
4311be35a1SLionel Sambuc #include "utils/env.hpp"
4411be35a1SLionel Sambuc #include "utils/format/macros.hpp"
4511be35a1SLionel Sambuc #include "utils/fs/path.hpp"
4611be35a1SLionel Sambuc #include "utils/fs/operations.hpp"
4711be35a1SLionel Sambuc #include "utils/optional.ipp"
4811be35a1SLionel Sambuc #include "utils/passwd.hpp"
4911be35a1SLionel Sambuc 
5011be35a1SLionel Sambuc namespace datetime = utils::datetime;
5111be35a1SLionel Sambuc namespace fs = utils::fs;
5211be35a1SLionel Sambuc namespace passwd = utils::passwd;
5311be35a1SLionel Sambuc 
5411be35a1SLionel Sambuc using utils::none;
5511be35a1SLionel Sambuc using utils::optional;
5611be35a1SLionel Sambuc 
5711be35a1SLionel Sambuc 
5811be35a1SLionel Sambuc namespace {
5911be35a1SLionel Sambuc 
6011be35a1SLionel Sambuc 
61*84d9c625SLionel Sambuc /// Creates a mock tester that exits cleanly.
6211be35a1SLionel Sambuc ///
6311be35a1SLionel Sambuc /// The interface accepted by the tester is 'mock'.  This tester outputs the
6411be35a1SLionel Sambuc /// arguments passed to it and then prints a message to both the stdout and the
6511be35a1SLionel Sambuc /// stderr.
6611be35a1SLionel Sambuc ///
6711be35a1SLionel Sambuc /// \param exit_status Code to exit with.
6811be35a1SLionel Sambuc static void
create_mock_tester_exit(const int exit_status)69*84d9c625SLionel Sambuc create_mock_tester_exit(const int exit_status)
7011be35a1SLionel Sambuc {
7111be35a1SLionel Sambuc     atf::utils::create_file(
7211be35a1SLionel Sambuc         "kyua-mock-tester",
7311be35a1SLionel Sambuc         F("#! /bin/sh\n"
7411be35a1SLionel Sambuc           "while [ ${#} -gt 0 ]; do\n"
7511be35a1SLionel Sambuc           "    echo \"Arg: ${1}\"\n"
7611be35a1SLionel Sambuc           "    shift\n"
7711be35a1SLionel Sambuc           "done\n"
7811be35a1SLionel Sambuc           "echo 'tester output'\n"
7911be35a1SLionel Sambuc           "echo 'tester error' 1>&2\n"
8011be35a1SLionel Sambuc           "exit %s\n") % exit_status);
8111be35a1SLionel Sambuc     ATF_REQUIRE(::chmod("kyua-mock-tester", 0755) != -1);
8211be35a1SLionel Sambuc 
8311be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", fs::current_path().str());
8411be35a1SLionel Sambuc }
8511be35a1SLionel Sambuc 
8611be35a1SLionel Sambuc 
87*84d9c625SLionel Sambuc /// Creates a mock tester that receives a signal.
88*84d9c625SLionel Sambuc ///
89*84d9c625SLionel Sambuc /// The interface accepted by the tester is 'mock'.  This tester outputs the
90*84d9c625SLionel Sambuc /// arguments passed to it and then prints a message to both the stdout and the
91*84d9c625SLionel Sambuc /// stderr.
92*84d9c625SLionel Sambuc ///
93*84d9c625SLionel Sambuc /// \param term_sig Signal to deliver to the tester.  If the tester does not
94*84d9c625SLionel Sambuc ///     exit due to this reason, it exits with an arbitrary non-zero code.
95*84d9c625SLionel Sambuc static void
create_mock_tester_signal(const int term_sig)96*84d9c625SLionel Sambuc create_mock_tester_signal(const int term_sig)
97*84d9c625SLionel Sambuc {
98*84d9c625SLionel Sambuc     atf::utils::create_file(
99*84d9c625SLionel Sambuc         "kyua-mock-tester",
100*84d9c625SLionel Sambuc         F("#! /bin/sh\n"
101*84d9c625SLionel Sambuc           "while [ ${#} -gt 0 ]; do\n"
102*84d9c625SLionel Sambuc           "    echo \"Arg: ${1}\"\n"
103*84d9c625SLionel Sambuc           "    shift\n"
104*84d9c625SLionel Sambuc           "done\n"
105*84d9c625SLionel Sambuc           "echo 'tester output'\n"
106*84d9c625SLionel Sambuc           "echo 'tester error' 1>&2\n"
107*84d9c625SLionel Sambuc           "kill -%s $$\n"
108*84d9c625SLionel Sambuc           "echo 'signal did not terminate the process\n"
109*84d9c625SLionel Sambuc           "exit 0\n") % term_sig);
110*84d9c625SLionel Sambuc     ATF_REQUIRE(::chmod("kyua-mock-tester", 0755) != -1);
111*84d9c625SLionel Sambuc 
112*84d9c625SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", fs::current_path().str());
113*84d9c625SLionel Sambuc }
114*84d9c625SLionel Sambuc 
115*84d9c625SLionel Sambuc 
11611be35a1SLionel Sambuc }  // anonymous namespace
11711be35a1SLionel Sambuc 
11811be35a1SLionel Sambuc 
11911be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__list__defaults);
ATF_TEST_CASE_BODY(tester__list__defaults)12011be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__list__defaults)
12111be35a1SLionel Sambuc {
122*84d9c625SLionel Sambuc     create_mock_tester_exit(EXIT_SUCCESS);
12311be35a1SLionel Sambuc     engine::tester tester("mock", none, none);
12411be35a1SLionel Sambuc     const std::string output = tester.list(fs::path("/foo/bar"));
12511be35a1SLionel Sambuc 
12611be35a1SLionel Sambuc     const std::string exp_output =
12711be35a1SLionel Sambuc         "Arg: list\n"
12811be35a1SLionel Sambuc         "Arg: /foo/bar\n"
12911be35a1SLionel Sambuc         "tester output\n"
13011be35a1SLionel Sambuc         "tester error\n";
13111be35a1SLionel Sambuc     ATF_REQUIRE_EQ(exp_output, output);
13211be35a1SLionel Sambuc }
13311be35a1SLionel Sambuc 
13411be35a1SLionel Sambuc 
13511be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__list__explicit_common_args);
ATF_TEST_CASE_BODY(tester__list__explicit_common_args)13611be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__list__explicit_common_args)
13711be35a1SLionel Sambuc {
13811be35a1SLionel Sambuc     const passwd::user user("fake", 123, 456);
13911be35a1SLionel Sambuc     const datetime::delta timeout(15, 0);
14011be35a1SLionel Sambuc 
141*84d9c625SLionel Sambuc     create_mock_tester_exit(EXIT_SUCCESS);
14211be35a1SLionel Sambuc     engine::tester tester("mock", utils::make_optional(user),
14311be35a1SLionel Sambuc                           utils::make_optional(timeout));
14411be35a1SLionel Sambuc     const std::string output = tester.list(fs::path("/another/program/1"));
14511be35a1SLionel Sambuc 
14611be35a1SLionel Sambuc     const std::string exp_output =
14711be35a1SLionel Sambuc         "Arg: -u123\n"
14811be35a1SLionel Sambuc         "Arg: -g456\n"
14911be35a1SLionel Sambuc         "Arg: -t15\n"
15011be35a1SLionel Sambuc         "Arg: list\n"
15111be35a1SLionel Sambuc         "Arg: /another/program/1\n"
15211be35a1SLionel Sambuc         "tester output\n"
15311be35a1SLionel Sambuc         "tester error\n";
15411be35a1SLionel Sambuc     ATF_REQUIRE_EQ(exp_output, output);
15511be35a1SLionel Sambuc }
15611be35a1SLionel Sambuc 
15711be35a1SLionel Sambuc 
15811be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__list__unknown_interface);
ATF_TEST_CASE_BODY(tester__list__unknown_interface)15911be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__list__unknown_interface)
16011be35a1SLionel Sambuc {
16111be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", ".");
16211be35a1SLionel Sambuc     engine::tester tester("non-existent", none, none);
16311be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(engine::error, "Unknown interface non-existent",
16411be35a1SLionel Sambuc                          tester.list(fs::path("does-not-matter")));
16511be35a1SLionel Sambuc }
16611be35a1SLionel Sambuc 
16711be35a1SLionel Sambuc 
16811be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__list__tester_fails);
ATF_TEST_CASE_BODY(tester__list__tester_fails)16911be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__list__tester_fails)
17011be35a1SLionel Sambuc {
171*84d9c625SLionel Sambuc     create_mock_tester_exit(EXIT_FAILURE);
172*84d9c625SLionel Sambuc     engine::tester tester("mock", none, none);
173*84d9c625SLionel Sambuc     ATF_REQUIRE_THROW_RE(
174*84d9c625SLionel Sambuc         engine::error,
175*84d9c625SLionel Sambuc         "Tester did not exit cleanly:.*tester output.*tester error",
176*84d9c625SLionel Sambuc         tester.list(fs::path("does-not-matter")));
177*84d9c625SLionel Sambuc }
178*84d9c625SLionel Sambuc 
179*84d9c625SLionel Sambuc 
180*84d9c625SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__list__tester_crashes);
ATF_TEST_CASE_BODY(tester__list__tester_crashes)181*84d9c625SLionel Sambuc ATF_TEST_CASE_BODY(tester__list__tester_crashes)
182*84d9c625SLionel Sambuc {
183*84d9c625SLionel Sambuc     create_mock_tester_signal(SIGKILL);
18411be35a1SLionel Sambuc     engine::tester tester("mock", none, none);
18511be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(
18611be35a1SLionel Sambuc         engine::error,
18711be35a1SLionel Sambuc         "Tester did not exit cleanly:.*tester output.*tester error",
18811be35a1SLionel Sambuc         tester.list(fs::path("does-not-matter")));
18911be35a1SLionel Sambuc }
19011be35a1SLionel Sambuc 
19111be35a1SLionel Sambuc 
19211be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__test__defaults);
ATF_TEST_CASE_BODY(tester__test__defaults)19311be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__test__defaults)
19411be35a1SLionel Sambuc {
19511be35a1SLionel Sambuc     std::map< std::string, std::string > vars;
19611be35a1SLionel Sambuc 
197*84d9c625SLionel Sambuc     create_mock_tester_exit(EXIT_FAILURE);
19811be35a1SLionel Sambuc     engine::tester tester("mock", none, none);
19911be35a1SLionel Sambuc     tester.test(fs::path("/foo/bar"), "test-case", fs::path("/the/result/file"),
20011be35a1SLionel Sambuc                 fs::path("tester.out"), fs::path("tester.err"), vars);
20111be35a1SLionel Sambuc 
20211be35a1SLionel Sambuc     const std::string exp_output =
20311be35a1SLionel Sambuc         "Arg: test\n"
20411be35a1SLionel Sambuc         "Arg: /foo/bar\n"
20511be35a1SLionel Sambuc         "Arg: test-case\n"
20611be35a1SLionel Sambuc         "Arg: /the/result/file\n"
20711be35a1SLionel Sambuc         "tester output\n";
20811be35a1SLionel Sambuc     const std::string exp_error =
20911be35a1SLionel Sambuc         "tester error\n";
21011be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::compare_file("tester.out", exp_output));
21111be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::compare_file("tester.err", exp_error));
21211be35a1SLionel Sambuc }
21311be35a1SLionel Sambuc 
21411be35a1SLionel Sambuc 
21511be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__test__explicit_common_args_and_vars);
ATF_TEST_CASE_BODY(tester__test__explicit_common_args_and_vars)21611be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__test__explicit_common_args_and_vars)
21711be35a1SLionel Sambuc {
21811be35a1SLionel Sambuc     const passwd::user user("fake", 123, 456);
21911be35a1SLionel Sambuc     const datetime::delta timeout(15, 0);
22011be35a1SLionel Sambuc 
22111be35a1SLionel Sambuc     std::map< std::string, std::string > vars;
22211be35a1SLionel Sambuc     vars["var1"] = "value1";
22311be35a1SLionel Sambuc     vars["variable-2"] = "value with spaces";
22411be35a1SLionel Sambuc 
225*84d9c625SLionel Sambuc     create_mock_tester_exit(EXIT_SUCCESS);
22611be35a1SLionel Sambuc     engine::tester tester("mock", utils::make_optional(user),
22711be35a1SLionel Sambuc                           utils::make_optional(timeout));
22811be35a1SLionel Sambuc     tester.test(fs::path("/foo/bar"), "test-case", fs::path("/the/result/file"),
22911be35a1SLionel Sambuc                 fs::path("tester.out"), fs::path("tester.err"), vars);
23011be35a1SLionel Sambuc 
23111be35a1SLionel Sambuc     const std::string exp_output =
23211be35a1SLionel Sambuc         "Arg: -u123\n"
23311be35a1SLionel Sambuc         "Arg: -g456\n"
23411be35a1SLionel Sambuc         "Arg: -t15\n"
23511be35a1SLionel Sambuc         "Arg: test\n"
23611be35a1SLionel Sambuc         "Arg: -vvar1=value1\n"
23711be35a1SLionel Sambuc         "Arg: -vvariable-2=value with spaces\n"
23811be35a1SLionel Sambuc         "Arg: /foo/bar\n"
23911be35a1SLionel Sambuc         "Arg: test-case\n"
24011be35a1SLionel Sambuc         "Arg: /the/result/file\n"
24111be35a1SLionel Sambuc         "tester output\n";
24211be35a1SLionel Sambuc     const std::string exp_error =
24311be35a1SLionel Sambuc         "tester error\n";
24411be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::compare_file("tester.out", exp_output));
24511be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::compare_file("tester.err", exp_error));
24611be35a1SLionel Sambuc }
24711be35a1SLionel Sambuc 
24811be35a1SLionel Sambuc 
24911be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__test__unknown_interface);
ATF_TEST_CASE_BODY(tester__test__unknown_interface)25011be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__test__unknown_interface)
25111be35a1SLionel Sambuc {
25211be35a1SLionel Sambuc     const std::map< std::string, std::string > vars;
25311be35a1SLionel Sambuc 
25411be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", ".");
25511be35a1SLionel Sambuc     engine::tester tester("non-existent", none, none);
25611be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(engine::error, "Unknown interface non-existent",
25711be35a1SLionel Sambuc                          tester.test(fs::path("foo"), "bar", fs::path("baz"),
25811be35a1SLionel Sambuc                                      fs::path("out"), fs::path("err"), vars));
25911be35a1SLionel Sambuc }
26011be35a1SLionel Sambuc 
26111be35a1SLionel Sambuc 
26211be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__test__tester_fails);
ATF_TEST_CASE_BODY(tester__test__tester_fails)26311be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester__test__tester_fails)
26411be35a1SLionel Sambuc {
26511be35a1SLionel Sambuc     const std::map< std::string, std::string > vars;
26611be35a1SLionel Sambuc 
267*84d9c625SLionel Sambuc     create_mock_tester_exit(2);
26811be35a1SLionel Sambuc     engine::tester tester("mock", none, none);
26911be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(
27011be35a1SLionel Sambuc         engine::error,
27111be35a1SLionel Sambuc         "Tester failed with code 2; this is a bug",
27211be35a1SLionel Sambuc         tester.test(fs::path("foo"), "bar", fs::path("baz"),
27311be35a1SLionel Sambuc                     fs::path("out"), fs::path("err"), vars));
27411be35a1SLionel Sambuc }
27511be35a1SLionel Sambuc 
27611be35a1SLionel Sambuc 
277*84d9c625SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester__test__tester_crashes);
ATF_TEST_CASE_BODY(tester__test__tester_crashes)278*84d9c625SLionel Sambuc ATF_TEST_CASE_BODY(tester__test__tester_crashes)
279*84d9c625SLionel Sambuc {
280*84d9c625SLionel Sambuc     const std::map< std::string, std::string > vars;
281*84d9c625SLionel Sambuc 
282*84d9c625SLionel Sambuc     create_mock_tester_signal(SIGKILL);
283*84d9c625SLionel Sambuc     engine::tester tester("mock", none, none);
284*84d9c625SLionel Sambuc     ATF_REQUIRE_THROW_RE(
285*84d9c625SLionel Sambuc         engine::error,
286*84d9c625SLionel Sambuc         F("Tester received signal %s; this is a bug") % SIGKILL,
287*84d9c625SLionel Sambuc         tester.test(fs::path("foo"), "bar", fs::path("baz"),
288*84d9c625SLionel Sambuc                     fs::path("out"), fs::path("err"), vars));
289*84d9c625SLionel Sambuc }
290*84d9c625SLionel Sambuc 
291*84d9c625SLionel Sambuc 
29211be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester_path__default);
ATF_TEST_CASE_BODY(tester_path__default)29311be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester_path__default)
29411be35a1SLionel Sambuc {
29511be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::file_exists(engine::tester_path("atf").str()));
29611be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::file_exists(engine::tester_path("plain").str()));
29711be35a1SLionel Sambuc }
29811be35a1SLionel Sambuc 
29911be35a1SLionel Sambuc 
30011be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester_path__custom);
ATF_TEST_CASE_BODY(tester_path__custom)30111be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester_path__custom)
30211be35a1SLionel Sambuc {
30311be35a1SLionel Sambuc     fs::mkdir(fs::path("testers"), 0755);
30411be35a1SLionel Sambuc     atf::utils::create_file("testers/kyua-mock-1-tester", "Not a binary");
30511be35a1SLionel Sambuc     atf::utils::create_file("testers/kyua-mock-2-tester", "Not a binary");
30611be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", (fs::current_path() / "testers").str());
30711be35a1SLionel Sambuc 
30811be35a1SLionel Sambuc     const fs::path mock1 = engine::tester_path("mock-1");
30911be35a1SLionel Sambuc     ATF_REQUIRE(mock1.is_absolute());
31011be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::file_exists(mock1.str()));
31111be35a1SLionel Sambuc 
31211be35a1SLionel Sambuc     const fs::path mock2 = engine::tester_path("mock-2");
31311be35a1SLionel Sambuc     ATF_REQUIRE(mock2.is_absolute());
31411be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::file_exists(mock2.str()));
31511be35a1SLionel Sambuc 
31611be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(engine::error, "Unknown interface mock-3",
31711be35a1SLionel Sambuc                          engine::tester_path("mock-3"));
31811be35a1SLionel Sambuc }
31911be35a1SLionel Sambuc 
32011be35a1SLionel Sambuc 
32111be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester_path__cached);
ATF_TEST_CASE_BODY(tester_path__cached)32211be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester_path__cached)
32311be35a1SLionel Sambuc {
32411be35a1SLionel Sambuc     fs::mkdir(fs::path("testers"), 0755);
32511be35a1SLionel Sambuc     atf::utils::create_file("testers/kyua-mock-tester", "Not a binary");
32611be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", (fs::current_path() / "testers").str());
32711be35a1SLionel Sambuc 
32811be35a1SLionel Sambuc     const fs::path mock = engine::tester_path("mock");
32911be35a1SLionel Sambuc     ATF_REQUIRE(atf::utils::file_exists(mock.str()));
33011be35a1SLionel Sambuc     ATF_REQUIRE(::unlink(mock.c_str()) != -1);
33111be35a1SLionel Sambuc     ATF_REQUIRE(!atf::utils::file_exists(mock.str()));
33211be35a1SLionel Sambuc     ATF_REQUIRE_EQ(mock, engine::tester_path("mock"));
33311be35a1SLionel Sambuc }
33411be35a1SLionel Sambuc 
33511be35a1SLionel Sambuc 
33611be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester_path__empty);
ATF_TEST_CASE_BODY(tester_path__empty)33711be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester_path__empty)
33811be35a1SLionel Sambuc {
33911be35a1SLionel Sambuc     fs::mkdir(fs::path("testers"), 0755);
34011be35a1SLionel Sambuc     atf::utils::create_file("testers/kyua--tester", "Not a binary");
34111be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", (fs::current_path() / "testers").str());
34211be35a1SLionel Sambuc 
34311be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(engine::error, "Unknown interface ",
34411be35a1SLionel Sambuc                          engine::tester_path(""));
34511be35a1SLionel Sambuc }
34611be35a1SLionel Sambuc 
34711be35a1SLionel Sambuc 
34811be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tester_path__missing);
ATF_TEST_CASE_BODY(tester_path__missing)34911be35a1SLionel Sambuc ATF_TEST_CASE_BODY(tester_path__missing)
35011be35a1SLionel Sambuc {
35111be35a1SLionel Sambuc     utils::setenv("KYUA_TESTERSDIR", fs::current_path().str());
35211be35a1SLionel Sambuc     ATF_REQUIRE_THROW_RE(engine::error, "Unknown interface plain",
35311be35a1SLionel Sambuc                          engine::tester_path("plain"));
35411be35a1SLionel Sambuc }
35511be35a1SLionel Sambuc 
35611be35a1SLionel Sambuc 
ATF_INIT_TEST_CASES(tcs)35711be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
35811be35a1SLionel Sambuc {
35911be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__list__defaults);
36011be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__list__explicit_common_args);
36111be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__list__unknown_interface);
36211be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__list__tester_fails);
363*84d9c625SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__list__tester_crashes);
36411be35a1SLionel Sambuc 
36511be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__test__defaults);
36611be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__test__explicit_common_args_and_vars);
36711be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__test__unknown_interface);
36811be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__test__tester_fails);
369*84d9c625SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester__test__tester_crashes);
37011be35a1SLionel Sambuc 
37111be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester_path__default);
37211be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester_path__custom);
37311be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester_path__cached);
37411be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester_path__empty);
37511be35a1SLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tester_path__missing);
37611be35a1SLionel Sambuc }
377