Files
contract/test/set/all_pre_old_post.cpp
Lorenzo Caminiti c594323bef added .old(...)
2015-10-23 15:46:47 -07:00

38 lines
889 B
C++

// Test all pre, old, and post (for free func, but same for all contracts).
#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;
void f() {
boost::contract::guard c = boost::contract::function()
.precondition([] { out << "f::pre" << std::endl; })
.old([] { out << "f::old" << std::endl; })
.postcondition([] { out << "f::post" << std::endl; })
;
out << "f::body" << std::endl;
}
int main() {
std::ostringstream ok;
out.str("");
f();
ok.str("");
ok
<< "f::pre" << std::endl
<< "f::old" << std::endl
<< "f::body" << std::endl
<< "f::post" << std::endl
;
BOOST_TEST(out.eq(ok.str()));
return boost::report_errors();
}