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

@@ -0,0 +1,46 @@
// Test throw from free function .old().
#include "../aux_/oteststream.hpp"
#include <boost/contract/function.hpp>
#include <boost/contract/guard.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <sstream>
boost::contract::aux::test::oteststream out;
struct err {};
void f() {
boost::contract::guard c = boost::contract::function()
.precondition([&] { out << "f::pre" << std::endl; })
.old([&] {
out << "f::old" << std::endl;
throw err(); // Test .old() throws.
})
.postcondition([&] { out << "f::post" << std::endl; })
;
out << "f::body" << std::endl;
}
int main() {
std::ostringstream ok;
boost::contract::set_postcondition_failed(
[] (boost::contract::from) { throw; });
try {
out.str("");
f();
BOOST_TEST(false);
} catch(err const&) {
ok.str(""); ok
<< "f::pre" << std::endl
<< "f::old" << std::endl // Test this threw.
;
BOOST_TEST(out.eq(ok.str()));
} catch(...) { BOOST_TEST(false); }
return boost::report_errors();
}