From cdee8e76c506f68d4493a6d3062944d46ce78600 Mon Sep 17 00:00:00 2001 From: "hans.dembinski@gmail.com" Date: Sun, 5 Feb 2017 19:06:21 +0000 Subject: [PATCH] fix for trac issue #12814, including a new test for the issue --- include/boost/core/lightweight_test.hpp | 37 +++++++++++++++++++++++++ test/lightweight_test_test.cpp | 5 ++++ 2 files changed, 42 insertions(+) diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index d6db024..e084b35 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -23,6 +23,7 @@ #include #include #include +#include // IDE's like Visual Studio perform better if output goes to std::cout or // some other stream, so allow user to configure output stream: @@ -118,6 +119,24 @@ template inline void test_eq_impl( char const * expr1, char co } } +// overload for const char* +inline void test_eq_impl( char const * expr1, char const * expr2, + char const * file, int line, char const * function, const char* t, const char* u ) +{ + if( std::strcmp(t, u) == 0 ) + { + report_errors_remind(); + } + else + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr1 << " == " << expr2 + << "' failed in function '" << function << "': " + << "'" << t << "' != '" << u << "'" << std::endl; + ++test_errors(); + } +} + template inline void test_ne_impl( char const * expr1, char const * expr2, char const * file, int line, char const * function, T const & t, U const & u ) { @@ -135,6 +154,24 @@ template inline void test_ne_impl( char const * expr1, char co } } +// overload for const char* +inline void test_ne_impl( char const * expr1, char const * expr2, + char const * file, int line, char const * function, const char* t, const char* u ) +{ + if( std::strcmp(t, u) != 0 ) + { + report_errors_remind(); + } + else + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr1 << " == " << expr2 + << "' failed in function '" << function << "': " + << "'" << t << "' == '" << u << "'" << std::endl; + ++test_errors(); + } +} + #if defined(_MSC_VER) # pragma warning(pop) #elif defined(__clang__) && defined(__has_warning) diff --git a/test/lightweight_test_test.cpp b/test/lightweight_test_test.cpp index d4808a1..be87950 100644 --- a/test/lightweight_test_test.cpp +++ b/test/lightweight_test_test.cpp @@ -65,10 +65,15 @@ int main() BOOST_TEST_EQ( ++x, ++y ); BOOST_TEST_EQ( x++, y++ ); + const char* s1 = "abc"; // make sure addresses are different + const char* s2 = "abc"; // make sure addresses are different + BOOST_TEST_EQ(s1, s2); + // BOOST_TEST_NE BOOST_TEST_NE( ++x, y ); BOOST_TEST_NE( &x, &y ); + BOOST_TEST_NE( "abc", "ABC" ); // BOOST_TEST_THROWS