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 missing contract check declaration gives run-time error. 8 9 struct err {}; 10 #ifndef BOOST_CONTRACT_ON_MISSING_CHECK_DECL 11 #error "build must define ON_MISSING_CHECK_DECL=`{ throw err(); }`" 12 #endif 13 14 #include <boost/contract/function.hpp> 15 #include <boost/contract/check.hpp> 16 #include <boost/detail/lightweight_test.hpp> 17 main()18int main() { 19 boost::contract::check c = boost::contract::function() // Test this is OK. 20 .precondition([] {}) 21 .old([] {}) 22 .postcondition([] {}) 23 ; 24 25 try { 26 boost::contract::function() // Test no `check c = ...` errors. 27 .precondition([] {}) 28 .old([] {}) 29 .postcondition([] {}) 30 ; 31 #if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ 32 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ 33 !defined(BOOST_CONTRACT_NO_INVARIANTS) 34 BOOST_TEST(false); // Error, must throw. 35 #endif 36 } catch(err const&) { 37 // OK, threw as expected. 38 } catch(...) { 39 BOOST_TEST(false); // Error, unexpected throw. 40 } 41 return boost::report_errors(); 42 } 43 44