summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/contract/test/specify/missing_check.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/contract/test/specify/missing_check.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/contract/test/specify/missing_check.cpp')
-rw-r--r--src/boost/libs/contract/test/specify/missing_check.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/specify/missing_check.cpp b/src/boost/libs/contract/test/specify/missing_check.cpp
new file mode 100644
index 000000000..7e6f01c0d
--- /dev/null
+++ b/src/boost/libs/contract/test/specify/missing_check.cpp
@@ -0,0 +1,43 @@
+
+// Copyright (C) 2008-2018 Lorenzo Caminiti
+// Distributed under the Boost Software License, Version 1.0 (see accompanying
+// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
+
+// Test missing contract check declaration gives run-time error.
+
+struct err {};
+#ifndef BOOST_CONTRACT_ON_MISSING_CHECK_DECL
+ #error "build must define ON_MISSING_CHECK_DECL=`{ throw err(); }`"
+#endif
+
+#include <boost/contract/function.hpp>
+#include <boost/contract/check.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main() {
+ boost::contract::check c = boost::contract::function() // Test this is OK.
+ .precondition([] {})
+ .old([] {})
+ .postcondition([] {})
+ ;
+
+ try {
+ boost::contract::function() // Test no `check c = ...` errors.
+ .precondition([] {})
+ .old([] {})
+ .postcondition([] {})
+ ;
+ #if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
+ !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
+ !defined(BOOST_CONTRACT_NO_INVARIANTS)
+ BOOST_TEST(false); // Error, must throw.
+ #endif
+ } catch(err const&) {
+ // OK, threw as expected.
+ } catch(...) {
+ BOOST_TEST(false); // Error, unexpected throw.
+ }
+ return boost::report_errors();
+}
+