• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, no old, post, or 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()17 void f() {
18     boost::contract::check c = boost::contract::function()
19         .precondition([] { out << "f::pre" << std::endl; })
20     ;
21     out << "f::body" << std::endl;
22 }
23 
main()24 int main() {
25     std::ostringstream ok;
26 
27     out.str("");
28     f();
29     ok.str(""); ok
30         #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
31             << "f::pre" << std::endl
32         #endif
33         << "f::body" << std::endl
34     ;
35     BOOST_TEST(out.eq(ok.str()));
36 
37     return boost::report_errors();
38 }
39 
40