From e80545a7d375ffb857691349f7d28e13aeb74361 Mon Sep 17 00:00:00 2001 From: Stefan Seefeld Date: Tue, 13 Sep 2005 14:42:03 +0000 Subject: [PATCH] Use BOOST_ASSERT instead of std::runtime_error to indicate errors. [SVN r30954] --- test/exec.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/test/exec.cpp b/test/exec.cpp index 111d9e0f..64b3ef0d 100644 --- a/test/exec.cpp +++ b/test/exec.cpp @@ -4,8 +4,23 @@ // http://www.boost.org/LICENSE_1_0.txt) #include +#define BOOST_ENABLE_ASSERT_HANDLER 1 +#include #include +namespace boost +{ + +void assertion_failed(char const * expr, char const * function, + char const * file, long line) +{ + std::cerr << "assertion failed : " << expr << " in " << function + << " at " << file << ':' << line << std::endl; + abort(); +} + +} // namespace boost + namespace python = boost::python; // An abstract base class @@ -70,8 +85,7 @@ void exec_test() // Creating and using instances of the C++ class is as easy as always. CppDerived cpp; - if (cpp.hello() != "Hello from C++!") - throw std::runtime_error("cpp.hello() returned unexpected string"); + BOOST_ASSERT(cpp.hello() == "Hello from C++!"); // But now creating and using instances of the Python class is almost // as easy! @@ -79,8 +93,7 @@ void exec_test() Base& py = python::extract(py_base) BOOST_EXTRACT_WORKAROUND; // Make sure the right 'hello' method is called. - if (py.hello() != "Hello from Python!") - throw std::runtime_error("py.hello() returned unexpected string"); + BOOST_ASSERT(py.hello() == "Hello from Python!"); } void exec_file_test(std::string const &script) @@ -90,8 +103,7 @@ void exec_file_test(std::string const &script) python::object result = python::exec_file(script.c_str(), global, global); // Extract an object the script stored in the global dictionary. - if (python::extract(global["number"]) != 42) - throw std::runtime_error("'number' has unexpected value"); + BOOST_ASSERT(python::extract(global["number"]) == 42); } void exec_test_error()