summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-07-29 23:46:08 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-07-29 23:46:08 +0100
commit142a5241eaa4ba041ea81edd68d6a40a68e2b293 (patch)
treeb9cca3567ed054efd75092cfd8f23f3fee1a8096
parentInline creation of DryIce for testing with different options (diff)
downloadicetray-142a5241eaa4ba041ea81edd68d6a40a68e2b293.tar.bz2
icetray-142a5241eaa4ba041ea81edd68d6a40a68e2b293.tar.xz
icetray-142a5241eaa4ba041ea81edd68d6a40a68e2b293.zip
Provide way of overriding a default value with an empty string
-rw-r--r--icetray/icetray/options.cpp9
-rw-r--r--icetray/unittests/testIceTrayOptions.cpp14
2 files changed, 22 insertions, 1 deletions
diff --git a/icetray/icetray/options.cpp b/icetray/icetray/options.cpp
index a12a7d0..dcc6bb0 100644
--- a/icetray/icetray/options.cpp
+++ b/icetray/icetray/options.cpp
@@ -46,7 +46,14 @@ namespace IceTray {
for (const auto & optDesc : all.options()) {
po::option opt;
opt.value = p->getPropertyAsList(optDesc->long_name());
- if (opt.value.empty()) continue;
+ if (opt.value.empty()) {
+ // If it was processed as an empty list and was empty, it wasn't there.
+ if (p->getProperty(optDesc->long_name()).empty()) {
+ continue;
+ }
+ // If it was process as an empty list but wasn't empty, treat as the empty string.
+ opt.value = { "" };
+ }
opt.string_key = optDesc->long_name();
opt.unregistered = false;
result.options.push_back(opt);
diff --git a/icetray/unittests/testIceTrayOptions.cpp b/icetray/unittests/testIceTrayOptions.cpp
index 3eb08fc..62f921a 100644
--- a/icetray/unittests/testIceTrayOptions.cpp
+++ b/icetray/unittests/testIceTrayOptions.cpp
@@ -30,3 +30,17 @@ BOOST_AUTO_TEST_CASE( testOptions )
BOOST_REQUIRE_EQUAL(8, myOpts->testVec[3]);
}
+BOOST_AUTO_TEST_CASE( overrideDefaultWithQuotesString )
+{
+ DI di({ R"C(--testString="some \"Quotes\" string")C" });
+ IceTray::OptionsResolver<TestOptions> myOpts;
+ BOOST_REQUIRE_EQUAL("some \"Quotes\" string", myOpts->testString);
+}
+
+BOOST_AUTO_TEST_CASE( overrideDefaultWithEmptyString )
+{
+ DI di({ R"C(--testString="")C" });
+ IceTray::OptionsResolver<TestOptions> myOpts;
+ BOOST_REQUIRE(myOpts->testString.empty());
+}
+