diff --git a/test/back_reference.cpp b/test/back_reference.cpp index c3c09e11..b5d1378c 100644 --- a/test/back_reference.cpp +++ b/test/back_reference.cpp @@ -10,7 +10,8 @@ #include #include #include -#include +#define BOOST_ENABLE_ASSERT_HANDLER +#include #include #include #include @@ -24,10 +25,10 @@ struct X { explicit X(int x) : x(x), magic(7654321) { ++counter; } X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - virtual ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } + virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; } - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } + void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; } + int value() const { BOOST_ASSERT(magic == 7654321); return x; } static int count() { return counter; } private: void operator=(X const&); diff --git a/test/callbacks.cpp b/test/callbacks.cpp index 5e317393..ee305553 100644 --- a/test/callbacks.cpp +++ b/test/callbacks.cpp @@ -2,6 +2,8 @@ // 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 + #include #include #include @@ -29,10 +31,10 @@ struct X { explicit X(int x) : x(x), magic(7654321) { ++counter; } X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } + ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; } - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } + void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; } + int value() const { BOOST_ASSERT(magic == 7654321); return x; } static int count() { return counter; } private: void operator=(X const&); diff --git a/test/destroy_test.cpp b/test/destroy_test.cpp index 382943c9..254bfc26 100644 --- a/test/destroy_test.cpp +++ b/test/destroy_test.cpp @@ -2,7 +2,8 @@ // Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include + +#include int count; int marks[] = { @@ -26,8 +27,8 @@ struct foo void assert_destructions(int n) { for (int i = 0; i < n; ++i) - assert(marks[i] == i); - assert(marks[n] == -1); + BOOST_TEST(marks[i] == i); + BOOST_TEST(marks[n] == -1); } int main() @@ -50,5 +51,5 @@ int main() boost::python::detail::destroy_referent(f3); assert_destructions(7); - return 0; + return boost::report_errors(); } diff --git a/test/dict.cpp b/test/dict.cpp index b4d5dde8..1363c142 100644 --- a/test/dict.cpp +++ b/test/dict.cpp @@ -2,6 +2,8 @@ // Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include + #include #include #include @@ -69,7 +71,7 @@ void test_templates(object print) print(tmp.get(2,"default")); print(tmp.setdefault(3,"default")); - assert(!tmp.has_key(key)); + BOOST_ASSERT(!tmp.has_key(key)); //print(tmp[3]); } diff --git a/test/exec.cpp b/test/exec.cpp index 64b3ef0d..889a5324 100644 --- a/test/exec.cpp +++ b/test/exec.cpp @@ -4,22 +4,10 @@ // http://www.boost.org/LICENSE_1_0.txt) #include -#define BOOST_ENABLE_ASSERT_HANDLER 1 -#include + +#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; @@ -85,7 +73,7 @@ void exec_test() // Creating and using instances of the C++ class is as easy as always. CppDerived cpp; - BOOST_ASSERT(cpp.hello() == "Hello from C++!"); + BOOST_TEST(cpp.hello() == "Hello from C++!"); // But now creating and using instances of the Python class is almost // as easy! @@ -93,7 +81,7 @@ void exec_test() Base& py = python::extract(py_base) BOOST_EXTRACT_WORKAROUND; // Make sure the right 'hello' method is called. - BOOST_ASSERT(py.hello() == "Hello from Python!"); + BOOST_TEST(py.hello() == "Hello from Python!"); } void exec_file_test(std::string const &script) @@ -103,7 +91,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. - BOOST_ASSERT(python::extract(global["number"]) == 42); + BOOST_TEST(python::extract(global["number"]) == 42); } void exec_test_error() @@ -115,9 +103,8 @@ void exec_test_error() int main(int argc, char **argv) { - assert(argc == 2); + BOOST_TEST(argc == 2); std::string script = argv[1]; - bool success = true; // Initialize the interpreter Py_Initialize(); @@ -126,15 +113,16 @@ int main(int argc, char **argv) { if (PyErr_Occurred()) { + BOOST_ERROR("Python Error detected"); PyErr_Print(); } else { - std::cerr << "A C++ exception was thrown for which " - << "there was no exception handler registered." << std::endl; + BOOST_ERROR("A C++ exception was thrown for which " + "there was no exception handler registered."); } - success = false; } + if (python::handle_exception(exec_test_error)) { if (PyErr_Occurred()) @@ -143,18 +131,18 @@ int main(int argc, char **argv) } else { - std::cerr << "A C++ exception was thrown for which " - << "there was no exception handler registered." << std::endl; - success = false; + BOOST_ERROR("A C++ exception was thrown for which " + "there was no exception handler registered."); } } else { - success = false; + BOOST_ERROR("Python exception expected, but not seen."); } + // Boost.Python doesn't support Py_Finalize yet. // Py_Finalize(); - return success ? 0 : 1; + return boost::report_errors(); } // Including this file makes sure diff --git a/test/extract.cpp b/test/extract.cpp index 91c90f8e..40584a07 100644 --- a/test/extract.cpp +++ b/test/extract.cpp @@ -13,7 +13,8 @@ #include #include #include -#include +#define BOOST_ENABLE_ASSERT_HANDLER +#include #include "test_class.hpp" using namespace boost::python; diff --git a/test/indirect_traits_test.cpp b/test/indirect_traits_test.cpp index 39da4279..594cfe55 100644 --- a/test/indirect_traits_test.cpp +++ b/test/indirect_traits_test.cpp @@ -2,7 +2,8 @@ // Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //#include -#include +#define BOOST_ENABLE_ASSERT_HANDLER +#include #include #include #include diff --git a/test/list.cpp b/test/list.cpp index 51b50496..d9c47a62 100644 --- a/test/list.cpp +++ b/test/list.cpp @@ -2,6 +2,8 @@ // 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 + #include #include @@ -118,10 +120,10 @@ void exercise(list x, object y, object print) w.append(5); w.append(6); w += "hi"; - assert(w[0] == 5); - assert(w[1] == 6); - assert(w[2] == 'h'); - assert(w[3] == 'i'); + BOOST_ASSERT(w[0] == 5); + BOOST_ASSERT(w[1] == 6); + BOOST_ASSERT(w[2] == 'h'); + BOOST_ASSERT(w[3] == 'i'); } BOOST_PYTHON_MODULE(list_ext) diff --git a/test/long.cpp b/test/long.cpp index 942834b7..61e4518f 100644 --- a/test/long.cpp +++ b/test/long.cpp @@ -7,7 +7,8 @@ #include #include #include -#include +#define BOOST_ENABLE_ASSERT_HANDLER +#include using namespace boost::python; @@ -30,7 +31,7 @@ char const* is_long1(long_& x) { long_ y = x; x += 50; - assert(x == y + 50); + BOOST_ASSERT(x == y + 50); return "yes"; } @@ -59,3 +60,4 @@ BOOST_PYTHON_MODULE(long_ext) ; } +#include "module_tail.cpp" diff --git a/test/module_tail.cpp b/test/module_tail.cpp index 48a9c67b..73a24047 100644 --- a/test/module_tail.cpp +++ b/test/module_tail.cpp @@ -27,3 +27,29 @@ extern "C" void (*old_translator)(unsigned, EXCEPTION_POINTERS*) #endif // _WIN32 +#include +#include +#include +struct test_failure : std::exception +{ + test_failure(char const* expr, char const* function, char const* file, unsigned line) + : msg(file + boost::python::str(":%s:") % line + ": Boost.Python assertion failure: " + expr) + {} + + char const* what() throw() + { + return boost::python::extract(msg)(); + } + + boost::python::str msg; +}; + +namespace boost +{ + +void assertion_failed(char const * expr, char const * function, char const * file, long line) +{ + throw ::test_failure(expr,function, file, line); +} + +} // namespace boost diff --git a/test/pointer_type_id_test.cpp b/test/pointer_type_id_test.cpp index e1b733de..02e168c7 100644 --- a/test/pointer_type_id_test.cpp +++ b/test/pointer_type_id_test.cpp @@ -2,7 +2,8 @@ // Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#include + +#include #include int main() @@ -13,30 +14,30 @@ int main() = boost::python::type_id(); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); - assert(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); + BOOST_TEST(pointer_type_id() == x); - return 0; + return boost::report_errors(); } diff --git a/test/raw_pyobject_fail1.cpp b/test/raw_pyobject_fail1.cpp index f9dd54bc..12d25158 100755 --- a/test/raw_pyobject_fail1.cpp +++ b/test/raw_pyobject_fail1.cpp @@ -7,5 +7,5 @@ int main() { boost::python::converter::arg_to_python x(0); - return 0; + return boost::report_errors(); } diff --git a/test/raw_pyobject_fail2.cpp b/test/raw_pyobject_fail2.cpp index 62c57ae7..9435c2db 100755 --- a/test/raw_pyobject_fail2.cpp +++ b/test/raw_pyobject_fail2.cpp @@ -9,5 +9,5 @@ struct X : PyObject {}; int main() { boost::python::converter::arg_to_python x(0); - return 0; + return boost::report_errors(); } diff --git a/test/staticmethod.cpp b/test/staticmethod.cpp index f3cb8763..0501c7c5 100644 --- a/test/staticmethod.cpp +++ b/test/staticmethod.cpp @@ -2,6 +2,8 @@ // 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 + #include #include #include @@ -15,10 +17,10 @@ struct X { explicit X(int x) : x(x), magic(7654321) { ++counter; } X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - virtual ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } + virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; } - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } + void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; } + int value() const { BOOST_ASSERT(magic == 7654321); return x; } static int count() { return counter; } private: void operator=(X const&); diff --git a/test/str.cpp b/test/str.cpp index fdbd93c5..3e033f85 100644 --- a/test/str.cpp +++ b/test/str.cpp @@ -2,6 +2,8 @@ // Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include + #include #include #include @@ -25,8 +27,8 @@ void work_with_string(object print) print(data.encode("utf-8")); print(data.decode("utf-8")); - assert(!data.endswith("xx")); - assert(!data.startswith("test")); + BOOST_ASSERT(!data.endswith("xx")); + BOOST_ASSERT(!data.startswith("test")); print(data.splitlines()); print(data.strip()); @@ -54,8 +56,8 @@ void work_with_string(object print) print(data.rfind("i",5)); print(data.rindex("i",5)); - assert(!data.startswith("asdf")); - assert(!data.endswith("asdf")); + BOOST_ASSERT(!data.startswith("asdf")); + BOOST_ASSERT(!data.endswith("asdf")); print(data.translate(str('a')*256)); diff --git a/test/string_literal.cpp b/test/string_literal.cpp index 4c0082d7..7a349d6c 100644 --- a/test/string_literal.cpp +++ b/test/string_literal.cpp @@ -3,7 +3,8 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include //#include -#include + +#include #include using namespace boost::python::detail; @@ -37,5 +38,5 @@ int main() BOOST_STATIC_ASSERT(!is_string_literal::value); BOOST_STATIC_ASSERT(!is_string_literal::value); BOOST_STATIC_ASSERT(!is_string_literal::value); - return 0; + return boost::report_errors(); } diff --git a/test/test_class.hpp b/test/test_class.hpp index 9dd3c814..6eb5e1e4 100644 --- a/test/test_class.hpp +++ b/test/test_class.hpp @@ -4,17 +4,17 @@ // http://www.boost.org/LICENSE_1_0.txt) #ifndef TEST_CLASS_DWA2002326_HPP # define TEST_CLASS_DWA2002326_HPP -# include +# include template struct test_class { explicit test_class(int x) : x(x), magic(7654321 + n) { ++counter; } test_class(test_class const& rhs) : x(rhs.x), magic(7654321 + n) { ++counter; } - virtual ~test_class() { assert(magic == 7654321 + n); magic = 6666666; x = 9999; --counter; } + virtual ~test_class() { BOOST_TEST(magic == 7654321 + n); magic = 6666666; x = 9999; --counter; } - void set(int x) { assert(magic == 7654321 + n); this->x = x; } - int value() const { assert(magic == 7654321 + n); return x; } + void set(int x) { BOOST_TEST(magic == 7654321 + n); this->x = x; } + int value() const { BOOST_TEST(magic == 7654321 + n); return x; } operator int() const { return x; } static int count() { return counter; } diff --git a/test/upcast.cpp b/test/upcast.cpp index 26b542f8..62df4937 100755 --- a/test/upcast.cpp +++ b/test/upcast.cpp @@ -2,6 +2,7 @@ // 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 #include struct X { long x; }; @@ -11,8 +12,8 @@ int main() { PyTypeObject o; Y y; - assert(&boost::python::upcast(&o)->ob_refcnt == &o.ob_refcnt); - assert(&boost::python::upcast(&y)->ob_refcnt == &y.ob_refcnt); - return 0; + BOOST_TEST(&boost::python::upcast(&o)->ob_refcnt == &o.ob_refcnt); + BOOST_TEST(&boost::python::upcast(&y)->ob_refcnt == &y.ob_refcnt); + return boost::report_errors(); } diff --git a/test/virtual_functions.cpp b/test/virtual_functions.cpp index 97fe1118..4d2405a3 100644 --- a/test/virtual_functions.cpp +++ b/test/virtual_functions.cpp @@ -2,6 +2,8 @@ // 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 + #include #include #include @@ -16,10 +18,10 @@ struct X { explicit X(int x) : x(x), magic(7654321) { ++counter; } X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; } - virtual ~X() { assert(magic == 7654321); magic = 6666666; x = 9999; --counter; } + virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; } - void set(int x) { assert(magic == 7654321); this->x = x; } - int value() const { assert(magic == 7654321); return x; } + void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; } + int value() const { BOOST_ASSERT(magic == 7654321); return x; } static int count() { return counter; } private: void operator=(X const&);