|
4 | 4 | // http://www.boost.org/LICENSE_1_0.txt) |
5 | 5 |
|
6 | 6 | #include <boost/python.hpp> |
| 7 | +#define BOOST_ENABLE_ASSERT_HANDLER 1 |
| 8 | +#include <boost/assert.hpp> |
7 | 9 | #include <iostream> |
8 | 10 |
|
| 11 | +namespace boost |
| 12 | +{ |
| 13 | + |
| 14 | +void assertion_failed(char const * expr, char const * function, |
| 15 | + char const * file, long line) |
| 16 | +{ |
| 17 | + std::cerr << "assertion failed : " << expr << " in " << function |
| 18 | + << " at " << file << ':' << line << std::endl; |
| 19 | + abort(); |
| 20 | +} |
| 21 | + |
| 22 | +} // namespace boost |
| 23 | + |
9 | 24 | namespace python = boost::python; |
10 | 25 |
|
11 | 26 | // An abstract base class |
@@ -70,17 +85,15 @@ void exec_test() |
70 | 85 |
|
71 | 86 | // Creating and using instances of the C++ class is as easy as always. |
72 | 87 | CppDerived cpp; |
73 | | - if (cpp.hello() != "Hello from C++!") |
74 | | - throw std::runtime_error("cpp.hello() returned unexpected string"); |
| 88 | + BOOST_ASSERT(cpp.hello() == "Hello from C++!"); |
75 | 89 |
|
76 | 90 | // But now creating and using instances of the Python class is almost |
77 | 91 | // as easy! |
78 | 92 | python::object py_base = PythonDerived(); |
79 | 93 | Base& py = python::extract<Base&>(py_base) BOOST_EXTRACT_WORKAROUND; |
80 | 94 |
|
81 | 95 | // Make sure the right 'hello' method is called. |
82 | | - if (py.hello() != "Hello from Python!") |
83 | | - throw std::runtime_error("py.hello() returned unexpected string"); |
| 96 | + BOOST_ASSERT(py.hello() == "Hello from Python!"); |
84 | 97 | } |
85 | 98 |
|
86 | 99 | void exec_file_test(std::string const &script) |
@@ -90,8 +103,7 @@ void exec_file_test(std::string const &script) |
90 | 103 | python::object result = python::exec_file(script.c_str(), global, global); |
91 | 104 |
|
92 | 105 | // Extract an object the script stored in the global dictionary. |
93 | | - if (python::extract<int>(global["number"]) != 42) |
94 | | - throw std::runtime_error("'number' has unexpected value"); |
| 106 | + BOOST_ASSERT(python::extract<int>(global["number"]) == 42); |
95 | 107 | } |
96 | 108 |
|
97 | 109 | void exec_test_error() |
|