2007-08-19 21:57:19 +02:00
|
|
|
|
/*
|
2008-11-30 21:00:20 +01:00
|
|
|
|
TestOption - handle cmdline for invoking Testsuite
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** 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. See the file COPYING for further details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
2016-11-03 18:22:31 +01:00
|
|
|
|
/** @file testoption.cpp
|
2016-11-07 15:51:41 +01:00
|
|
|
|
** Implementation of commandline parsing for the unittest test-suite.
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 08:03:21 +02:00
|
|
|
|
#include "lib/error.hpp"
|
2026-03-06 21:34:20 +01:00
|
|
|
|
#include "test/testoption.hpp"
|
|
|
|
|
|
#include "test/suite.hpp"
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2011-02-05 23:53:37 +01:00
|
|
|
|
using lib::VectS;
|
2024-11-11 16:31:43 +01:00
|
|
|
|
using std::optional;
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
2011-02-05 23:53:37 +01:00
|
|
|
|
namespace test {
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** set up an options parser to use the current commandline.
|
2008-11-30 21:00:20 +01:00
|
|
|
|
* Recognises the following options
|
2007-08-19 21:57:19 +02:00
|
|
|
|
* \code
|
|
|
|
|
|
* --help
|
|
|
|
|
|
* --group <groupID>
|
2008-04-05 07:26:54 +02:00
|
|
|
|
* --describe
|
2007-08-19 21:57:19 +02:00
|
|
|
|
* \endcode
|
|
|
|
|
|
*/
|
2011-02-05 23:53:37 +01:00
|
|
|
|
TestOption::TestOption (lib::Cmdline& cmdline)
|
2007-08-23 17:52:33 +02:00
|
|
|
|
: 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(),
|
2008-11-30 21:00:20 +01:00
|
|
|
|
"enumerate all testcases in this Suite in a format usable with ./test.sh.")
|
2024-11-11 16:31:43 +01:00
|
|
|
|
("seed", op::value<uint64_t>(),
|
|
|
|
|
|
"the group (selection) of testcases to execute")
|
2007-08-23 17:52:33 +02:00
|
|
|
|
("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);
|
|
|
|
|
|
|
2025-06-07 23:59:57 +02:00
|
|
|
|
op::parsed_options parsed =
|
2007-08-23 17:52:33 +02:00
|
|
|
|
op::command_line_parser (cmdline)
|
|
|
|
|
|
.options (syntax)
|
|
|
|
|
|
.positional(posopt)
|
|
|
|
|
|
.allow_unregistered()
|
2025-06-07 23:59:57 +02:00
|
|
|
|
.run();
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
|
|
op::store (parsed, parameters);
|
2025-06-07 23:59:57 +02:00
|
|
|
|
op::notify(parameters);
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
2008-11-30 21:00:20 +01:00
|
|
|
|
// remove all recognised options from original cmdline vector
|
2007-08-23 17:52:33 +02:00
|
|
|
|
cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
|
2007-08-19 21:57:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @return the Tests-Group as given on cmdline, or Suite::ALLGROUP as default
|
|
|
|
|
|
*/
|
2025-06-07 23:59:57 +02:00
|
|
|
|
const string
|
2007-08-19 21:57:19 +02:00
|
|
|
|
TestOption::getTestgroup ()
|
2011-02-05 23:53:37 +01: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 ()
|
2011-02-05 23:53:37 +01: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
|
|
|
|
|
2024-11-11 16:31:43 +01:00
|
|
|
|
optional<uint64_t>
|
|
|
|
|
|
TestOption::optSeed()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parameters.count ("seed"))
|
|
|
|
|
|
return parameters["seed"].as<uint64_t>();
|
|
|
|
|
|
else
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
|
/** @return \c true if --describe switch was given */
|
2025-06-07 23:59:57 +02:00
|
|
|
|
bool
|
2014-05-05 22:59:23 +02:00
|
|
|
|
TestOption::shouldDescribe ()
|
2011-02-05 23:53:37 +01:00
|
|
|
|
{
|
|
|
|
|
|
return parameters["describe"].as<bool>();
|
|
|
|
|
|
}
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
2014-05-05 22:59:23 +02:00
|
|
|
|
/** 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;
|
|
|
|
|
|
}
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
2025-06-07 23:59:57 +02:00
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
|
ostream&
|
|
|
|
|
|
operator<< (ostream& os, const TestOption& to)
|
2011-02-05 23:53:37 +01:00
|
|
|
|
{
|
|
|
|
|
|
return os << to.syntax;
|
|
|
|
|
|
}
|
2007-08-19 21:57:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace test
|