draft outline for main()
This commit is contained in:
parent
6ca2c23bda
commit
3693a5fa3d
8 changed files with 258 additions and 22 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Suite - handle cmdline for invoking Testsuite
|
||||
TestOption - handle cmdline for invoking Testsuite
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
|
@ -40,7 +40,7 @@ namespace test
|
|||
|
||||
|
||||
/** set up an options parser to use the current commandline.
|
||||
* reconizes the following options
|
||||
* Recognises the following options
|
||||
* \code
|
||||
* --help
|
||||
* --group <groupID>
|
||||
|
|
@ -56,7 +56,7 @@ namespace test
|
|||
("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.")
|
||||
"enumerate 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.")
|
||||
;
|
||||
|
|
@ -75,7 +75,7 @@ namespace test
|
|||
op::store (parsed, parameters);
|
||||
op::notify(parameters);
|
||||
|
||||
// remove all recognized options from original cmdline vector
|
||||
// remove all recognised options from original cmdline vector
|
||||
cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
|
||||
|
||||
if (parameters.count("help"))
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace test
|
|||
* to be parsed is taken wrapped into a Cmdline
|
||||
* instance; after parsing this commandline
|
||||
* vector will contain only the remaining
|
||||
* unrecognized parts.
|
||||
* unrecognised parts.
|
||||
*/
|
||||
class TestOption : private boost::noncopyable
|
||||
{
|
||||
|
|
@ -66,8 +66,8 @@ namespace test
|
|||
};
|
||||
|
||||
|
||||
/** for outputting the help messages. Forward accummulated
|
||||
* help messages from all contained option defintions */
|
||||
/** for outputting the help messages. Forward accumulated
|
||||
* help messages from all contained option definitions */
|
||||
ostream& operator<< (ostream& os, const TestOption& to);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ using boost::regex_search;
|
|||
namespace util
|
||||
{
|
||||
|
||||
/** create as a tokenized <i>copy</i> of the current commandline.
|
||||
* Note that argv[0] is allways ignored. */
|
||||
/** create as a tokenised <i>copy</i> of the current commandline.
|
||||
* Note that argv[0] is always ignored. */
|
||||
Cmdline::Cmdline (int argc, const char** argv)
|
||||
: vector<string> (noneg(argc-1))
|
||||
{
|
||||
|
|
@ -63,7 +63,7 @@ namespace util
|
|||
}
|
||||
|
||||
|
||||
/** create by tokenizing a string
|
||||
/** create by tokenising a string
|
||||
* (e.g. "fake" cmdline, separated by whitespace)
|
||||
*/
|
||||
Cmdline::Cmdline (const string cmdline)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@ namespace lumiera {
|
|||
using util::contains;
|
||||
using std::string;
|
||||
|
||||
// typedef const char * const Symbol; //TODO define a real Symbol class, i.e. same literal string==same pointer,
|
||||
// so we don't have to store string keys in the map...
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,23 +24,63 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "proc/common.hpp"
|
||||
#include "include/nobugcfg.h"
|
||||
#include "include/error.hpp"
|
||||
#include "include/lifecycle.h"
|
||||
#include "lumiera/appstate.hpp"
|
||||
#include "lumiera/option.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using lumiera::AppState;
|
||||
using lumiera::ON_GLOBAL_INIT;
|
||||
using lumiera::ON_GLOBAL_SHUTDOWN;
|
||||
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
cout << "*** Lumiera NLE for Linux ***" << endl;
|
||||
NOTICE (lumiera, "*** Lumiera NLE for Linux ***");
|
||||
|
||||
AppState::lifecycle (ON_GLOBAL_INIT);
|
||||
util::Cmdline args (argc,argv);
|
||||
AppState& application = AppState::instance();
|
||||
application.decide (lumiera::Option (args));
|
||||
|
||||
// great things are happening here....
|
||||
try
|
||||
{
|
||||
AppState::lifecycle (ON_GLOBAL_INIT);
|
||||
|
||||
if (application.isLoadExistingSession())
|
||||
Session::current.load (application.getSessionFile());
|
||||
|
||||
if (application.isServerNode())
|
||||
ServerNode::open (application.getNodeServices());
|
||||
|
||||
if (application.isUseGUI())
|
||||
GuiFacade::start();
|
||||
|
||||
if (application.isRunScript())
|
||||
ScriptEnv::run (application.getScriptFile());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
catch (lumiera::Error& problem)
|
||||
{
|
||||
application.abort (problem);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
application.abort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
shutdown ()
|
||||
{
|
||||
/////////////TODO: any sensible way how this function can be activated?
|
||||
|
||||
AppState::lifecycle (ON_GLOBAL_SHUTDOWN);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
|
|||
123
src/lumiera/option.cpp
Normal file
123
src/lumiera/option.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
Option - handle cmdline for starting the Lumiera application
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
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 "lumiera/option.hpp"
|
||||
|
||||
#include "include/error.hpp"
|
||||
|
||||
|
||||
|
||||
typedef boost::program_options::options_description Syntax;
|
||||
typedef boost::program_options::variables_map VarMap;
|
||||
|
||||
namespace op = boost::program_options;
|
||||
|
||||
using util::VectS;
|
||||
|
||||
namespace lumiera {
|
||||
|
||||
|
||||
/** set up an options parser to use the application commandline.
|
||||
* Recognises the following options
|
||||
* \code
|
||||
* --help
|
||||
* \endcode
|
||||
* @todo describe the actual options
|
||||
*/
|
||||
Option::Option (util::Cmdline& cmdline)
|
||||
: syntax("Run a collection of test cases. Supported parameters"),
|
||||
parameters()
|
||||
{
|
||||
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(),
|
||||
"enumerate 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 recognised options from original cmdline vector
|
||||
cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
|
||||
|
||||
if (parameters.count("help"))
|
||||
std::cerr << *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** @return the Tests-Group as given on cmdline, or Suite::ALLGROUP as default
|
||||
*/
|
||||
const string
|
||||
Option::getTestgroup ()
|
||||
{
|
||||
ASSERT (parameters.count ("group"));
|
||||
return parameters["group"].as<string>();
|
||||
}
|
||||
|
||||
/** @return ID of a single test to run, empty string if not specified
|
||||
*/
|
||||
const string
|
||||
Option::getTestID ()
|
||||
{
|
||||
if (parameters.count ("id") &&
|
||||
parameters["id"].as<VectS>().size() > 0)
|
||||
return parameters["id"].as<VectS>()[0];
|
||||
else
|
||||
return string ();
|
||||
}
|
||||
|
||||
/** @return \c true if --describe switch was given */
|
||||
const bool
|
||||
Option::getDescribe ()
|
||||
{
|
||||
return parameters["describe"].as<bool>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
ostream&
|
||||
operator<< (ostream& os, const TestOption& to)
|
||||
{
|
||||
return os << to.syntax;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace lumiera
|
||||
75
src/lumiera/option.hpp
Normal file
75
src/lumiera/option.hpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
OPTION.hpp - handle cmdline for starting the Lumiera application
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LUMIERA_OPTION_H
|
||||
#define LUMIERA_OPTION_H
|
||||
|
||||
#include "lib/cmdline.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
|
||||
|
||||
namespace lumiera {
|
||||
|
||||
using std::string;
|
||||
using std::ostream;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Support for selecting and configuring testcases
|
||||
* via commandline arguments. A preconfigured wrapper
|
||||
* around boost::program_options, with the ability
|
||||
* to tolerate unknown options. The commandline
|
||||
* to be parsed is taken wrapped into a Cmdline
|
||||
* instance; after parsing this commandline
|
||||
* vector will contain only the remaining
|
||||
* unrecognised parts.
|
||||
*/
|
||||
class Option : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
Option (util::Cmdline& cmdline);
|
||||
const string getTestgroup ();
|
||||
const string getTestID ();
|
||||
const bool getDescribe ();
|
||||
|
||||
private:
|
||||
boost::program_options::options_description syntax;
|
||||
boost::program_options::variables_map parameters;
|
||||
|
||||
friend ostream& operator<< (ostream&, const TestOption&);
|
||||
};
|
||||
|
||||
|
||||
/** for outputting the help messages. Forward accumulated
|
||||
* help messages from all contained option definitions */
|
||||
ostream& operator<< (ostream& os, const TestOption& to);
|
||||
|
||||
|
||||
} // namespace lumiera
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
mainsuite.cpp - "the" Lumiera self test suite
|
||||
mainsuite.cpp - execute a suite of test objects, possibly filtered by category
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Christian Thaeter <ct@pipapo.org>
|
||||
|
|
@ -32,7 +32,7 @@ using lumiera::ON_GLOBAL_SHUTDOWN;
|
|||
|
||||
|
||||
/** run all tests or any single test specified in the first
|
||||
* cmd line argument.
|
||||
* command line argument.
|
||||
* Note: to ease debugging, we don't catch any exceptions.
|
||||
*/
|
||||
int main (int argc, const char* argv[])
|
||||
|
|
|
|||
Loading…
Reference in a new issue