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
7 // Test check (class and macro).
9 #include "../detail/oteststream.hpp"
10 #include <boost/contract/check.hpp>
11 #include <boost/contract/assert.hpp>
12 #include <boost/detail/lightweight_test.hpp>
15 boost::contract::test::detail::oteststream out;
17 struct err {}; // Global decl so visible in MSVC10 lambdas.
20 #ifdef BOOST_CONTRACT_TEST_CHECK_MACRO
21 BOOST_CONTRACT_CHECK([&] () -> bool {
22 out << "f::check" << std::endl;
26 boost::contract::check c = [&] {
27 out << "f::check" << std::endl;
28 BOOST_CONTRACT_ASSERT(check);
31 out << "f::body" << std::endl;
35 std::ostringstream ok;
40 #ifndef BOOST_CONTRACT_NO_CHECKS
41 << "f::check" << std::endl
43 << "f::body" << std::endl
45 BOOST_TEST(out.eq(ok.str()));
47 boost::contract::set_check_failure([] { throw err(); });
52 #ifndef BOOST_CONTRACT_NO_CHECKS
56 ok << "f::check" << std::endl;
59 ok << "f::body" << std::endl;
61 BOOST_TEST(out.eq(ok.str()));
62 } catch(...) { BOOST_TEST(false); }
64 return boost::report_errors();