testrunner: handle help request properly

don't actually execute the tests when there was a --help
This commit is contained in:
Fischlurch 2014-05-05 22:59:23 +02:00
parent 027386d76c
commit a4c41d1c12
6 changed files with 26 additions and 13 deletions

View file

@ -28,7 +28,7 @@
**
** @see HelloWorld_test
** @see test::Suite
** @see mainsuite.cpp
** @see testrunner.cpp
** @see main.cpp
*/

View file

@ -195,7 +195,7 @@ namespace test {
* in this suite is invoked with a empty cmdline vector.
* @param cmdline ref to the vector of commandline tokens
*/
void
bool
Suite::run (Arg cmdline)
{
PTestMap tests = testcases.getGroup(groupID_);
@ -214,7 +214,7 @@ namespace test {
cmdline.erase (cmdline.begin());
VALID (test,testID);
exitCode_ |= invokeTestCase (*(*test)(), cmdline); // TODO confusing statement, improve definition of test collection datatype Ticket #289
return;
return true;
}
else
throw lumiera::error::Invalid ("unknown test : "+testID);
@ -229,6 +229,7 @@ namespace test {
VALID (test, i->first);
exitCode_ |= invokeTestCase (*(*test)(), cmdline); // actually no cmdline arguments
}
return true;
}

View file

@ -33,7 +33,7 @@
** @see test::Test
** @see test::TestOption
** @see run.hpp
** @see mainsuite.cpp
** @see testrunner.cpp
*/
@ -70,7 +70,7 @@ namespace test {
public:
Suite (string groupID);
void run (Arg cmdline);
bool run (Arg cmdline);
void describe ();
int getExitCode () const;
static void enrol (Launcher *test, string testID, string groups);

View file

@ -76,9 +76,6 @@ namespace test {
// remove all recognised options from original cmdline vector
cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
if (parameters.count("help"))
std::cerr << *this;
}
@ -107,11 +104,25 @@ namespace test {
/** @return \c true if --describe switch was given */
bool
TestOption::getDescribe ()
TestOption::shouldDescribe ()
{
return parameters["describe"].as<bool>();
}
/** handles the --help switch by printing a syntax description
* @return \c false if there was no help request and the
* Suite should indeed be executed.
*/
bool
TestOption::handleHelpRequest()
{
if (parameters.count("help"))
{
std::cerr << *this;
return true;
}
return false;
}
ostream&

View file

@ -56,7 +56,8 @@ namespace test {
TestOption (lib::Cmdline& cmdline);
const string getTestgroup ();
const string getTestID ();
bool getDescribe ();
bool handleHelpRequest();
bool shouldDescribe ();
private:
boost::program_options::options_description syntax;

View file

@ -1,5 +1,5 @@
/*
mainsuite.cpp - execute a suite of test objects, possibly filtered by category
testrunner.cpp - execute a suite of test objects, possibly filtered by category
Copyright (C) Lumiera.org
2008, Christian Thaeter <ct@pipapo.org>
@ -44,10 +44,10 @@ int main (int argc, const char* argv[])
test::Suite suite (optparser.getTestgroup());
LifecycleHook::trigger (ON_GLOBAL_INIT);
if (optparser.getDescribe())
if (optparser.shouldDescribe())
suite.describe();
else
suite.run (args);
optparser.handleHelpRequest() || suite.run (args);
LifecycleHook::trigger (ON_GLOBAL_SHUTDOWN);
return suite.getExitCode();