xref: /freebsd/contrib/kyua/cli/common.hpp (revision 99aeb219cad9a5a0347ca3ffef963bb614c99eb9)
1 // Copyright 2011 The Kyua Authors.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
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.
16 //
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.
28 
29 /// \file cli/common.hpp
30 /// Utility functions to implement CLI subcommands.
31 
32 #if !defined(CLI_COMMON_HPP)
33 #define CLI_COMMON_HPP
34 
35 #include <memory>
36 #include <set>
37 #include <vector>
38 
39 #include "engine/filters_fwd.hpp"
40 #include "model/test_program_fwd.hpp"
41 #include "model/test_result.hpp"
42 #include "utils/cmdline/base_command.hpp"
43 #include "utils/cmdline/options_fwd.hpp"
44 #include "utils/cmdline/parser_fwd.hpp"
45 #include "utils/cmdline/ui_fwd.hpp"
46 #include "utils/config/tree_fwd.hpp"
47 #include "utils/datetime_fwd.hpp"
48 #include "utils/fs/path_fwd.hpp"
49 #include "utils/optional_fwd.hpp"
50 
51 namespace cli {
52 
53 
54 extern const utils::cmdline::path_option build_root_option;
55 extern const utils::cmdline::path_option kyuafile_option;
56 extern const utils::cmdline::string_option results_file_create_option;
57 extern const utils::cmdline::string_option results_file_open_option;
58 extern const utils::cmdline::list_option results_filter_option;
59 extern const utils::cmdline::property_option variable_option;
60 
61 
62 /// Base type for commands defined in the cli module.
63 ///
64 /// All commands in Kyua receive a configuration object as their runtime
65 /// data parameter because the configuration file applies to all the
66 /// commands.
67 typedef utils::cmdline::base_command< utils::config::tree > cli_command;
68 
69 
70 /// Scoped, strictly owned pointer to a cli_command.
71 typedef std::auto_ptr< cli_command > cli_command_ptr;
72 
73 
74 /// Collection of result types.
75 ///
76 /// This is a vector rather than a set because we want to respect the order in
77 /// which the user provided the types.
78 typedef std::vector< model::test_result_type > result_types;
79 
80 
81 utils::optional< utils::fs::path > build_root_path(
82     const utils::cmdline::parsed_cmdline&);
83 utils::fs::path kyuafile_path(const utils::cmdline::parsed_cmdline&);
84 std::string results_file_create(const utils::cmdline::parsed_cmdline&);
85 std::string results_file_open(const utils::cmdline::parsed_cmdline&);
86 result_types get_result_types(const utils::cmdline::parsed_cmdline&);
87 
88 std::set< engine::test_filter > parse_filters(
89     const utils::cmdline::args_vector&);
90 bool report_unused_filters(const std::set< engine::test_filter >&,
91                            utils::cmdline::ui*);
92 
93 std::string format_delta(const utils::datetime::delta&);
94 std::string format_result(const model::test_result&);
95 std::string format_test_case_id(const model::test_program&, const std::string&);
96 std::string format_test_case_id(const engine::test_filter&);
97 
98 
99 void write_version_header(utils::cmdline::ui*);
100 
101 
102 }  // namespace cli
103 
104 #endif  // !defined(CLI_COMMON_HPP)
105