2007-08-19 21:57:19 +02:00
|
|
|
/*
|
|
|
|
|
Suite - helper class for running collections of tests
|
|
|
|
|
|
|
|
|
|
Copyright (C) CinelerraCV
|
2007-11-27 03:19:35 +01:00
|
|
|
2007, Hermann Vosseler <Ichthyostega@web.de>
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "common/test/testoption.hpp"
|
|
|
|
|
#include "common/test/suite.hpp"
|
|
|
|
|
|
|
|
|
|
#include "nobugcfg.h"
|
|
|
|
|
#include "common/error.hpp"
|
|
|
|
|
|
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
typedef boost::program_options::options_description Syntax;
|
|
|
|
|
typedef boost::program_options::variables_map VarMap;
|
|
|
|
|
|
|
|
|
|
namespace op = boost::program_options;
|
|
|
|
|
|
|
|
|
|
using util::VectS;
|
|
|
|
|
|
2007-08-19 21:57:19 +02:00
|
|
|
namespace test
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** set up an options parser to use the current commandline.
|
|
|
|
|
* reconizes the following options
|
|
|
|
|
* \code
|
|
|
|
|
* --help
|
|
|
|
|
* --group <groupID>
|
|
|
|
|
* \endcode
|
|
|
|
|
*/
|
2007-08-23 17:52:33 +02:00
|
|
|
TestOption::TestOption (util::Cmdline& cmdline)
|
|
|
|
|
: syntax("Run a collection of test cases. Supported parameters"),
|
|
|
|
|
parameters()
|
2007-08-19 21:57:19 +02:00
|
|
|
{
|
2007-08-23 17:52:33 +02:00
|
|
|
syntax.add_options()
|
|
|
|
|
("help,h", "produce help message")
|
|
|
|
|
("group,g", op::value<string>()->default_value(Suite::ALLGROUP),
|
|
|
|
|
"the group (selection) of testcases to execute")
|
|
|
|
|
("describe", op::bool_switch(),
|
|
|
|
|
"ennumerate all testcases in this Suite in a format usable with ./test.sh.")
|
|
|
|
|
("id", op::value<VectS>(),
|
|
|
|
|
"an individual testcase to be called.\nIf not specified, run all.")
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
// the testcase-ID is really an positional parameter
|
|
|
|
|
op::positional_options_description posopt;
|
|
|
|
|
posopt.add("id", -1);
|
|
|
|
|
|
|
|
|
|
op::parsed_options parsed =
|
|
|
|
|
op::command_line_parser (cmdline)
|
|
|
|
|
.options (syntax)
|
|
|
|
|
.positional(posopt)
|
|
|
|
|
.allow_unregistered()
|
|
|
|
|
.run();
|
|
|
|
|
|
|
|
|
|
op::store (parsed, parameters);
|
|
|
|
|
op::notify(parameters);
|
|
|
|
|
|
|
|
|
|
// remove all recognized options from original cmdline vector
|
|
|
|
|
cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
|
|
|
|
|
|
|
|
|
|
if (parameters.count("help"))
|
|
|
|
|
std::cerr << *this;
|
2007-08-19 21:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @return the Tests-Group as given on cmdline, or Suite::ALLGROUP as default
|
|
|
|
|
*/
|
2007-08-23 17:52:33 +02:00
|
|
|
const string
|
2007-08-19 21:57:19 +02:00
|
|
|
TestOption::getTestgroup ()
|
|
|
|
|
{
|
2007-08-23 17:52:33 +02:00
|
|
|
ASSERT (parameters.count ("group"));
|
|
|
|
|
return parameters["group"].as<string>();
|
2007-08-19 21:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
/** @return ID of a single test to run, empty string if not specified
|
2007-08-19 21:57:19 +02:00
|
|
|
*/
|
2007-08-23 17:52:33 +02:00
|
|
|
const string
|
2007-08-19 21:57:19 +02:00
|
|
|
TestOption::getTestID ()
|
|
|
|
|
{
|
2007-08-23 17:52:33 +02:00
|
|
|
if (parameters.count ("id") &&
|
|
|
|
|
parameters["id"].as<VectS>().size() > 0)
|
|
|
|
|
return parameters["id"].as<VectS>()[0];
|
|
|
|
|
else
|
|
|
|
|
return string ();
|
2007-08-19 21:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
/** @return \c true if --describe switch was given */
|
|
|
|
|
const bool
|
|
|
|
|
TestOption::getDescribe ()
|
2007-08-19 21:57:19 +02:00
|
|
|
{
|
2007-08-23 17:52:33 +02:00
|
|
|
return parameters["describe"].as<bool>();
|
2007-08-19 21:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
ostream&
|
|
|
|
|
operator<< (ostream& os, const TestOption& to)
|
2007-08-19 21:57:19 +02:00
|
|
|
{
|
2007-08-23 17:52:33 +02:00
|
|
|
return os << to.syntax;
|
2007-08-19 21:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace test
|