added tests for throwing from .old()

This commit is contained in:
Lorenzo Caminiti
2015-12-15 11:51:44 -08:00
parent 07248b63ea
commit ec79700b26
11 changed files with 538 additions and 141 deletions

View File

@@ -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();
}