forked from boostorg/core
more compared code following suggestion from Glen Fernandes and testing expected failures
This commit is contained in:
@ -102,6 +102,12 @@ inline void throw_failed_impl(char const * excep, char const * file, int line, c
|
|||||||
# pragma GCC diagnostic ignored "-Wsign-compare"
|
# pragma GCC diagnostic ignored "-Wsign-compare"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// specialize test output for char pointers to avoid printing as cstring
|
||||||
|
template <class T> inline const T& test_output_impl(const T& v) { return v; }
|
||||||
|
inline const void* test_output_impl(const char* v) { return v; }
|
||||||
|
inline const void* test_output_impl(const unsigned char* v) { return v; }
|
||||||
|
inline const void* test_output_impl(const signed char* v) { return v; }
|
||||||
|
|
||||||
template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
|
template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
|
||||||
char const * file, int line, char const * function, T const & t, U const & u )
|
char const * file, int line, char const * function, T const & t, U const & u )
|
||||||
{
|
{
|
||||||
@ -114,43 +120,7 @@ template<class T, class U> inline void test_eq_impl( char const * expr1, char co
|
|||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||||
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
||||||
<< "' failed in function '" << function << "': "
|
<< "' failed in function '" << function << "': "
|
||||||
<< "'" << t << "' != '" << u << "'" << std::endl;
|
<< "'" << test_output_impl(t) << "' != '" << test_output_impl(u) << "'" << std::endl;
|
||||||
++test_errors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// overloads for pointers compare and print addresses
|
|
||||||
template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
|
|
||||||
char const * file, int line, char const * function, const T* const t, const U* const u )
|
|
||||||
{
|
|
||||||
if( t == u )
|
|
||||||
{
|
|
||||||
report_errors_remind();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
|
||||||
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
|
||||||
<< "' failed in function '" << function << "': "
|
|
||||||
<< "'" << (const void*)t << "' != '" << (const void*)u << "'" << std::endl;
|
|
||||||
++test_errors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// impl for cstring
|
|
||||||
inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
|
|
||||||
char const * file, int line, char const * function, const char* const t, const char* const 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();
|
++test_errors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,16 +137,15 @@ template<class T, class U> inline void test_ne_impl( char const * expr1, char co
|
|||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||||
<< file << "(" << line << "): test '" << expr1 << " != " << expr2
|
<< file << "(" << line << "): test '" << expr1 << " != " << expr2
|
||||||
<< "' failed in function '" << function << "': "
|
<< "' failed in function '" << function << "': "
|
||||||
<< "'" << t << "' == '" << u << "'" << std::endl;
|
<< "'" << test_output_impl(t) << "' == '" << test_output_impl(u) << "'" << std::endl;
|
||||||
++test_errors();
|
++test_errors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// overloads for pointers compare and print addresses
|
inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
|
||||||
template<class T, class U> inline void test_ne_impl( char const * expr1, char const * expr2,
|
char const * file, int line, char const * function, char const * const t, char const * const u )
|
||||||
char const * file, int line, char const * function, const T* const t, const U* const u )
|
|
||||||
{
|
{
|
||||||
if( t != u )
|
if( std::strcmp(t, u) == 0 )
|
||||||
{
|
{
|
||||||
report_errors_remind();
|
report_errors_remind();
|
||||||
}
|
}
|
||||||
@ -185,14 +154,13 @@ template<class T, class U> inline void test_ne_impl( char const * expr1, char co
|
|||||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||||
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
||||||
<< "' failed in function '" << function << "': "
|
<< "' failed in function '" << function << "': "
|
||||||
<< "'" << (const void*)t << "' == '" << (const void*)u << "'" << std::endl;
|
<< "'" << t << "' != '" << u << "'" << std::endl;
|
||||||
++test_errors();
|
++test_errors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl for cstring
|
|
||||||
inline void test_cstr_ne_impl( char const * expr1, char const * expr2,
|
inline void test_cstr_ne_impl( char const * expr1, char const * expr2,
|
||||||
char const * file, int line, char const * function, const char* const t, const char* const u )
|
char const * file, int line, char const * function, char const * const t, char const * const u )
|
||||||
{
|
{
|
||||||
if( std::strcmp(t, u) != 0 )
|
if( std::strcmp(t, u) != 0 )
|
||||||
{
|
{
|
||||||
|
@ -76,6 +76,8 @@ run-fail lightweight_test_fail7.cpp ;
|
|||||||
run-fail lightweight_test_fail7.cpp : : : <rtti>off : lightweight_test_fail7_no_rtti ;
|
run-fail lightweight_test_fail7.cpp : : : <rtti>off : lightweight_test_fail7_no_rtti ;
|
||||||
run-fail lightweight_test_fail8.cpp ;
|
run-fail lightweight_test_fail8.cpp ;
|
||||||
run-fail lightweight_test_fail8.cpp : : : <rtti>off : lightweight_test_fail8_no_rtti ;
|
run-fail lightweight_test_fail8.cpp : : : <rtti>off : lightweight_test_fail8_no_rtti ;
|
||||||
|
run-fail lightweight_test_fail9.cpp ;
|
||||||
|
run-fail lightweight_test_fail10.cpp ;
|
||||||
|
|
||||||
run is_same_test.cpp ;
|
run is_same_test.cpp ;
|
||||||
|
|
||||||
|
18
test/lightweight_test_fail10.cpp
Normal file
18
test/lightweight_test_fail10.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Negative test for BOOST_TEST_EQ on const char*
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017 Hans Dembinski
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ("xab"+1 , "yab"+1); // compares addresses, not cstrings
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
18
test/lightweight_test_fail9.cpp
Normal file
18
test/lightweight_test_fail9.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Negative test for BOOST_TEST_CSTR_EQ
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017 Hans Dembinski
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST_CSTR_EQ("x" , "y");
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user