diff --git a/src/common/test/testoption.cpp b/src/common/test/testoption.cpp index 064c3b6d3..d898eaef9 100644 --- a/src/common/test/testoption.cpp +++ b/src/common/test/testoption.cpp @@ -1,5 +1,5 @@ /* - Suite - handle cmdline for invoking Testsuite + TestOption - handle cmdline for invoking Testsuite Copyright (C) Lumiera.org 2008, Hermann Vosseler @@ -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 @@ -56,7 +56,7 @@ namespace test ("group,g", op::value()->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(), "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")) diff --git a/src/common/test/testoption.hpp b/src/common/test/testoption.hpp index 31b69ff24..0bdb9f616 100644 --- a/src/common/test/testoption.hpp +++ b/src/common/test/testoption.hpp @@ -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); diff --git a/src/lib/cmdline.cpp b/src/lib/cmdline.cpp index a2d62c19a..f2105394a 100644 --- a/src/lib/cmdline.cpp +++ b/src/lib/cmdline.cpp @@ -50,8 +50,8 @@ using boost::regex_search; namespace util { - /** create as a tokenized copy of the current commandline. - * Note that argv[0] is allways ignored. */ + /** create as a tokenised copy of the current commandline. + * Note that argv[0] is always ignored. */ Cmdline::Cmdline (int argc, const char** argv) : vector (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) diff --git a/src/lib/lifecycleregistry.hpp b/src/lib/lifecycleregistry.hpp index 88f8b9f63..32f5aa91b 100644 --- a/src/lib/lifecycleregistry.hpp +++ b/src/lib/lifecycleregistry.hpp @@ -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... /** diff --git a/src/lumiera/main.cpp b/src/lumiera/main.cpp index 7c310ada4..1905a64c1 100644 --- a/src/lumiera/main.cpp +++ b/src/lumiera/main.cpp @@ -24,23 +24,63 @@ #include -#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; + } diff --git a/src/lumiera/option.cpp b/src/lumiera/option.cpp new file mode 100644 index 000000000..cabedf9e3 --- /dev/null +++ b/src/lumiera/option.cpp @@ -0,0 +1,123 @@ +/* + Option - handle cmdline for starting the Lumiera application + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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()->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(), + "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(); + } + + /** @return ID of a single test to run, empty string if not specified + */ + const string + Option::getTestID () + { + if (parameters.count ("id") && + parameters["id"].as().size() > 0) + return parameters["id"].as()[0]; + else + return string (); + } + + /** @return \c true if --describe switch was given */ + const bool + Option::getDescribe () + { + return parameters["describe"].as(); + } + + + + ostream& + operator<< (ostream& os, const TestOption& to) + { + return os << to.syntax; + } + + + +} // namespace lumiera diff --git a/src/lumiera/option.hpp b/src/lumiera/option.hpp new file mode 100644 index 000000000..6bcacb47a --- /dev/null +++ b/src/lumiera/option.hpp @@ -0,0 +1,75 @@ +/* + OPTION.hpp - handle cmdline for starting the Lumiera application + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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 +#include +#include +#include + + + +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 diff --git a/tests/common/mainsuite.cpp b/tests/common/mainsuite.cpp index 562dc264c..92db417e3 100644 --- a/tests/common/mainsuite.cpp +++ b/tests/common/mainsuite.cpp @@ -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 @@ -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[])