mirror of
https://github.com/boostorg/contract.git
synced 2026-01-27 18:52:16 +00:00
added tests for throwing from .old()
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
// Test free function body throwing.
|
||||
// Test throw from free function body.
|
||||
|
||||
#include "../aux_/oteststream.hpp"
|
||||
#include <boost/contract/function.hpp>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
boost::contract::aux::test::oteststream out;
|
||||
|
||||
struct e {};
|
||||
struct err {};
|
||||
|
||||
void f() {
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
@@ -18,24 +18,24 @@ void f() {
|
||||
.postcondition([&] { out << "f::post" << std::endl; })
|
||||
;
|
||||
out << "f::body" << std::endl;
|
||||
throw e(); // Test body throw.
|
||||
throw err(); // Test body throws.
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ostringstream ok;
|
||||
|
||||
bool threw = false;
|
||||
out.str("");
|
||||
try { f(); }
|
||||
catch(e const&) { threw = true; }
|
||||
BOOST_TEST(threw);
|
||||
ok.str(""); ok
|
||||
<< "f::pre" << std::endl
|
||||
<< "f::old" << std::endl
|
||||
<< "f::body" << std::endl
|
||||
// Test no post because body threw.
|
||||
;
|
||||
BOOST_TEST(out.eq(ok.str()));
|
||||
try {
|
||||
out.str("");
|
||||
f();
|
||||
BOOST_TEST(false);
|
||||
} catch(err const&) {
|
||||
ok.str(""); ok
|
||||
<< "f::pre" << std::endl
|
||||
<< "f::old" << std::endl
|
||||
<< "f::body" << std::endl // Test this threw.
|
||||
;
|
||||
BOOST_TEST(out.eq(ok.str()));
|
||||
} catch(...) { BOOST_TEST(false); }
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user