From b4178ae888e5f3bd3c326d3130ed11a2b44eb73d Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Sun, 4 Dec 2016 16:13:50 +0100 Subject: [PATCH] Test macros: be more rigorous and consistent - Because of possible operator overloading, make SG_CHECK_EQUAL(a, b) fail if, and only if (a) == (b) is false (testing if (a) != (b) for this macro is not correct in general). - For clarity and consistency, change the messages printed when some tests fail: SG_VERIFY(some_test) prints 'failed: some_test' (okay), but SG_CHECK_EQUAL(a, b) used to print 'failed: a != b', which is inconsistent. Instead, print: 'failed: a == b' because this is what we know that failed (again, because of possible operator overloading, pretending we know the the logical value of (a != b) after testing (a == b) is not correct in general. Similarly, the "approximate equality tests" SG_CHECK_EQUAL_EP() and SG_CHECK_EQUAL_EP2() now print something like 'failed: a ~= b' when they fail, instead of 'failed with epsilon: a != b'. --- simgear/misc/test_macros.hxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/simgear/misc/test_macros.hxx b/simgear/misc/test_macros.hxx index 4e6e5a94..7ba18d06 100644 --- a/simgear/misc/test_macros.hxx +++ b/simgear/misc/test_macros.hxx @@ -13,8 +13,8 @@ } #define SG_CHECK_EQUAL(a, b) \ - if ((a) != (b)) { \ - std::cerr << "failed: " << #a << " != " << #b << std::endl; \ + if ( !((a) == (b)) ) { \ + std::cerr << "failed: " << #a << " == " << #b << std::endl; \ std::cerr << "\tgot '" << a << "' and '" << b << "'" << std::endl; \ std::cerr << "\tat " << __FILE__ << ":" << __LINE__ << std::endl; \ exit(1); \ @@ -22,7 +22,7 @@ #define SG_CHECK_EQUAL_EP(a, b) \ if (std::fabs((a) - (b)) > SG_EPSILON) { \ - std::cerr << "failed with epsilon: " << #a << " != " << #b << std::endl; \ + std::cerr << "failed: " << #a << " ~= " << #b << std::endl; \ std::cerr << "\tgot '" << a << "' and '" << b << "'" << std::endl; \ std::cerr << "\tat " << __FILE__ << ":" << __LINE__ << std::endl; \ exit(1); \ @@ -30,7 +30,7 @@ #define SG_CHECK_EQUAL_EP2(a, b, ep) \ if (std::fabs((a) - (b)) > ep) { \ - std::cerr << "failed with epsilon: " << #a << " != " << #b << std::endl; \ + std::cerr << "failed: " << #a << " ~= " << #b << std::endl; \ std::cerr << "\tgot '" << a << "' and '" << b << "'" << std::endl; \ std::cerr << "\tat " << __FILE__ << ":" << __LINE__ << std::endl; \ exit(1); \