Browse Source

adding sloppy mode for Settings, load settings in tests

sloppy mode will not check for requirements of arguments.
this is somewhat ugly, as it might not even check for correct type (I'm not sure about that, as we only have strings right now), but it's only the tests-binary anyway...
tempestpy_adaptions
gereon 12 years ago
parent
commit
3a1b0f0433
  1. 8
      src/utility/Settings.cpp
  2. 8
      src/utility/Settings.h
  3. 35
      test/storm-tests.cpp

8
src/utility/Settings.cpp

@ -46,12 +46,12 @@ std::map< std::pair<std::string, std::string>, std::shared_ptr<bpo::options_desc
* @param argv should be argv passed to main function
* @param filename either nullptr or name of config file
*/
Settings::Settings(int const argc, char const * const argv[], char const * const filename) {
Settings::Settings(int const argc, char const * const argv[], char const * const filename, bool const sloppy) {
Settings::binaryName = std::string(argv[0]);
try {
// Initially fill description objects.
this->initDescriptions();
// Take care of positional arguments.
Settings::positional.add("trafile", 1);
Settings::positional.add("labfile", 1);
@ -97,7 +97,9 @@ Settings::Settings(int const argc, char const * const argv[], char const * const
this->secondRun(argc, argv, filename);
// Finalize parsed options, check for specified requirements.
bpo::notify(this->vm);
if (!sloppy) {
bpo::notify(this->vm);
}
LOG4CPLUS_DEBUG(logger, "Finished loading config.");
}
catch (bpo::reading_file e) {

8
src/utility/Settings.h

@ -122,13 +122,13 @@ namespace settings {
friend std::ostream& help(std::ostream& os);
friend std::ostream& helpConfigfile(std::ostream& os);
friend Settings* instance();
friend Settings* newInstance(int const argc, char const * const argv[], char const * const filename);
friend Settings* newInstance(int const argc, char const * const argv[], char const * const filename, bool const sloppy = false);
private:
/*!
* @brief Constructor.
*/
Settings(int const argc, char const * const argv[], char const * const filename);
Settings(int const argc, char const * const argv[], char const * const filename, bool const sloppy);
/*!
* @brief Initialize options_description object.
@ -200,9 +200,9 @@ namespace settings {
* @param filename either NULL or name of config file
* @return The new instance of Settings.
*/
inline Settings* newInstance(int const argc, char const * const argv[], char const * const filename) {
inline Settings* newInstance(int const argc, char const * const argv[], char const * const filename, bool const sloppy) {
if (Settings::inst != nullptr) delete Settings::inst;
Settings::inst = new Settings(argc, argv, filename);
Settings::inst = new Settings(argc, argv, filename, sloppy);
return Settings::inst;
}

35
test/storm-tests.cpp

@ -6,6 +6,9 @@
#include "log4cplus/consoleappender.h"
#include "log4cplus/fileappender.h"
#include "src/utility/Settings.h"
#include "src/modelChecker/GmmxxDtmcPrctlModelChecker.h"
log4cplus::Logger logger;
/*!
@ -25,8 +28,38 @@ void setUpLogging() {
// logger.addAppender(consoleLogAppender);
}
int main(int argc, char** argv) {
/*!
* Function that parses the command line options.
* @param argc The argc argument of main().
* @param argv The argv argument of main().
* @return True iff the program should continue to run after parsing the options.
*/
bool parseOptions(int const argc, char const * const argv[]) {
storm::settings::Settings* s = nullptr;
try {
storm::settings::Settings::registerModule<storm::modelChecker::GmmxxDtmcPrctlModelChecker<double>>();
s = storm::settings::newInstance(argc, argv, nullptr, true);
} catch (storm::exceptions::InvalidSettingsException& e) {
std::cout << "Could not recover from settings error: " << e.what() << "." << std::endl;
std::cout << std::endl << storm::settings::help;
delete s;
return false;
}
if (s->isSet("help")) {
std::cout << storm::settings::help;
delete s;
return false;
}
return true;
}
int main(int argc, char* argv[]) {
setUpLogging();
if (!parseOptions(argc, argv)) {
return 0;
}
std::cout << "STORM Testing Suite" << std::endl;
testing::InitGoogleTest(&argc, argv);

Loading…
Cancel
Save