Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SettingsManagerTest.cpp
Go to the documentation of this file.
1#include "test/storm_gtest.h"
2
9
10namespace {
11
12class SettingsParsingTestModule : public storm::settings::modules::ModuleSettings {
13 public:
14 static const std::string moduleName;
15
16 SettingsParsingTestModule() : ModuleSettings(moduleName) {
17 this->addOption(storm::settings::OptionBuilder("settingsparsing", "optiona", false, "Test option a.")
18 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("value", "The value.").build())
19 .build());
20 this->addOption(storm::settings::OptionBuilder("settingsparsing", "optionb", false, "Test option b.")
21 .setShortName("ob")
22 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("value", "The value.").build())
23 .build());
24 this->addOption(storm::settings::OptionBuilder("settingsparsing", "optionc", false, "Test option c.")
25 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("value", "The value.").build())
26 .build());
27 this->addOption(storm::settings::OptionBuilder("settingsparsing", "optiond", false, "Test option d.")
28 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("value", "The value.").build())
29 .build());
30 }
31
32 std::string getOptionString(std::string const& optionName) const {
33 return this->getOption(optionName).getArgumentByName("value").getValueAsString();
34 }
35};
36
37const std::string SettingsParsingTestModule::moduleName = "settingsparsing";
38
39bool ensureSettingsParsingTestModuleRegistered() {
40 if (!storm::settings::manager().hasModule("settingsparsing")) {
42 }
43 return true;
44}
45
46bool settingsParsingTestModuleRegistered = ensureSettingsParsingTestModuleRegistered();
47
48} // namespace
49
50TEST(SettingsManagerTest, ValueWithLeadingDashLongOption) {
51 storm::settings::mutableManager().setFromExplodedString({"--optiona", "-1 <= x <= 1"});
52 EXPECT_EQ("-1 <= x <= 1", storm::settings::getModule<SettingsParsingTestModule>().getOptionString("optiona"));
53}
54
55TEST(SettingsManagerTest, ValueWithLeadingDashShortOption) {
57 EXPECT_EQ("-1<=x<=1", storm::settings::getModule<SettingsParsingTestModule>().getOptionString("optionb"));
58}
59
60TEST(SettingsManagerTest, ValueWithLeadingDashFollowedByKnownOption) {
61 storm::settings::mutableManager().setFromExplodedString({"--optionc", "-1 <= x <= 1", "--verbose"});
62 EXPECT_EQ("-1 <= x <= 1", storm::settings::getModule<SettingsParsingTestModule>().getOptionString("optionc"));
63
64 // The "--verbose" option is only used here as a known option to test the parsing behavior. Setting it mutates the global
65 // settings manager, so we restore the defaults to avoid influencing other tests depending on the test execution order.
67}
68
69TEST(SettingsManagerTest, KnownOptionNotSwallowedAsValue) {
70 EXPECT_THROW({ storm::settings::mutableManager().setFromExplodedString({"--optiond", "--verbose"}); }, storm::exceptions::OptionParserException);
71}
TEST(SettingsManagerTest, ValueWithLeadingDashLongOption)
static ArgumentBuilder createStringArgument(std::string const &name, std::string const &description)
Creates a string argument with the given parameters.
void setFromExplodedString(std::vector< std::string > const &commandLineArguments)
This function parses the given command line arguments (represented by several strings) and sets all r...
modules::ModuleSettings const & getModule(std::string const &moduleName) const
Retrieves the settings of the module with the given name.
This is the base class of the settings for a particular module.
void restoreDefaults()
Restores the default values for all arguments of all options and marks all options as not set.
bool hasModule()
Returns true if the given module is registered.
SettingsType const & getModule()
Get module.
void addModule(bool doRegister=true)
Add new module to use for the settings.
SettingsManager const & manager()
Retrieves the settings manager.
SettingsManager & mutableManager()
Retrieves the settings manager.