Skip to content

Commit 0205abd

Browse files
author
Kangmo
committed
Improve unit test code not to compare with explanatory messages for each platform.
Instead, use have an exception object to check if the string returned by what() on the raised exception matches the string returned by what() on the expected exception instance. This way, we do not need to list all different possible explanatory strings for different platforms in the test code, and make it simple. (The idea is by Cory Fields.)
1 parent bccd532 commit 0205abd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/test/serialize_tests.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ BOOST_AUTO_TEST_CASE(compactsize)
6161

6262
static bool isCanonicalException(const std::ios_base::failure& ex)
6363
{
64-
std::string strExplanatoryString("non-canonical ReadCompactSize()");
64+
std::ios_base::failure expectedException("non-canonical ReadCompactSize()");
6565

66-
return strExplanatoryString == ex.what() ||
67-
// OSX Apple LLVM version 5.0 (OSX 10.9)
68-
strExplanatoryString + ": unspecified iostream_category error" == ex.what();
66+
// The string returned by what() can be different for different platforms.
67+
// Instead of directly comparing the ex.what() with an expected string,
68+
// create an instance of exception to see if ex.what() matches
69+
// the expected explanatory string returned by the exception instance.
70+
return strcmp(expectedException.what(), ex.what()) == 0;
6971
}
7072

7173

0 commit comments

Comments
 (0)