diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2012-04-11 10:58:51 +0200 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2012-04-11 10:58:57 +0200 |
commit | d577eeb36730bc5629bf2308703e58e733b01bfd (patch) | |
tree | 86df6e4688c4dd73a0d62da941d71e7c250ccbf9 | |
parent | c6c6d59b23af949ae54b0a14fcc7bf044083f14f (diff) |
command line: fixed error handling for invalid property assignmentsccs-pohly
xyz=1 triggered an error message with (null) inside instead of a
property name. The name is prominently given in the assignment
parameter, so just drop the explicit property name.
=1 triggered an error message with two single quotes instead of
one (because args are already passed with quotation marks) and then
crashed because of a missing return.
Also added unit tests...
-rw-r--r-- | src/syncevo/Cmdline.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/syncevo/Cmdline.cpp b/src/syncevo/Cmdline.cpp index bd3ffb5f..25209ef3 100644 --- a/src/syncevo/Cmdline.cpp +++ b/src/syncevo/Cmdline.cpp @@ -1712,11 +1712,16 @@ bool Cmdline::parseProp(PropertyType propertyType, boost::iequals(spec.m_property, "type")) { validProps = &m_validSourceProps; } else { - usage(false, StringPrintf("unrecognized property '%s' in %s", propname, args.c_str())); + if (propname) { + usage(false, StringPrintf("unrecognized property '%s' in %s", propname, args.c_str())); + } else { + usage(false, StringPrintf("unrecognized property in %s", args.c_str())); + } return false; } } else { - usage(false, StringPrintf("a property name must be given in '%s'", args.c_str())); + usage(false, StringPrintf("a property name must be given in %s", args.c_str())); + return false; } } @@ -3276,6 +3281,19 @@ protected: string(filter2.m_cmdline->m_props[""].m_sourceProps[""])); CPPUNIT_ASSERT_EQUAL_DIFF("", string(filter2.m_cmdline->m_props[""].m_syncProps)); + + TestCmdline filter3("--source-property", "xyz=1", NULL); + CPPUNIT_ASSERT(!filter3.m_cmdline->parse()); + CPPUNIT_ASSERT_EQUAL(string(""), filter3.m_out.str()); + CPPUNIT_ASSERT_EQUAL(string("[ERROR] '--source-property xyz=1': no such property\n"), filter3.m_err.str()); + + TestCmdline filter4("xyz=1", NULL); + CPPUNIT_ASSERT(!filter4.m_cmdline->parse()); + CPPUNIT_ASSERT_NO_THROW(filter4.expectUsageError("[ERROR] unrecognized property in 'xyz=1'\n")); + + TestCmdline filter5("=1", NULL); + CPPUNIT_ASSERT(!filter5.m_cmdline->parse()); + CPPUNIT_ASSERT_NO_THROW(filter5.expectUsageError("[ERROR] a property name must be given in '=1'\n")); } void testWebDAV() { |