44// http://www.boost.org/LICENSE_1_0.txt)
55
66#include < boost/python.hpp>
7- #define BOOST_ENABLE_ASSERT_HANDLER 1
8- #include < boost/assert.hpp>
9- #include < iostream>
10-
11- namespace boost
12- {
137
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- }
8+ #include < boost/detail/lightweight_test.hpp>
9+ #include < iostream>
2110
22- } // namespace boost
2311
2412namespace python = boost::python;
2513
@@ -85,15 +73,15 @@ void exec_test()
8573
8674 // Creating and using instances of the C++ class is as easy as always.
8775 CppDerived cpp;
88- BOOST_ASSERT (cpp.hello () == " Hello from C++!" );
76+ BOOST_TEST (cpp.hello () == " Hello from C++!" );
8977
9078 // But now creating and using instances of the Python class is almost
9179 // as easy!
9280 python::object py_base = PythonDerived ();
9381 Base& py = python::extract<Base&>(py_base) BOOST_EXTRACT_WORKAROUND;
9482
9583 // Make sure the right 'hello' method is called.
96- BOOST_ASSERT (py.hello () == " Hello from Python!" );
84+ BOOST_TEST (py.hello () == " Hello from Python!" );
9785}
9886
9987void exec_file_test (std::string const &script)
@@ -103,7 +91,7 @@ void exec_file_test(std::string const &script)
10391 python::object result = python::exec_file (script.c_str (), global, global);
10492
10593 // Extract an object the script stored in the global dictionary.
106- BOOST_ASSERT (python::extract<int >(global[" number" ]) == 42 );
94+ BOOST_TEST (python::extract<int >(global[" number" ]) == 42 );
10795}
10896
10997void exec_test_error ()
@@ -115,9 +103,8 @@ void exec_test_error()
115103
116104int main (int argc, char **argv)
117105{
118- assert (argc == 2 );
106+ BOOST_TEST (argc == 2 );
119107 std::string script = argv[1 ];
120- bool success = true ;
121108 // Initialize the interpreter
122109 Py_Initialize ();
123110
@@ -126,15 +113,16 @@ int main(int argc, char **argv)
126113 {
127114 if (PyErr_Occurred ())
128115 {
116+ BOOST_ERROR (" Python Error detected" );
129117 PyErr_Print ();
130118 }
131119 else
132120 {
133- std::cerr << " A C++ exception was thrown for which "
134- << " there was no exception handler registered." << std::endl ;
121+ BOOST_ERROR ( " A C++ exception was thrown for which "
122+ " there was no exception handler registered." ) ;
135123 }
136- success = false ;
137124 }
125+
138126 if (python::handle_exception (exec_test_error))
139127 {
140128 if (PyErr_Occurred ())
@@ -143,18 +131,18 @@ int main(int argc, char **argv)
143131 }
144132 else
145133 {
146- std::cerr << " A C++ exception was thrown for which "
147- << " there was no exception handler registered." << std::endl;
148- success = false ;
134+ BOOST_ERROR (" A C++ exception was thrown for which "
135+ " there was no exception handler registered." );
149136 }
150137 }
151138 else
152139 {
153- success = false ;
140+ BOOST_ERROR ( " Python exception expected, but not seen. " ) ;
154141 }
142+
155143 // Boost.Python doesn't support Py_Finalize yet.
156144 // Py_Finalize();
157- return success ? 0 : 1 ;
145+ return boost::report_errors () ;
158146}
159147
160148// Including this file makes sure
0 commit comments