diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-12-16 07:53:47 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2013-12-16 07:59:07 +0100 |
commit | 3d7c66d75de3e5d14332976a21573aa5d4c3a74c (patch) | |
tree | df1f18a1ff539c679cdba9ef2b09572482bf679c | |
parent | a5a65bbc90890fa4532313beec1b1b422f7a5c81 (diff) | |
parent | 0205abd83d8f8dcbe453440a3fa4e494b71704e8 (diff) |
Merge pull request #3423
0205abd 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.) (Kangmo)
-rw-r--r-- | src/test/serialize_tests.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index 885a91658d..415f957811 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -61,11 +61,13 @@ BOOST_AUTO_TEST_CASE(compactsize) static bool isCanonicalException(const std::ios_base::failure& ex) { - std::string strExplanatoryString("non-canonical ReadCompactSize()"); + std::ios_base::failure expectedException("non-canonical ReadCompactSize()"); - return strExplanatoryString == ex.what() || - // OSX Apple LLVM version 5.0 (OSX 10.9) - strExplanatoryString + ": unspecified iostream_category error" == ex.what(); + // The string returned by what() can be different for different platforms. + // Instead of directly comparing the ex.what() with an expected string, + // create an instance of exception to see if ex.what() matches + // the expected explanatory string returned by the exception instance. + return strcmp(expectedException.what(), ex.what()) == 0; } |