1 2 // Copyright (C) 2008-2018 Lorenzo Caminiti 3 // Distributed under the Boost Software License, Version 1.0 (see accompanying 4 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). 5 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html 6 7 // Test specifying pre, old, and post, no except (same if not free func). 8 9 #include "../detail/oteststream.hpp" 10 #include <boost/contract/function.hpp> 11 #include <boost/contract/check.hpp> 12 #include <boost/detail/lightweight_test.hpp> 13 #include <sstream> 14 15 boost::contract::test::detail::oteststream out; 16 f()17void f() { 18 boost::contract::check c = boost::contract::function() 19 .precondition([] { out << "f::pre" << std::endl; }) 20 .old([] { out << "f::old" << std::endl; }) 21 .postcondition([] { out << "f::post" << std::endl; }) 22 ; 23 out << "f::body" << std::endl; 24 } 25 main()26int main() { 27 std::ostringstream ok; 28 29 out.str(""); 30 f(); 31 ok.str(""); 32 ok 33 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS 34 << "f::pre" << std::endl 35 #endif 36 #ifndef BOOST_CONTRACT_NO_OLDS 37 << "f::old" << std::endl 38 #endif 39 << "f::body" << std::endl 40 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS 41 << "f::post" << std::endl 42 #endif 43 ; 44 BOOST_TEST(out.eq(ok.str())); 45 46 return boost::report_errors(); 47 } 48 49