|
Boost-Commit : |
From: pdimov_at_[hidden]
Date: 2007-11-03 16:55:23
Author: pdimov
Date: 2007-11-03 16:55:22 EDT (Sat, 03 Nov 2007)
New Revision: 40728
URL: http://svn.boost.org/trac/boost/changeset/40728
Log:
BOOST_VERIFY added.
Added:
trunk/libs/utility/verify_test.cpp (contents, props changed)
Text files modified:
trunk/boost/assert.hpp | 13 +++++++++++++
trunk/libs/utility/assert.html | 10 +++++++---
trunk/libs/utility/test/Jamfile.v2 | 1 +
3 files changed, 21 insertions(+), 3 deletions(-)
Modified: trunk/boost/assert.hpp
==============================================================================
--- trunk/boost/assert.hpp (original)
+++ trunk/boost/assert.hpp 2007-11-03 16:55:22 EDT (Sat, 03 Nov 2007)
@@ -2,6 +2,7 @@
// boost/assert.hpp - BOOST_ASSERT(expr)
//
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
+// Copyright (c) 2007 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -35,3 +36,15 @@
# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
# define BOOST_ASSERT(expr) assert(expr)
#endif
+
+#undef BOOST_VERIFY
+
+#if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )
+
+# define BOOST_VERIFY(expr) ((void)(expr))
+
+#else
+
+# define BOOST_VERIFY(expr) BOOST_ASSERT(expr)
+
+#endif
Modified: trunk/libs/utility/assert.html
==============================================================================
--- trunk/libs/utility/assert.html (original)
+++ trunk/libs/utility/assert.html 2007-11-03 16:55:22 EDT (Sat, 03 Nov 2007)
@@ -47,9 +47,13 @@
<P>As is the case with <STRONG><cassert></STRONG>, <STRONG><boost/assert.hpp></STRONG>
can be included multiple times in a single translation unit. <STRONG>BOOST_ASSERT</STRONG>
will be redefined each time as specified above.</P>
+ <p><STRONG><boost/assert.hpp></STRONG> also defines the macro <STRONG>BOOST_VERIFY</STRONG>.
+ It has exactly the same behavior as <STRONG>BOOST_ASSERT</STRONG>, except
+ that the expression that is passed to <STRONG>BOOST_VERIFY</STRONG> is always
+ evaluated.</p>
<p><br>
- <small>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.</small></p>
+ <small>Copyright © 2002, 2007 by Peter Dimov. Distributed under the Boost
+ Software License, Version 1.0. See accompanying file <A href="../../LICENSE_1_0.txt">
+ LICENSE_1_0.txt</A> or copy at http://www.boost.org/LICENSE_1_0.txt.</small></p>
</body>
</html>
Modified: trunk/libs/utility/test/Jamfile.v2
==============================================================================
--- trunk/libs/utility/test/Jamfile.v2 (original)
+++ trunk/libs/utility/test/Jamfile.v2 2007-11-03 16:55:22 EDT (Sat, 03 Nov 2007)
@@ -33,4 +33,5 @@
[ compile-fail ../value_init_test_fail1.cpp ]
[ compile-fail ../value_init_test_fail2.cpp ]
[ compile-fail ../value_init_test_fail3.cpp ]
+ [ run verify_test.cpp ]
;
Added: trunk/libs/utility/verify_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/verify_test.cpp 2007-11-03 16:55:22 EDT (Sat, 03 Nov 2007)
@@ -0,0 +1,126 @@
+//
+// verify_test.cpp - a test for BOOST_VERIFY
+//
+// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
+// Copyright (c) 2007 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 <boost/detail/lightweight_test.hpp>
+
+#include <boost/assert.hpp>
+
+int f( int & x )
+{
+ return ++x;
+}
+
+void test_default()
+{
+ int x = 1;
+
+ BOOST_VERIFY( 1 );
+ BOOST_VERIFY( x == 1 );
+ BOOST_VERIFY( ++x );
+ BOOST_VERIFY( f(x) );
+ BOOST_VERIFY( &x );
+
+ BOOST_TEST( x == 3 );
+}
+
+#define BOOST_DISABLE_ASSERTS
+#include <boost/assert.hpp>
+
+void test_disabled()
+{
+ int x = 1;
+
+ BOOST_VERIFY( 1 );
+ BOOST_VERIFY( x == 1 );
+ BOOST_VERIFY( ++x );
+ BOOST_VERIFY( f(x) );
+ BOOST_VERIFY( &x );
+
+ BOOST_TEST( x == 3 );
+
+ BOOST_VERIFY( 0 );
+ BOOST_VERIFY( !x );
+ BOOST_VERIFY( x == 0 );
+ BOOST_VERIFY( !++x );
+ BOOST_VERIFY( !f(x) );
+
+ BOOST_TEST( x == 5 );
+
+ void * p = 0;
+ BOOST_VERIFY( p );
+}
+
+#undef BOOST_DISABLE_ASSERTS
+
+#define BOOST_ENABLE_ASSERT_HANDLER
+#include <boost/assert.hpp>
+#include <boost/config.hpp>
+#include <cstdio>
+
+int handler_invoked = 0;
+
+void boost::assertion_failed(char const * expr, char const * function, char const * file, long line)
+{
+#if !defined(BOOST_NO_STDC_NAMESPACE)
+ using std::printf;
+#endif
+
+ printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line);
+ ++handler_invoked;
+}
+
+struct X
+{
+ static bool f()
+ {
+ BOOST_VERIFY( 0 );
+ return false;
+ }
+};
+
+void test_handler()
+{
+ int x = 1;
+
+ BOOST_VERIFY( 1 );
+ BOOST_VERIFY( x == 1 );
+ BOOST_VERIFY( ++x );
+ BOOST_VERIFY( f(x) );
+ BOOST_VERIFY( &x );
+
+ BOOST_TEST( x == 3 );
+
+ BOOST_VERIFY( 0 );
+ BOOST_VERIFY( !x );
+ BOOST_VERIFY( x == 0 );
+ BOOST_VERIFY( !++x );
+ BOOST_VERIFY( !f(x) );
+
+ BOOST_TEST( x == 5 );
+
+ void * p = 0;
+ BOOST_VERIFY( p );
+
+ BOOST_VERIFY( X::f() );
+
+ BOOST_TEST( handler_invoked == 8 );
+}
+
+#undef BOOST_ENABLE_ASSERT_HANDLER
+
+int main()
+{
+ test_default();
+ test_disabled();
+ test_handler();
+
+ return boost::report_errors();
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk