1*6b3a42afSjmmv // Copyright 2011 Google Inc.
2*6b3a42afSjmmv // All rights reserved.
3*6b3a42afSjmmv //
4*6b3a42afSjmmv // Redistribution and use in source and binary forms, with or without
5*6b3a42afSjmmv // modification, are permitted provided that the following conditions are
6*6b3a42afSjmmv // met:
7*6b3a42afSjmmv //
8*6b3a42afSjmmv // * Redistributions of source code must retain the above copyright
9*6b3a42afSjmmv // notice, this list of conditions and the following disclaimer.
10*6b3a42afSjmmv // * Redistributions in binary form must reproduce the above copyright
11*6b3a42afSjmmv // notice, this list of conditions and the following disclaimer in the
12*6b3a42afSjmmv // documentation and/or other materials provided with the distribution.
13*6b3a42afSjmmv // * Neither the name of Google Inc. nor the names of its contributors
14*6b3a42afSjmmv // may be used to endorse or promote products derived from this software
15*6b3a42afSjmmv // without specific prior written permission.
16*6b3a42afSjmmv //
17*6b3a42afSjmmv // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*6b3a42afSjmmv // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*6b3a42afSjmmv // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*6b3a42afSjmmv // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*6b3a42afSjmmv // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*6b3a42afSjmmv // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*6b3a42afSjmmv // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*6b3a42afSjmmv // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*6b3a42afSjmmv // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*6b3a42afSjmmv // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*6b3a42afSjmmv // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*6b3a42afSjmmv
29*6b3a42afSjmmv #include "cli/cmd_debug.hpp"
30*6b3a42afSjmmv
31*6b3a42afSjmmv #include <cstdlib>
32*6b3a42afSjmmv
33*6b3a42afSjmmv #include "cli/common.ipp"
34*6b3a42afSjmmv #include "engine/drivers/debug_test.hpp"
35*6b3a42afSjmmv #include "engine/filters.hpp"
36*6b3a42afSjmmv #include "utils/cmdline/exceptions.hpp"
37*6b3a42afSjmmv #include "utils/cmdline/parser.ipp"
38*6b3a42afSjmmv #include "utils/format/macros.hpp"
39*6b3a42afSjmmv
40*6b3a42afSjmmv namespace cmdline = utils::cmdline;
41*6b3a42afSjmmv namespace config = utils::config;
42*6b3a42afSjmmv namespace debug_test = engine::drivers::debug_test;
43*6b3a42afSjmmv
44*6b3a42afSjmmv using cli::cmd_debug;
45*6b3a42afSjmmv
46*6b3a42afSjmmv
47*6b3a42afSjmmv /// Default constructor for cmd_debug.
cmd_debug(void)48*6b3a42afSjmmv cmd_debug::cmd_debug(void) : cli_command(
49*6b3a42afSjmmv "debug", "test_case", 1, 1,
50*6b3a42afSjmmv "Executes a single test case providing facilities for debugging")
51*6b3a42afSjmmv {
52*6b3a42afSjmmv add_option(build_root_option);
53*6b3a42afSjmmv add_option(kyuafile_option);
54*6b3a42afSjmmv
55*6b3a42afSjmmv add_option(cmdline::path_option(
56*6b3a42afSjmmv "stdout", "Where to direct the standard output of the test case",
57*6b3a42afSjmmv "path", "/dev/stdout"));
58*6b3a42afSjmmv
59*6b3a42afSjmmv add_option(cmdline::path_option(
60*6b3a42afSjmmv "stderr", "Where to direct the standard error of the test case",
61*6b3a42afSjmmv "path", "/dev/stderr"));
62*6b3a42afSjmmv }
63*6b3a42afSjmmv
64*6b3a42afSjmmv
65*6b3a42afSjmmv /// Entry point for the "debug" subcommand.
66*6b3a42afSjmmv ///
67*6b3a42afSjmmv /// \param ui Object to interact with the I/O of the program.
68*6b3a42afSjmmv /// \param cmdline Representation of the command line to the subcommand.
69*6b3a42afSjmmv /// \param user_config The runtime debuguration of the program.
70*6b3a42afSjmmv ///
71*6b3a42afSjmmv /// \return 0 if everything is OK, 1 if any of the necessary documents cannot be
72*6b3a42afSjmmv /// opened.
73*6b3a42afSjmmv int
run(cmdline::ui * ui,const cmdline::parsed_cmdline & cmdline,const config::tree & user_config)74*6b3a42afSjmmv cmd_debug::run(cmdline::ui* ui, const cmdline::parsed_cmdline& cmdline,
75*6b3a42afSjmmv const config::tree& user_config)
76*6b3a42afSjmmv {
77*6b3a42afSjmmv const std::string& test_case_name = cmdline.arguments()[0];
78*6b3a42afSjmmv if (test_case_name.find(':') == std::string::npos)
79*6b3a42afSjmmv throw cmdline::usage_error(F("'%s' is not a test case identifier "
80*6b3a42afSjmmv "(missing ':'?)") % test_case_name);
81*6b3a42afSjmmv const engine::test_filter filter = engine::test_filter::parse(
82*6b3a42afSjmmv test_case_name);
83*6b3a42afSjmmv
84*6b3a42afSjmmv const debug_test::result result = debug_test::drive(
85*6b3a42afSjmmv kyuafile_path(cmdline), build_root_path(cmdline), filter, user_config,
86*6b3a42afSjmmv cmdline.get_option< cmdline::path_option >("stdout"),
87*6b3a42afSjmmv cmdline.get_option< cmdline::path_option >("stderr"));
88*6b3a42afSjmmv
89*6b3a42afSjmmv ui->out(F("%s -> %s") % cli::format_test_case_id(result.test_case) %
90*6b3a42afSjmmv cli::format_result(result.test_result));
91*6b3a42afSjmmv
92*6b3a42afSjmmv return result.test_result.good() ? EXIT_SUCCESS : EXIT_FAILURE;
93*6b3a42afSjmmv }
94