mirror of
https://github.com/boostorg/contract.git
synced 2026-02-27 04:52:22 +00:00
resolved most todo and recompiled most examples and tests
This commit is contained in:
36
test/specify/no_guard.cpp
Normal file
36
test/specify/no_guard.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
// Test missing contract guard gives run-time error.
|
||||
|
||||
struct err {};
|
||||
#define BOOST_CONTRACT_ON_MISSING_GUARD { throw err(); }
|
||||
|
||||
#include <boost/contract/function.hpp>
|
||||
#include <boost/contract/guard.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main() {
|
||||
boost::contract::guard c = boost::contract::function() // Test this is OK.
|
||||
.precondition([] {})
|
||||
.old([] {})
|
||||
.postcondition([] {})
|
||||
;
|
||||
|
||||
try {
|
||||
boost::contract::function() // Test no `guard 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user