From db331efaa1b5f59bb2de19f23b39a8ef884a96d5 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 17 Jul 2015 14:48:51 +0200 Subject: [PATCH] tests: Add test for exception propagation from make_lw_shared() --- tests/shared_ptr_test.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/shared_ptr_test.cc b/tests/shared_ptr_test.cc index 21e8a814bf..5abae77f84 100644 --- a/tests/shared_ptr_test.cc +++ b/tests/shared_ptr_test.cc @@ -26,6 +26,8 @@ #include #include "core/shared_ptr.hh" +struct expected_exception : public std::exception {}; + struct A { static bool destroyed; A() { @@ -93,3 +95,23 @@ BOOST_AUTO_TEST_CASE(test_shared_from_this_called_on_const_object) { auto ptr = make_lw_shared(); ptr->const_method(); } + +BOOST_AUTO_TEST_CASE(test_exception_thrown_from_constructor_is_propagated) { + struct X { + X() { + throw expected_exception(); + } + }; + try { + auto ptr = make_lw_shared(); + BOOST_FAIL("Constructor should have thrown"); + } catch (const expected_exception& e) { + BOOST_MESSAGE("Expected exception caught"); + } + try { + auto ptr = ::make_shared(); + BOOST_FAIL("Constructor should have thrown"); + } catch (const expected_exception& e) { + BOOST_MESSAGE("Expected exception caught"); + } +}