Sequoia
Loading...
Searching...
No Matches
CommandLineArgumentsTestingUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2020. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
14
16
17
18namespace sequoia::testing
19{
21 {
22 explicit function_object(std::string t="")
23 : tag{t}
24 {}
25
26 void operator()(const parsing::commandline::arg_list&) const noexcept {}
27
28 std::string tag{};
29 };
30
31 template<>
32 struct value_tester<parsing::commandline::operation>
33 {
35
36 template<test_mode Mode>
37 static void test(weak_equivalence_check_t, test_logger<Mode>& logger, const type& operation, const type& prediction)
38 {
39 check_executor(logger, operation.early, prediction.early, "early");
40 check_executor(logger, operation.late, prediction.late, "late");
41 check(equality, "Operation Parameters differ", logger, operation.arguments, prediction.arguments);
42 }
43 private:
44 using executor = parsing::commandline::executor;
45
46 template<test_mode Mode>
47 static void check_executor(test_logger<Mode>& logger, const executor& operation, const executor& prediction, std::string_view tag)
48 {
49 const bool consistent{(operation && prediction) || (!operation && !prediction)};
50 testing::check(std::string{"Existence of"}.append(tag).append(" function objects differs"), logger, consistent);
51
52 if(operation && prediction)
53 {
54 check(equality,
55 "Function object tag",
56 logger,
57 operation.target<function_object>()->tag,
58 prediction.target<function_object>()->tag);
59 }
60 }
61 };
62
63
64 template<>
65 struct value_tester<parsing::commandline::outcome>
66 {
68
69 template<test_mode Mode>
70 static void test(weak_equivalence_check_t, test_logger<Mode>& logger, const type& obtained, const type& prediction)
71 {
72 check(equality, "Zeroth Argument", logger, obtained.zeroth_arg, prediction.zeroth_arg);
73 check(weak_equivalence, "Operations", logger, obtained.operations, prediction.operations);
74 check(equality, "Help", logger, obtained.help, prediction.help);
75 }
76 };
77
78 template<>
79 struct value_tester<parsing::commandline::argument_parser>
80 {
83
84 template<test_mode Mode>
85 static void test(weak_equivalence_check_t, test_logger<Mode>& logger, const type& obtained, const prediction_type& prediction)
86 {
87 check(weak_equivalence, "", logger, obtained.get(), prediction);
88 }
89 };
90
92 {
93 public:
94 [[nodiscard]]
95 int size() const noexcept
96 {
97 return static_cast<int>(m_Args.size());
98 }
99
100 commandline_arguments(std::vector<std::string> args);
101
102 [[nodiscard]]
103 char** get() noexcept
104 {
105 return !m_Ptrs.empty() ? &m_Ptrs[0] : nullptr;
106 }
107 private:
108 std::vector<std::string> m_Args;
109 std::vector<char*> m_Ptrs;
110 };
111}
Parsing of commandline arguments.
bool check(CheckType flavour, std::string description, test_logger< Mode > &logger, Iter first, Sentinel last, PredictionIter predictionFirst, PredictionSentinel predictionLast, tutor< Advisor > advisor={})
The workhorse for comparing the contents of ranges.
Definition: FreeCheckers.hpp:377
Utilities for checking regular semantics.
Parses command line arguments, building outcome from an option forest.
Definition: CommandLineArguments.hpp:176
Definition: CommandLineArgumentsTestingUtilities.hpp:92
Definition: TestLogger.hpp:183
Used to build a forest of operations which will be invoked at the end of the parsing process.
Definition: CommandLineArguments.hpp:100
The result of parsing command line arguments to build an operation forest.
Definition: CommandLineArguments.hpp:119
Definition: CommandLineArgumentsTestingUtilities.hpp:21
class template, specializations of which implement various comparisons for the specified type.
Definition: FreeCheckers.hpp:78