Commit 1b4c1bee authored by Tom Perkins's avatar Tom Perkins
Browse files

Add test for non-numeric, non-string property

Test exceptions in both cases:
- string cannot be parsed
- not a numeric value or a string

Also add spaces to exception string.

re #17087
parent 80f596dc
......@@ -356,8 +356,8 @@ double LogManager::getPropertyAsSingleValue(
return std::stod(stringLog->value());
} catch (const std::invalid_argument &) {
throw std::invalid_argument(
"Run::getPropertyAsSingleValue - Property\"" + name +
"\"cannot be converted to a numeric value.");
"Run::getPropertyAsSingleValue - Property \"" + name +
"\" cannot be converted to a numeric value.");
}
} else {
throw std::invalid_argument(
......
......@@ -288,11 +288,21 @@ public:
doTest_GetPropertyAsSingleValue_TimeSeriesType<uint64_t>();
}
void
test_GetPropertyAsSingleValue_Throws_If_Type_Is_Not_Numeric_Or_TimeSeries_Numeric() {
void test_GetPropertyAsSingleValue_Throws_If_String_Is_Invalid() {
LogManager runInfo;
const std::string name = "string_prop";
runInfo.addProperty<std::string>(name, "hello"); // Adds a string property
runInfo.addProperty<std::string>(name, "hello"); // not a number
TS_ASSERT_THROWS(runInfo.getPropertyAsSingleValue(name),
std::invalid_argument);
}
void
test_GetPropertyAsSingleValue_Throws_If_Type_Is_Not_Numeric_Or_TimeSeries_Numeric_Or_Valid_String() {
LogManager runInfo;
const std::string name = "bool_prop";
const bool value(false);
runInfo.addProperty<bool>(name, value); // Adds a bool property
TS_ASSERT_THROWS(runInfo.getPropertyAsSingleValue(name),
std::invalid_argument);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment