mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2025-04-11 00:30:47 +00:00
When a test comparison fails, print the actual and expected values that did not match instead of the expressions in the code.
This requires a specialization of TestUtils::toString() for each distinct type, otherwise a generic message is used.
This commit is contained in:
parent
b5edffc0b6
commit
1fb6d03886
1 changed files with 24 additions and 2 deletions
|
@ -37,11 +37,17 @@ class TestUtils
|
|||
if (x != y)
|
||||
{
|
||||
throw "Actual and expected values differ. "
|
||||
"Actual: " + std::string(xString) +
|
||||
" Expected: " + std::string(yString);
|
||||
"Actual: " + toString(x,xString) +
|
||||
" Expected: " + toString(y,yString);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static std::string toString(T value, const char* context)
|
||||
{
|
||||
return "Unprintable: " + std::string(context);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static int runTest(class TestList<T>& tests) throw ()
|
||||
{
|
||||
|
@ -80,6 +86,22 @@ class TestUtils
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
inline std::string TestUtils::toString(const std::string& value, const char*)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
template <>
|
||||
inline std::string TestUtils::toString(std::string value, const char*)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
template <>
|
||||
inline std::string TestUtils::toString(const char* value, const char*)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
#define TEST_COMPARE(x,y) \
|
||||
TestUtils::compare(x,y,#x,#y);
|
||||
|
||||
|
|
Loading…
Reference in a new issue