From e47d4e0cbf0e12686e568a20e269fe0f8e34e406 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 16 Aug 2002 16:41:16 +0000 Subject: [PATCH 01/14] Switched to for testing. [SVN r14932] --- include/boost/detail/lightweight_test.hpp | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 include/boost/detail/lightweight_test.hpp diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp new file mode 100644 index 0000000..2b33580 --- /dev/null +++ b/include/boost/detail/lightweight_test.hpp @@ -0,0 +1,74 @@ +#ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED +#define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED + +#if _MSC_VER >= 1020 +#pragma once +#endif + +// +// boost/detail/lightweight_test.hpp - lightweight test library +// +// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// +// BOOST_TEST(expression) +// BOOST_ERROR(message) +// +// int boost::report_errors() +// + +#include +#include + +namespace boost +{ + +namespace detail +{ + +inline int & test_errors() +{ + static int x = 0; + return x; +} + +inline void test_failed_impl(char const * expr, char const * file, int line, char const * function) +{ + std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl; + ++test_errors(); +} + +inline void error_impl(char const * msg, char const * file, int line, char const * function) +{ + std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl; + ++test_errors(); +} + +} // namespace detail + +inline int report_errors() +{ + int errors = detail::test_errors(); + + if(errors == 0) + { + std::cerr << "No errors detected." << std::endl; + return 0; + } + else + { + std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl; + return 1; + } +} + +} // namespace boost + +#define BOOST_TEST(expr) ((expr)? (void)0: boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)) +#define BOOST_ERROR(msg) boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) + +#endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED From 8bdcb2f3e3f460002ce2a02ab413f3f9af6294fb Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 18 Nov 2002 14:37:02 +0000 Subject: [PATCH 02/14] Major changes to shared_ptr and weak_ptr [SVN r16314] --- include/boost/detail/lightweight_test.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 2b33580..8c4fc33 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -68,7 +68,7 @@ inline int report_errors() } // namespace boost -#define BOOST_TEST(expr) ((expr)? (void)0: boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)) -#define BOOST_ERROR(msg) boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +#define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)) +#define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED From 5f07eefa1d49ac78414142ca9af08beae40cb110 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 12 Jun 2003 17:09:24 +0000 Subject: [PATCH 03/14] -Wundef fixes. [SVN r18788] --- include/boost/detail/lightweight_test.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 8c4fc33..33f5234 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -1,8 +1,8 @@ #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED #define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED -#if _MSC_VER >= 1020 -#pragma once +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once #endif // From 0afee0da68cab0ba8a6f5d96839c08185b7347b7 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 28 Nov 2003 15:35:21 +0000 Subject: [PATCH 04/14] _MSC_VER use clarified. [SVN r20992] --- include/boost/detail/lightweight_test.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 33f5234..8fd04a5 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -1,6 +1,8 @@ #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED #define BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED +// MS compatible compilers support #pragma once + #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif From f0676ad36546b3391f993c3ebfe9b98eca456fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20M=2E=20L=C3=B3pez=20Mu=C3=B1oz?= Date: Fri, 7 May 2004 10:44:23 +0000 Subject: [PATCH 05/14] initial commit [SVN r22759] --- .../boost/detail/no_exceptions_support.hpp | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 include/boost/detail/no_exceptions_support.hpp diff --git a/include/boost/detail/no_exceptions_support.hpp b/include/boost/detail/no_exceptions_support.hpp new file mode 100644 index 0000000..d94e358 --- /dev/null +++ b/include/boost/detail/no_exceptions_support.hpp @@ -0,0 +1,87 @@ +#ifndef BOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_ +#define BOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_ + +#if (defined _MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +//---------------------------------------------------------------------- +// (C) Copyright 2004 Pavel Vozenilek. +// Use, modification and distribution is subject to 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) +// +// +// This file contains helper macros used when exception support may be +// disabled (as indicated by macro BOOST_NO_EXCEPTIONS). +// +// Before picking up these macros you may consider using RAII techniques +// to deal with exceptions - their syntax can be always the same with +// or without exception support enabled. +// + +/* Example of use: + +void foo() { + BOOST_TRY { + ... + } BOOST_CATCH(const std::bad_alloc&) { + ... + BOOST_RETHROW + } BOOST_CATCH(const std::exception& e) { + ... + } + BOOST_CATCH_END +} + +With exception support enabled it will expand into: + +void foo() { + { try { + ... + } catch (const std::bad_alloc&) { + ... + throw; + } catch (const std::exception& e) { + ... + } + } +} + +With exception support disabled it will expand into: + +void foo() { + { if(true) { + ... + } else if (false) { + ... + } else if (false) { + ... + } + } +} +*/ +//---------------------------------------------------------------------- + +#include +#include + +#if !(defined BOOST_NO_EXCEPTIONS) +# define BOOST_TRY { try +# define BOOST_CATCH(x) catch(x) +# define BOOST_RETHROW throw; +# define BOOST_CATCH_END } +#else +# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# define BOOST_TRY { if ("") +# define BOOST_CATCH(x) else if (!"") +# else +# define BOOST_TRY { if (true) +# define BOOST_CATCH(x) else if (false) +# endif +# define BOOST_RETHROW +# define BOOST_CATCH_END } +#endif + + +#endif From e23db039e4dee74c129a45bf2ea3d4a224ce115c Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 26 Jul 2004 00:32:12 +0000 Subject: [PATCH 06/14] Converted to Boost Software License, Version 1.0 [SVN r24055] --- include/boost/detail/lightweight_test.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 8fd04a5..b651e0e 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -12,10 +12,9 @@ // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. -// This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. +// 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) // // BOOST_TEST(expression) // BOOST_ERROR(message) From 82a4de1e1aa89674d752c9b0d63431f08423c6eb Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 26 Mar 2009 00:03:45 +0000 Subject: [PATCH 07/14] Add BOOST_TEST_EQ. [SVN r51976] --- include/boost/detail/lightweight_test.hpp | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index b651e0e..ffa750d 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -10,14 +10,15 @@ // // boost/detail/lightweight_test.hpp - lightweight test library // -// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2002, 2009 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) +// 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 // // BOOST_TEST(expression) // BOOST_ERROR(message) +// BOOST_TEST_EQ(expr1, expr2) // // int boost::report_errors() // @@ -49,13 +50,27 @@ inline void error_impl(char const * msg, char const * file, int line, char const ++test_errors(); } +template 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 ) +{ + if( t == u ) + { + } + else + { + std::cerr << file << "(" << line << "): test '" << expr1 << " == " << expr2 + << "' failed in function '" << function << "': " + << "'" << t << "' != '" << u << "'" << std::endl; + ++test_errors(); + } +} + } // namespace detail inline int report_errors() { int errors = detail::test_errors(); - if(errors == 0) + if( errors == 0 ) { std::cerr << "No errors detected." << std::endl; return 0; @@ -71,5 +86,6 @@ inline int report_errors() #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)) #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +#define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED From 2c5aeee5623b43ce454b3aa45ba93231b425f5fb Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 19 Aug 2010 17:03:38 +0000 Subject: [PATCH 08/14] Remove path array optimization; problematic when array contains a string shorter than the array length. Reported by Adam Badura. [SVN r64928] --- include/boost/detail/lightweight_test.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index ffa750d..8aa76f8 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -24,6 +24,7 @@ // #include +#include #include namespace boost @@ -64,10 +65,31 @@ template inline void test_eq_impl( char const * expr1, char co } } +struct report_errors_reminder +{ + bool remembered_to_call_report_errors_function; + report_errors_reminder() : remembered_to_call_report_errors_function(false) {} + ~report_errors_reminder() + { + BOOST_ASSERT(remembered_to_call_report_errors_function); + } +}; + } // namespace detail +} // namespace boost +namespace +{ + boost::detail::report_errors_reminder boost_report_errors_reminder; +} + +namespace boost +{ + inline int report_errors() { + boost_report_errors_reminder.remembered_to_call_report_errors_function = true; + int errors = detail::test_errors(); if( errors == 0 ) From 2c28e851d87180272ceca94d74ec338077a75431 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 19 Aug 2010 17:09:22 +0000 Subject: [PATCH 09/14] Revert change committed in error [SVN r64929] --- include/boost/detail/lightweight_test.hpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 8aa76f8..ffa750d 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -24,7 +24,6 @@ // #include -#include #include namespace boost @@ -65,31 +64,10 @@ template inline void test_eq_impl( char const * expr1, char co } } -struct report_errors_reminder -{ - bool remembered_to_call_report_errors_function; - report_errors_reminder() : remembered_to_call_report_errors_function(false) {} - ~report_errors_reminder() - { - BOOST_ASSERT(remembered_to_call_report_errors_function); - } -}; - } // namespace detail -} // namespace boost -namespace -{ - boost::detail::report_errors_reminder boost_report_errors_reminder; -} - -namespace boost -{ - inline int report_errors() { - boost_report_errors_reminder.remembered_to_call_report_errors_function = true; - int errors = detail::test_errors(); if( errors == 0 ) From 646e4db7d283341ac00df0ebfeeeb2489706dcde Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 24 Aug 2010 18:57:38 +0000 Subject: [PATCH 10/14] Add BOOST_ASSERT that report_errors() has been called. [SVN r64987] --- include/boost/detail/lightweight_test.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index ffa750d..8add322 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -24,6 +24,7 @@ // #include +#include #include namespace boost @@ -32,9 +33,26 @@ namespace boost namespace detail { +struct report_errors_reminder +{ + bool called_report_errors_function; + report_errors_reminder() : called_report_errors_function(false) {} + ~report_errors_reminder() + { + BOOST_ASSERT(called_report_errors_function); // verify report_errors() was called + } +}; + +inline report_errors_reminder& report_errors_remind() +{ + static report_errors_reminder r; + return r; +} + inline int & test_errors() { static int x = 0; + report_errors_remind(); return x; } @@ -68,6 +86,8 @@ template inline void test_eq_impl( char const * expr1, char co inline int report_errors() { + detail::report_errors_remind().called_report_errors_function = true; + int errors = detail::test_errors(); if( errors == 0 ) From 632867705e71d2cdab3826873a8d7adbcc5339e7 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Mon, 24 Jan 2011 15:37:13 +0000 Subject: [PATCH 11/14] Add BOOST_ASSERT_MSG. Add macros to configure output stream. [SVN r68414] --- include/boost/detail/lightweight_test.hpp | 29 +++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 8add322..986bf41 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -11,6 +11,7 @@ // boost/detail/lightweight_test.hpp - lightweight test library // // Copyright (c) 2002, 2009 Peter Dimov +// Copyright (2) Beman Dawes 2010, 2011 // // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE_1_0.txt or copy at @@ -23,9 +24,15 @@ // int boost::report_errors() // +#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: +#ifndef BOOST_LIGHTWEIGHT_TEST_OSTREAM +# define BOOST_LIGHTWEIGHT_TEST_OSTREAM std::cerr +#endif namespace boost { @@ -58,24 +65,30 @@ inline int & test_errors() inline void test_failed_impl(char const * expr, char const * file, int line, char const * function) { - std::cerr << file << "(" << line << "): test '" << expr << "' failed in function '" << function << "'" << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr << "' failed in function '" + << function << "'" << std::endl; ++test_errors(); } inline void error_impl(char const * msg, char const * file, int line, char const * function) { - std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): " << msg << " in function '" + << function << "'" << std::endl; ++test_errors(); } -template 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 ) +template 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 ) { if( t == u ) { } else { - std::cerr << file << "(" << line << "): test '" << expr1 << " == " << expr2 + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr1 << " == " << expr2 << "' failed in function '" << function << "': " << "'" << t << "' != '" << u << "'" << std::endl; ++test_errors(); @@ -92,12 +105,14 @@ inline int report_errors() if( errors == 0 ) { - std::cerr << "No errors detected." << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << "No errors detected." << std::endl; return 0; } else { - std::cerr << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl; return 1; } } From a1dbe7520b545f1c8586658098ee70057d961b26 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 24 Feb 2011 23:24:54 +0000 Subject: [PATCH 12/14] Add hash_value for shared_ptr; prevents hash_value( bool ) from being used. Refs #5216. [SVN r69260] --- include/boost/detail/lightweight_test.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 986bf41..dbd99b9 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -95,6 +95,22 @@ template inline void test_eq_impl( char const * expr1, char co } } +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 ) +{ + if( t != u ) + { + } + else + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr1 << " != " << expr2 + << "' failed in function '" << function << "': " + << "'" << t << "' == '" << u << "'" << std::endl; + ++test_errors(); + } +} + } // namespace detail inline int report_errors() @@ -122,5 +138,6 @@ inline int report_errors() #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION)) #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) +#define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED From cb91a3f9dda074fc2f4a42af5da1a2df441f55d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 14 Mar 2013 23:08:40 +0000 Subject: [PATCH 13/14] Added BOOST_TEST_THROWS [SVN r83433] --- include/boost/detail/lightweight_test.hpp | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index dbd99b9..49dd5e4 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -12,21 +12,61 @@ // // Copyright (c) 2002, 2009 Peter Dimov // Copyright (2) Beman Dawes 2010, 2011 +// Copyright (3) Ion Gaztanaga 2013 // // 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 // +// --------------- +// +// If expression is false increases the error count +// and outputs a message containing 'expression' +// // BOOST_TEST(expression) +// +// --------------- +// +// Increases error count and outputs a message containing 'message' +// // BOOST_ERROR(message) +// +// --------------- +// +// If 'expr1' != 'expr2' increases the error count +// and outputs a message containing both expressions +// // BOOST_TEST_EQ(expr1, expr2) // +// --------------- +// +// If 'expr1' == 'expr2' increases the error count +// and outputs a message containing both expressions +// +// BOOST_TEST_NE(expr1, expr2) +// +// --------------- +// +// If BOOST_NO_EXCEPTIONS is NOT defined and if 'expr' does not +// throw an exception of type 'excep', increases the error count +// and outputs a message containing the expression. +// +// If BOOST_NO_EXCEPTIONS is defined, this macro expands to nothing +// and 'expr' is not evaluated. +// +// BOOST_TEST_THROWS(expr, excep) +// +// --------------- +// +// Returns the error count +// // int boost::report_errors() // #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: @@ -79,6 +119,14 @@ inline void error_impl(char const * msg, char const * file, int line, char const ++test_errors(); } +inline void throw_failed_impl(char const * excep, char const * file, int line, char const * function) +{ + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): Exception '" << excep << "' not thrown in function '" + << function << "'" << std::endl; + ++test_errors(); +} + template 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 ) { @@ -139,5 +187,22 @@ inline int report_errors() #define BOOST_ERROR(msg) ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) #define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) +#ifndef BOOST_NO_EXCEPTIONS + #define BOOST_TEST_THROWS( EXPR, EXCEP ) \ + try { \ + EXPR; \ + ::boost::detail::throw_failed_impl \ + (#EXCEP, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); \ + } \ + catch(EXCEP const&) { \ + } \ + catch(...) { \ + ::boost::detail::throw_failed_impl \ + (#EXCEP, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); \ + } \ + // +#else + #define BOOST_TEST_THROWS( EXPR, EXCEP ) +#endif #endif // #ifndef BOOST_DETAIL_LIGHTWEIGHT_TEST_HPP_INCLUDED From e47cd1550b2ed47b8e6e2575374fe519e86d8c67 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 26 Sep 2013 13:02:51 +0000 Subject: [PATCH 14/14] Remove obsolete MSVC check from pragma guard git grep -h -B1 "^#\s*pragma once" | grep -v pragma | sort | uniq is now clean. [SVN r85952] --- include/boost/detail/lightweight_test.hpp | 2 +- include/boost/detail/no_exceptions_support.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/detail/lightweight_test.hpp b/include/boost/detail/lightweight_test.hpp index 49dd5e4..8704d5c 100644 --- a/include/boost/detail/lightweight_test.hpp +++ b/include/boost/detail/lightweight_test.hpp @@ -3,7 +3,7 @@ // MS compatible compilers support #pragma once -#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#if defined(_MSC_VER) # pragma once #endif diff --git a/include/boost/detail/no_exceptions_support.hpp b/include/boost/detail/no_exceptions_support.hpp index d94e358..89336f6 100644 --- a/include/boost/detail/no_exceptions_support.hpp +++ b/include/boost/detail/no_exceptions_support.hpp @@ -1,7 +1,7 @@ #ifndef BOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_ #define BOOST_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP_ -#if (defined _MSC_VER) && (_MSC_VER >= 1200) +#if defined(_MSC_VER) # pragma once #endif