Lumiera  0.pre.03
»edit your freedom«
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
21 #include "lib/test/testoption.hpp"
22 #include "lib/test/suite.hpp"
23 
24 
25 
26 
27 typedef boost::program_options::options_description Syntax;
28 typedef boost::program_options::variables_map VarMap;
29 
30 namespace op = boost::program_options;
31 
32 using lib::VectS;
33 using std::optional;
34 
35 namespace 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>
105  TestOption::optSeed()
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
Commandline options for our unittest test-suite executable.
Definition: run.hpp:40
const string getTestID()
Definition: testoption.cpp:95
Building and running a suite of tests, implemented as test classes.
const string getTestgroup()
Definition: testoption.cpp:86
Support for selecting and configuring testcases via commandline arguments.
Definition: testoption.hpp:51
static const string ALLGROUP
"magic" groupID containing all registered testcases
Definition: suite.hpp:71
friend ostream & operator<<(ostream &, const TestOption &)
for outputting the help messages.
Definition: testoption.cpp:137
Lumiera error handling (C++ interface).
bool handleHelpRequest()
handles the –help switch by printing a syntax description
Definition: testoption.cpp:125
TestOption(lib::Cmdline &cmdline)
set up an options parser to use the current commandline.
Definition: testoption.cpp:46
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition: cmdline.hpp:48