pre_except.cpp 1.1 KB

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