diff --git a/assert.html b/assert.html index 5f3f6e7..4723ff8 100644 --- a/assert.html +++ b/assert.html @@ -2,12 +2,12 @@ Boost: assert.hpp documentation - + -
boost.png (6897 bytes) + boost.png (6897 bytes)

assert.hpp

@@ -18,31 +18,32 @@

- BOOST_ASSERT
- BOOST_ASSERT_MSG
- BOOST_VERIFY

+ BOOST_ASSERT
+ BOOST_ASSERT_MSG
+ BOOST_VERIFY
+ BOOST_VERIFY_MSG
+

BOOST_ASSERT

- The header <boost/assert.hpp> defines the macro BOOST_ASSERT, - which is similar to the standard assert macro defined in <cassert>. + The header <boost/assert.hpp> defines the macro BOOST_ASSERT, + which is similar to the standard assert macro defined in <cassert>. The macro is intended to be used in both Boost libraries and user code.

-

By default, BOOST_ASSERT(expr) is equivalent to assert(expr).

-

If the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> - is included, BOOST_ASSERT(expr) is defined as ((void)0). This - allows users to selectively disable BOOST_ASSERT without - affecting the definition of the standard assert.

-

If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> - is included, BOOST_ASSERT(expr) evaluates expr and, if the - result is false, evaluates the expression

+

• By default, BOOST_ASSERT(expr) expands to assert(expr).

+

• If the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> + is included, BOOST_ASSERT(expr) expands to ((void)0), regardless of whether + the macro NDEBUG is defined. This allows users to selectively disable BOOST_ASSERT without + affecting the definition of the standard assert.

+

• If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_ASSERT(expr) expands to

-

::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, - __FILE__, __LINE__)

-
-

assertion_failed is declared in <boost/assert.hpp> - as

+
(BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
+ +

That is, it evaluates expr and if it's false, calls ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__). + This is true regardless of whether NDEBUG is defined.

+

boost::assertion_failed is declared in <boost/assert.hpp> as

namespace boost
 {
@@ -52,40 +53,28 @@
 		

but it is never defined. The user is expected to supply an appropriate definition.

-

As is the case with <cassert>, <boost/assert.hpp> - can be included multiple times in a single translation unit. BOOST_ASSERT - will be redefined each time as specified above.

+

• If the macro BOOST_ENABLE_ASSERT_DEBUG_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_ASSERT(expr) expands to ((void)0) when NDEBUG is + defined. Otherwise the behavior is as if BOOST_ENABLE_ASSERT_HANDLER has been defined.

+

As is the case with <cassert>, <boost/assert.hpp> + can be included multiple times in a single translation unit. BOOST_ASSERT + will be redefined each time as specified above.

BOOST_ASSERT_MSG

- The header <boost/assert.hpp> defines the macro BOOST_ASSERT_MSG, - which is similar to the standard assert macro defined in <cassert>, - but with an additional macro parameter supplying an error message. The macro is intended to be used in both Boost libraries - and user code. -

-

BOOST_ASSERT_MSG(expr, msg) is equivalent to - ((void)0) if BOOST_DISABLE_ASSERTS or NDEBUG are - defined or expr evaluates to true. If those - macros and BOOST_ENABLE_ASSERT_HANDLER are not - defined, and expr evaluates to false, an error - message that includes #expr, msg, BOOST_CURRENT_FUNCTION, - __FILE__, and __LINE__ is sent to output stream - BOOST_ASSERT_MSG_OSTREAM - and std::abort() is called.

-

BOOST_ASSERT_MSG_OSTREAM defines the output stream. It defaults to std::cerr. - Integrated development environments (IDE's) like Microsoft Visual Studio - may produce easier to understand output if messages go to a different - stream, such as std::cout. Users may define BOOST_ASSERT_MSG_OSTREAM before including <boost/assert.hpp> - to specify a different output stream. 

-

If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> - is included, instead of sending a error message to an output - stream, this expression is evaluated

+ The macro BOOST_ASSERT_MSG is similar to BOOST_ASSERT, but it takes an additional argument, + a character literal, supplying an error message.

+

• By default, BOOST_ASSERT_MSG(expr,msg) expands to assert((expr)&&(msg)).

+

• If the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> + is included, BOOST_ASSERT_MSG(expr,msg) expands to ((void)0), regardless of whether + the macro NDEBUG is defined.

+

• If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_ASSERT_MSG(expr,msg) expands to

-

::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, - __FILE__, __LINE__)

-
-

assertion_failed_msg is declared in <boost/assert.hpp> - as

+
(BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
+ +

This is true regardless of whether NDEBUG is defined.

+

boost::assertion_failed_msg is declared in <boost/assert.hpp> as

namespace boost
 {
@@ -95,21 +84,38 @@
 		

but it is never defined. The user is expected to supply an appropriate definition.

-

As is the case with <cassert>, <boost/assert.hpp> - can be included multiple times in a single translation unit. BOOST_ASSERT_MSG - will be redefined each time as specified above.

+

• If the macro BOOST_ENABLE_ASSERT_DEBUG_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_ASSERT_MSG(expr) expands to ((void)0) when NDEBUG is + defined. Otherwise the behavior is as if BOOST_ENABLE_ASSERT_HANDLER has been defined.

+

As is the case with <cassert>, <boost/assert.hpp> + can be included multiple times in a single translation unit. BOOST_ASSERT_MSG + will be redefined each time as specified above.

BOOST_VERIFY

-

<boost/assert.hpp> also defines the macro BOOST_VERIFY. - It has exactly the same behavior as BOOST_ASSERT, except that - the expression that is passed to BOOST_VERIFY is always +

The macro BOOST_VERIFY has the same behavior as BOOST_ASSERT, except that + the expression that is passed to BOOST_VERIFY is always evaluated. This is useful when the asserted expression has desirable side effects; it can also help suppress warnings about unused variables when the only use of the variable is inside an assertion.

-


- Copyright © 2002, 2007 by Peter Dimov.  Copyright © 2011 +

• If the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> + is included, BOOST_VERIFY(expr) expands to ((void)(expr)).

+

• If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_VERIFY(expr) expands to BOOST_ASSERT(expr).

+

• Otherwise, BOOST_VERIFY(expr) expands to ((void)(expr)) when NDEBUG is + defined, to BOOST_ASSERT(expr) when it's not.

+

BOOST_VERIFY_MSG

+

The macro BOOST_VERIFY_MSG is similar to BOOST_VERIFY, with an additional parameter, an error message.

+

• If the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> + is included, BOOST_VERIFY_MSG(expr,msg) expands to ((void)(expr)).

+

• If the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> + is included, BOOST_VERIFY_MSG(expr,msg) expands to BOOST_ASSERT_MSG(expr,msg).

+

• Otherwise, BOOST_VERIFY_MSG(expr,msg) expands to ((void)(expr)) when NDEBUG is + defined, to BOOST_ASSERT_MSG(expr,msg) when it's not.

+
+

+ Copyright © 2002, 2007, 2014 by Peter Dimov.  Copyright © 2011 by Beman Dawes. 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.

+ License, Version 1.0. See accompanying file LICENSE_1_0.txt + or copy at http://www.boost.org/LICENSE_1_0.txt.

- \ No newline at end of file + diff --git a/current_function.html b/current_function.html index 373eb22..f7f6515 100644 --- a/current_function.html +++ b/current_function.html @@ -2,12 +2,12 @@ Boost: current_function.hpp documentation - + -
boost.png (6897 bytes) + boost.png (6897 bytes)

current_function.hpp

@@ -18,19 +18,20 @@

- The header <boost/current_function.hpp> defines a single - macro, BOOST_CURRENT_FUNCTION, similar to the - C99 predefined identifier __func__. + The header <boost/current_function.hpp> defines a single + macro, BOOST_CURRENT_FUNCTION, similar to the + C99 predefined identifier __func__.

-

BOOST_CURRENT_FUNCTION expands to a string literal containing +

BOOST_CURRENT_FUNCTION expands to a string literal containing the (fully qualified, if possible) name of the enclosing function. If there is - no enclosing function, the behavior is undefined.

+ no enclosing function, the behavior is undefined.

Some compilers do not provide a way to obtain the name of the current enclosing - function. On such compilers, the string literal has an unspecified value.

+ function. On such compilers, BOOST_CURRENT_FUNCTION expands to + "(unknown)".

+

-
Copyright © 2002 by Peter Dimov. 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.

+ 1.0. See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt.

diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index ccc776a..595e6d5 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -2,18 +2,19 @@ // boost/assert.hpp - BOOST_ASSERT(expr) // BOOST_ASSERT_MSG(expr, msg) // BOOST_VERIFY(expr) +// BOOST_VERIFY_MSG(expr, msg) // // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. -// Copyright (c) 2007 Peter Dimov +// Copyright (c) 2007, 2014 Peter Dimov // Copyright (c) Beman Dawes 2011 // -// 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) +// 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 // // Note: There are no include guards. This is intentional. // -// See http://www.boost.org/libs/utility/assert.html for documentation. +// See http://www.boost.org/libs/assert/assert.html for documentation. // // @@ -22,62 +23,60 @@ // boostinspect:naassert_macro // -//--------------------------------------------------------------------------------------// -// BOOST_ASSERT // -//--------------------------------------------------------------------------------------// +// +// BOOST_ASSERT +// #undef BOOST_ASSERT -#if defined(BOOST_DISABLE_ASSERTS) +#if defined(BOOST_DISABLE_ASSERTS) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && defined(NDEBUG) ) # define BOOST_ASSERT(expr) ((void)0) -#elif defined(BOOST_ENABLE_ASSERT_HANDLER) +#elif defined(BOOST_ENABLE_ASSERT_HANDLER) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG) ) #include #include namespace boost { - void assertion_failed(char const * expr, - char const * function, char const * file, long line); // user defined + void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined } // namespace boost -#define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr)) \ - ? ((void)0) \ - : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) +#define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) #else # include // .h to support old libraries w/o - effect is the same # define BOOST_ASSERT(expr) assert(expr) #endif -//--------------------------------------------------------------------------------------// -// BOOST_ASSERT_MSG // -//--------------------------------------------------------------------------------------// +// +// BOOST_ASSERT_MSG +// -# undef BOOST_ASSERT_MSG +#undef BOOST_ASSERT_MSG -#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG) +#if defined(BOOST_DISABLE_ASSERTS) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && defined(NDEBUG) ) - #define BOOST_ASSERT_MSG(expr, msg) ((void)0) +# define BOOST_ASSERT_MSG(expr, msg) ((void)0) -#elif defined(BOOST_ENABLE_ASSERT_HANDLER) +#elif defined(BOOST_ENABLE_ASSERT_HANDLER) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG) ) - #include - #include +#include +#include - namespace boost - { - void assertion_failed_msg(char const * expr, char const * msg, - char const * function, char const * file, long line); // user defined - } // namespace boost +namespace boost +{ + void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line); // user defined +} // namespace boost - #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr)) \ - ? ((void)0) \ - : ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) +#define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) #else +# include +# define BOOST_ASSERT_MSG(expr, msg) assert((expr)&&(msg)) + +/* #ifndef BOOST_ASSERT_HPP #define BOOST_ASSERT_HPP #include @@ -122,11 +121,12 @@ namespace boost ? ((void)0) \ : ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \ BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) +*/ #endif -//--------------------------------------------------------------------------------------// -// BOOST_VERIFY // -//--------------------------------------------------------------------------------------// +// +// BOOST_VERIFY +// #undef BOOST_VERIFY @@ -139,3 +139,19 @@ namespace boost # define BOOST_VERIFY(expr) BOOST_ASSERT(expr) #endif + +// +// BOOST_VERIFY_MSG +// + +#undef BOOST_VERIFY_MSG + +#if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) + +# define BOOST_VERIFY_MSG(expr, msg) ((void)(expr)) + +#else + +# define BOOST_VERIFY_MSG(expr, msg) BOOST_ASSERT_MSG(expr,msg) + +#endif diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index cb36e35..5c113f8 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -12,11 +12,11 @@ // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // -// 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) +// 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 // -// http://www.boost.org/libs/utility/current_function.html +// http://www.boost.org/libs/assert/current_function.html // namespace boost @@ -52,6 +52,10 @@ inline void current_function_helper() # define BOOST_CURRENT_FUNCTION __func__ +#elif defined(__cplusplus) && (__cplusplus >= 201103) + +# define BOOST_CURRENT_FUNCTION __func__ + #else # define BOOST_CURRENT_FUNCTION "(unknown)" @@ -65,4 +69,3 @@ inline void current_function_helper() } // namespace boost #endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED - diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6cb6e23..4993ed9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -14,4 +14,9 @@ test-suite "assert" [ run assert_test.cpp ] [ run current_function_test.cpp : : : always_show_run_output ] [ run verify_test.cpp ] + # expansion tests are in exp/ so that there is a backslash in the path on Windows + [ run exp/assert_exp_test.cpp ] + [ run exp/assert_msg_exp_test.cpp ] + [ run exp/verify_exp_test.cpp ] + [ run exp/verify_msg_exp_test.cpp ] ; diff --git a/test/exp/assert_exp_test.cpp b/test/exp/assert_exp_test.cpp new file mode 100644 index 0000000..c56cdef --- /dev/null +++ b/test/exp/assert_exp_test.cpp @@ -0,0 +1,164 @@ +// +// assert_exp_test.cpp - tests BOOST_ASSERT expansion +// +// Copyright (c) 2014 Peter Dimov +// +// 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 +#include +#include +#include + +// Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled +static std::string quote( std::string const & s ) +{ + std::string r; + r.reserve( s.size() ); + + for( char const * p = s.c_str(); *p; ++p ) + { + r += *p; + if( *p == '\\' ) r += *p; + } + + return r; +} + +// default case, !NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#undef NDEBUG +#include +#undef assert + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT(x1)); + BOOST_TEST_EQ( v1, "assert(x1)" ); +} + +// default case, NDEBUG +// BOOST_ASSERT(x) -> assert(x) + +#define NDEBUG +#include +#undef assert + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT(x2)); + BOOST_TEST_EQ( v2, "assert(x2)" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT(x3)); + BOOST_TEST_EQ( v3, "((void)0)" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT(x4)); + BOOST_TEST_EQ( v4, "((void)0)" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#undef BOOST_LIKELY +#undef BOOST_CURRENT_FUNCTION + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT(x5)); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed(\"x5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler()"; + BOOST_TEST_EQ( v5, w5 ); +} + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#define NDEBUG +#include + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT(x6)); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed(\"x6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()"; + BOOST_TEST_EQ( v6, w6 ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT(x7)); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed(\"x7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()"; + BOOST_TEST_EQ( v7, w7 ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT(x) -> ((void)0) + +#define NDEBUG +#include + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT(x8)); + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()"; + BOOST_TEST_EQ( v8, "((void)0)" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/test/exp/assert_msg_exp_test.cpp b/test/exp/assert_msg_exp_test.cpp new file mode 100644 index 0000000..faff616 --- /dev/null +++ b/test/exp/assert_msg_exp_test.cpp @@ -0,0 +1,164 @@ +// +// assert_msg_exp_test.cpp - tests BOOST_ASSERT_MSG expansion +// +// Copyright (c) 2014 Peter Dimov +// +// 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 +#include +#include +#include + +// Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled +static std::string quote( std::string const & s ) +{ + std::string r; + r.reserve( s.size() ); + + for( char const * p = s.c_str(); *p; ++p ) + { + r += *p; + if( *p == '\\' ) r += *p; + } + + return r; +} + +// default case, !NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> assert((x)&&("m")) + +#undef NDEBUG +#include +#undef assert + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x1, "m1")); + BOOST_TEST_EQ( v1, "assert((x1)&&(\"m1\"))" ); +} + +// default case, NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> assert((x)&&("m")) + +#define NDEBUG +#include +#undef assert + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x2, "m2")); + BOOST_TEST_EQ( v2, "assert((x2)&&(\"m2\"))" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> ((void)0) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x3, "m3")); + BOOST_TEST_EQ( v3, "((void)0)" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> ((void)0) + +#define NDEBUG +#include + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x4, "m4")); + BOOST_TEST_EQ( v4, "((void)0)" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_ASSERT_MSG(expr, msg) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#undef BOOST_LIKELY +#undef BOOST_CURRENT_FUNCTION + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x5, "m5")); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed_msg(\"x5\", \"m5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler()"; + BOOST_TEST_EQ( v5, w5 ); +} + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_ASSERT_MSG(expr, msg) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) + +#define NDEBUG +#include + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x6, "m6")); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed_msg(\"x6\", \"m6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()"; + BOOST_TEST_EQ( v6, w6 ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// same as BOOST_ENABLE_ASSERT_HANDLER + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x7, "m7")); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed_msg(\"x7\", \"m7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()"; + BOOST_TEST_EQ( v7, w7 ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_ASSERT_MSG(x,"m") -> ((void)0) + +#define NDEBUG +#include + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x8, "m8")); + + char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()"; + BOOST_TEST_EQ( v8, "((void)0)" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/test/exp/verify_exp_test.cpp b/test/exp/verify_exp_test.cpp new file mode 100644 index 0000000..844513b --- /dev/null +++ b/test/exp/verify_exp_test.cpp @@ -0,0 +1,136 @@ +// +// verify_exp_test.cpp - tests BOOST_ASSERT expansion +// +// Copyright (c) 2014 Peter Dimov +// +// 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 +#include +#include +#include + +// default case, !NDEBUG +// BOOST_VERIFY(x) -> BOOST_ASSERT(x) + +#undef NDEBUG +#include +#undef BOOST_ASSERT + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY(x1)); + BOOST_TEST_EQ( v1, "BOOST_ASSERT(x1)" ); +} + +// default case, NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#define NDEBUG +#include + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY(x2)); + BOOST_TEST_EQ( v2, "((void)(x2))" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#define BOOST_DISABLE_ASSERTS +#undef NDEBUG +#include + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY(x3)); + BOOST_TEST_EQ( v3, "((void)(x3))" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#undef NDEBUG +#include + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY(x4)); + BOOST_TEST_EQ( v4, "((void)(x4))" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_VERIFY(x) -> BOOST_ASSERT(x) + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include +#undef BOOST_ASSERT + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY(x5)); + BOOST_TEST_EQ( v5, "BOOST_ASSERT(x5)" ); +} + +#define NDEBUG +#include +#undef BOOST_ASSERT + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY(x6)); + BOOST_TEST_EQ( v6, "BOOST_ASSERT(x6)" ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// BOOST_VERIFY(x) -> BOOST_ASSERT(x) + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include +#undef BOOST_ASSERT + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY(x7)); + BOOST_TEST_EQ( v7, "BOOST_ASSERT(x7)" ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_VERIFY(x) -> ((void)(x)) + +#define NDEBUG +#include + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY(x8)); + BOOST_TEST_EQ( v8, "((void)(x8))" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +} diff --git a/test/exp/verify_msg_exp_test.cpp b/test/exp/verify_msg_exp_test.cpp new file mode 100644 index 0000000..02090fe --- /dev/null +++ b/test/exp/verify_msg_exp_test.cpp @@ -0,0 +1,140 @@ +// +// verify_msg_exp_test.cpp - tests BOOST_VERIFY_MSG expansion +// +// Copyright (c) 2014 Peter Dimov +// +// 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 +#include +#include +#include + +// default case, !NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> BOOST_ASSERT_MSG(x,"m") + +#undef NDEBUG +#include +#undef BOOST_ASSERT_MSG + +void test_default() +{ + std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x1, m1)); + BOOST_TEST_EQ( v1, "BOOST_ASSERT_MSG(x1,m1)" ); +} + +// default case, NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define NDEBUG +#include + +void test_default_ndebug() +{ + std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x2, m2)); + BOOST_TEST_EQ( v2, "((void)(x2))" ); +} + +// BOOST_DISABLE_ASSERTS, !NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define BOOST_DISABLE_ASSERTS + +#undef NDEBUG +#include + +void test_disabled() +{ + std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x3, "m3")); + BOOST_TEST_EQ( v3, "((void)(x3))" ); +} + +// BOOST_DISABLE_ASSERTS, NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define NDEBUG +#include + +void test_disabled_ndebug() +{ + std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x4, "m4")); + BOOST_TEST_EQ( v4, "((void)(x4))" ); +} + +#undef BOOST_DISABLE_ASSERTS + +// BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG +// BOOST_VERIFY_MSG(x,m) -> BOOST_ASSERT_MSG(x,m) + +#define BOOST_ENABLE_ASSERT_HANDLER + +#undef NDEBUG +#include +#undef BOOST_ASSERT_MSG + +void test_handler() +{ + std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x5, m5)); + BOOST_TEST_EQ( v5, "BOOST_ASSERT_MSG(x5,m5)" ); +} + +// BOOST_ENABLE_ASSERT_HANDLER, NDEBUG +// BOOST_VERIFY_MSG(x,n) -> BOOST_ASSERT_MSG(x,m) + +#define NDEBUG +#include +#undef BOOST_ASSERT_MSG + +void test_handler_ndebug() +{ + std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x6, m6)); + BOOST_TEST_EQ( v6, "BOOST_ASSERT_MSG(x6,m6)" ); +} + +#undef BOOST_ENABLE_ASSERT_HANDLER + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG +// BOOST_VERIFY_MSG(x,n) -> BOOST_ASSERT_MSG(x,m) + +#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +#undef NDEBUG +#include +#undef BOOST_ASSERT_MSG + +void test_debug_handler() +{ + std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x7, m7)); + BOOST_TEST_EQ( v7, "BOOST_ASSERT_MSG(x7,m7)" ); +} + +// BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG +// BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) + +#define NDEBUG +#include + +void test_debug_handler_ndebug() +{ + std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x8, "m8")); + BOOST_TEST_EQ( v8, "((void)(x8))" ); +} + +#undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER + +int main() +{ + test_default(); + test_default_ndebug(); + test_disabled(); + test_disabled_ndebug(); + test_handler(); + test_handler_ndebug(); + test_debug_handler(); + test_debug_handler_ndebug(); + + return boost::report_errors(); +}