audit.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // no #include guard
  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. #include <boost/contract/check.hpp>
  7. #include <boost/contract/core/exception.hpp>
  8. #include <boost/detail/lightweight_test.hpp>
  9. struct err {}; // Global decl so visible in MSVC10 lambdas.
  10. int main() {
  11. boost::contract::set_check_failure([] { throw err(); });
  12. bool threw = false;
  13. try {
  14. #ifdef BOOST_CONTRACT_TEST_ERROR
  15. BOOST_CONTRACT_CHECK_AUDIT(
  16. BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier);
  17. #else
  18. BOOST_CONTRACT_CHECK_AUDIT(false);
  19. #endif
  20. } catch(err const&) { threw = true; }
  21. #if defined(BOOST_CONTRACT_AUDITS) && !defined(BOOST_CONTRACT_NO_CHECKS)
  22. BOOST_TEST(threw);
  23. #else
  24. BOOST_TEST(!threw);
  25. #endif
  26. return boost::report_errors();
  27. }