Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
testoption.cpp
Go to the documentation of this file.
1/*
2 TestOption - handle cmdline for invoking Testsuite
3
4 Copyright (C)
5 2008, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
20#include "lib/error.hpp"
22#include "lib/test/suite.hpp"
23
24
25
26
27typedef boost::program_options::options_description Syntax;
28typedef boost::program_options::variables_map VarMap;
29
30namespace op = boost::program_options;
31
32using lib::VectS;
33using std::optional;
34
35namespace test {
36
37
47 : syntax("Run a collection of test cases. Supported parameters"),
48 parameters()
49 {
50 syntax.add_options()
51 ("help,h", "produce help message")
52 ("group,g", op::value<string>()->default_value(Suite::ALLGROUP),
53 "the group (selection) of testcases to execute")
54 ("describe", op::bool_switch(),
55 "enumerate all testcases in this Suite in a format usable with ./test.sh.")
56 ("seed", op::value<uint64_t>(),
57 "the group (selection) of testcases to execute")
58 ("id", op::value<VectS>(),
59 "an individual testcase to be called.\nIf not specified, run all.")
60 ;
61
62 // the testcase-ID is really an positional parameter
63 op::positional_options_description posopt;
64 posopt.add("id", -1);
65
66 op::parsed_options parsed =
67 op::command_line_parser (cmdline)
68 .options (syntax)
69 .positional(posopt)
70 .allow_unregistered()
71 .run();
72
73 op::store (parsed, parameters);
74 op::notify(parameters);
75
76 // remove all recognised options from original cmdline vector
77 cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
78 }
79
80
81
82
85 const string
87 {
88 ASSERT (parameters.count ("group"));
89 return parameters["group"].as<string>();
90 }
91
94 const string
96 {
97 if (parameters.count ("id") &&
98 parameters["id"].as<VectS>().size() > 0)
99 return parameters["id"].as<VectS>()[0];
100 else
101 return string ();
102 }
103
104 optional<uint64_t>
106 {
107 if (parameters.count ("seed"))
108 return parameters["seed"].as<uint64_t>();
109 else
110 return std::nullopt;
111 }
112
114 bool
116 {
117 return parameters["describe"].as<bool>();
118 }
119
124 bool
126 {
127 if (parameters.count("help"))
128 {
129 std::cerr << *this;
130 return true;
131 }
132 return false;
133 }
134
135
136 ostream&
137 operator<< (ostream& os, const TestOption& to)
138 {
139 return os << to.syntax;
140 }
141
142
143
144} // namespace test
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition cmdline.hpp:49
static const string ALLGROUP
"magic" groupID containing all registered testcases
Definition suite.hpp:71
Support for selecting and configuring testcases via commandline arguments.
const string getTestgroup()
std::optional< uint64_t > optSeed()
bool handleHelpRequest()
handles the –help switch by printing a syntax description
boost::program_options::variables_map parameters
boost::program_options::options_description syntax
const string getTestID()
TestOption(lib::Cmdline &cmdline)
set up an options parser to use the current commandline.
Lumiera error handling (C++ interface).
vector< string > VectS
Definition cmdline.hpp:39
Test runner and basic definitions for tests.
ostream & operator<<(ostream &os, const TestOption &to)
for outputting the help messages.
Building and running a suite of tests, implemented as test classes.
boost::program_options::variables_map VarMap
boost::program_options::options_description Syntax
Commandline options for our unittest test-suite executable.