Lumiera  0.pre.03
»edit your freedom«
testoption.cpp
Go to the documentation of this file.
1 /*
2  TestOption - handle cmdline for invoking Testsuite
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
29 #include "lib/error.hpp"
30 #include "lib/test/testoption.hpp"
31 #include "lib/test/suite.hpp"
32 
33 
34 
35 
36 typedef boost::program_options::options_description Syntax;
37 typedef boost::program_options::variables_map VarMap;
38 
39 namespace op = boost::program_options;
40 
41 using lib::VectS;
42 
43 namespace test {
44 
45 
55  : syntax("Run a collection of test cases. Supported parameters"),
56  parameters()
57  {
58  syntax.add_options()
59  ("help,h", "produce help message")
60  ("group,g", op::value<string>()->default_value(Suite::ALLGROUP),
61  "the group (selection) of testcases to execute")
62  ("describe", op::bool_switch(),
63  "enumerate all testcases in this Suite in a format usable with ./test.sh.")
64  ("id", op::value<VectS>(),
65  "an individual testcase to be called.\nIf not specified, run all.")
66  ;
67 
68  // the testcase-ID is really an positional parameter
69  op::positional_options_description posopt;
70  posopt.add("id", -1);
71 
72  op::parsed_options parsed =
73  op::command_line_parser (cmdline)
74  .options (syntax)
75  .positional(posopt)
76  .allow_unregistered()
77  .run();
78 
79  op::store (parsed, parameters);
80  op::notify(parameters);
81 
82  // remove all recognised options from original cmdline vector
83  cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
84  }
85 
86 
87 
88 
91  const string
93  {
94  ASSERT (parameters.count ("group"));
95  return parameters["group"].as<string>();
96  }
97 
100  const string
102  {
103  if (parameters.count ("id") &&
104  parameters["id"].as<VectS>().size() > 0)
105  return parameters["id"].as<VectS>()[0];
106  else
107  return string ();
108  }
109 
111  bool
113  {
114  return parameters["describe"].as<bool>();
115  }
116 
121  bool
123  {
124  if (parameters.count("help"))
125  {
126  std::cerr << *this;
127  return true;
128  }
129  return false;
130  }
131 
132 
133  ostream&
134  operator<< (ostream& os, const TestOption& to)
135  {
136  return os << to.syntax;
137  }
138 
139 
140 
141 } // namespace test
Commandline options for our unittest test-suite executable.
Definition: run.hpp:49
const string getTestID()
Definition: testoption.cpp:101
Building and running a suite of tests, implemented as test classes.
const string getTestgroup()
Definition: testoption.cpp:92
Support for selecting and configuring testcases via commandline arguments.
Definition: testoption.hpp:59
static const string ALLGROUP
"magic" groupID containing all registered testcases
Definition: suite.hpp:78
friend ostream & operator<<(ostream &, const TestOption &)
for outputting the help messages.
Definition: testoption.cpp:134
Lumiera error handling (C++ interface).
bool handleHelpRequest()
handles the –help switch by printing a syntax description
Definition: testoption.cpp:122
TestOption(lib::Cmdline &cmdline)
set up an options parser to use the current commandline.
Definition: testoption.cpp:54
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition: cmdline.hpp:57