diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/contract/test/specify | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/contract/test/specify')
28 files changed, 988 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/specify/auto_error.cpp b/src/boost/libs/contract/test/specify/auto_error.cpp new file mode 100644 index 00000000..04990649 --- /dev/null +++ b/src/boost/libs/contract/test/specify/auto_error.cpp @@ -0,0 +1,24 @@ + +// 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 auto error (for free func, but same for all contracts). + +#include <boost/config.hpp> +// Not just __cplusplus to detect C++17 as MSVC defines it correctly sometimes. +#if (defined(__cplusplus) && __cplusplus >= 201703L) || \ + !defined(BOOST_NO_CXX17_IF_CONSTEXPR) + #error "C++17 copy elision invalidates test so forcing expected failure" +#else + +#include <boost/contract/function.hpp> + +int main() { + auto c = boost::contract::function(); // Error (can't use auto). + return 0; +} + +#endif + diff --git a/src/boost/libs/contract/test/specify/auto_pre_error.cpp b/src/boost/libs/contract/test/specify/auto_pre_error.cpp new file mode 100644 index 00000000..1a5b7f60 --- /dev/null +++ b/src/boost/libs/contract/test/specify/auto_pre_error.cpp @@ -0,0 +1,26 @@ + +// 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 auto error after pre (for free func, but same for all contracts). + +#include <boost/config.hpp> +// Not just __cplusplus to detect C++17 as MSVC defines it correctly sometimes. +#if (defined(__cplusplus) && __cplusplus >= 201703L) || \ + !defined(BOOST_NO_CXX17_IF_CONSTEXPR) + #error "C++17 copy elision invalidates test so forcing expected failure" +#else + +#include <boost/contract/function.hpp> + +int main() { + auto c = boost::contract::function() // Error (can't use auto). + .precondition([] {}) + ; + return 0; +} + +#endif + diff --git a/src/boost/libs/contract/test/specify/auto_pre_old_error.cpp b/src/boost/libs/contract/test/specify/auto_pre_old_error.cpp new file mode 100644 index 00000000..6c318769 --- /dev/null +++ b/src/boost/libs/contract/test/specify/auto_pre_old_error.cpp @@ -0,0 +1,27 @@ + +// 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 auto error after old (for free func, but same for all contracts). + +#include <boost/config.hpp> +// Not just __cplusplus to detect C++17 as MSVC defines it correctly sometimes. +#if (defined(__cplusplus) && __cplusplus >= 201703L) || \ + !defined(BOOST_NO_CXX17_IF_CONSTEXPR) + #error "C++17 copy elision invalidates test so forcing expected failure" +#else + +#include <boost/contract/function.hpp> + +int main() { + auto c = boost::contract::function() // Error (can't use auto). + .precondition([] {}) + .old([] {}) + ; + return 0; +} + +#endif + diff --git a/src/boost/libs/contract/test/specify/auto_pre_old_post_error.cpp b/src/boost/libs/contract/test/specify/auto_pre_old_post_error.cpp new file mode 100644 index 00000000..6d0302ff --- /dev/null +++ b/src/boost/libs/contract/test/specify/auto_pre_old_post_error.cpp @@ -0,0 +1,28 @@ + +// 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 auto error after post (for free func, but same for all contracts). + +#include <boost/config.hpp> +// Not just __cplusplus to detect C++17 as MSVC defines it correctly sometimes. +#if (defined(__cplusplus) && __cplusplus >= 201703L) || \ + !defined(BOOST_NO_CXX17_IF_CONSTEXPR) + #error "C++17 copy elision invalidates test so forcing expected failure" +#else + +#include <boost/contract/function.hpp> + +int main() { + auto c = boost::contract::function() // Error (can't use auto). + .precondition([] {}) + .old([] {}) + .postcondition([] {}) + ; + return 0; +} + +#endif + diff --git a/src/boost/libs/contract/test/specify/auto_pre_old_post_except_error.cpp b/src/boost/libs/contract/test/specify/auto_pre_old_post_except_error.cpp new file mode 100644 index 00000000..c51d3295 --- /dev/null +++ b/src/boost/libs/contract/test/specify/auto_pre_old_post_except_error.cpp @@ -0,0 +1,29 @@ + +// 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 auto error after except (for free func, but same for all contracts). + +#include <boost/config.hpp> +// Not just __cplusplus to detect C++17 as MSVC defines it correctly sometimes. +#if (defined(__cplusplus) && __cplusplus >= 201703L) || \ + !defined(BOOST_NO_CXX17_IF_CONSTEXPR) + #error "C++17 copy elision invalidates test so forcing expected failure" +#else + +#include <boost/contract/function.hpp> + +int main() { + auto c = boost::contract::function() // Error (can't use auto). + .precondition([] {}) + .old([] {}) + .postcondition([] {}) + .except([] {}) + ; + return 0; +} + +#endif + diff --git a/src/boost/libs/contract/test/specify/except.cpp b/src/boost/libs/contract/test/specify/except.cpp new file mode 100644 index 00000000..791ba114 --- /dev/null +++ b/src/boost/libs/contract/test/specify/except.cpp @@ -0,0 +1,37 @@ + +// 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 specifying except, no pre, old, or post (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/except_old_error.cpp b/src/boost/libs/contract/test/specify/except_old_error.cpp new file mode 100644 index 00000000..ea865e84 --- /dev/null +++ b/src/boost/libs/contract/test/specify/except_old_error.cpp @@ -0,0 +1,23 @@ + +// 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 old after except error (same if not free func). + +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> + +void f() { + boost::contract::check c = boost::contract::function() + .except([] {}) + .old([] {}) // Error (old after except). + ; +} + +int main() { + f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/specify/except_post_error.cpp b/src/boost/libs/contract/test/specify/except_post_error.cpp new file mode 100644 index 00000000..5b9ef354 --- /dev/null +++ b/src/boost/libs/contract/test/specify/except_post_error.cpp @@ -0,0 +1,23 @@ + +// 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 post after except error (same if not free func). + +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> + +void f() { + boost::contract::check c = boost::contract::function() + .except([] {}) + .postcondition([] {}) // Error (post after except). + ; +} + +int main() { + f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/specify/except_pre_error.cpp b/src/boost/libs/contract/test/specify/except_pre_error.cpp new file mode 100644 index 00000000..3b690662 --- /dev/null +++ b/src/boost/libs/contract/test/specify/except_pre_error.cpp @@ -0,0 +1,23 @@ + +// 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 pre after except error (same if not free func). + +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> + +void f() { + boost::contract::check c = boost::contract::function() + .except([] {}) + .precondition([] {}) // Error (pre after except). + ; +} + +int main() { + f(); + return 0; +} + 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 00000000..7e6f01c0 --- /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(); +} + diff --git a/src/boost/libs/contract/test/specify/nothing.cpp b/src/boost/libs/contract/test/specify/nothing.cpp new file mode 100644 index 00000000..b14a7c0c --- /dev/null +++ b/src/boost/libs/contract/test/specify/nothing.cpp @@ -0,0 +1,32 @@ + +// 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 no pre or post (for free func, but same for all contracts). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function(); + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); ok << "f::body" << std::endl; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/old.cpp b/src/boost/libs/contract/test/specify/old.cpp new file mode 100644 index 00000000..a064d5f9 --- /dev/null +++ b/src/boost/libs/contract/test/specify/old.cpp @@ -0,0 +1,39 @@ + +// 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 specifying old, no pre, post, or except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .old([] { out << "f::old" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/old_except.cpp b/src/boost/libs/contract/test/specify/old_except.cpp new file mode 100644 index 00000000..31af8066 --- /dev/null +++ b/src/boost/libs/contract/test/specify/old_except.cpp @@ -0,0 +1,41 @@ + +// 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 specifying old and except, no pre or post (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .old([] { out << "f::old" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/old_post.cpp b/src/boost/libs/contract/test/specify/old_post.cpp new file mode 100644 index 00000000..97f3eb02 --- /dev/null +++ b/src/boost/libs/contract/test/specify/old_post.cpp @@ -0,0 +1,44 @@ + +// 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 specifying old and post, no pre or except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .old([] { out << "f::old" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/old_post_except.cpp b/src/boost/libs/contract/test/specify/old_post_except.cpp new file mode 100644 index 00000000..36259e60 --- /dev/null +++ b/src/boost/libs/contract/test/specify/old_post_except.cpp @@ -0,0 +1,45 @@ + +// 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 specifying old, post, and except, not pre (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .old([] { out << "f::old" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/old_pre_error.cpp b/src/boost/libs/contract/test/specify/old_pre_error.cpp new file mode 100644 index 00000000..9d9548ce --- /dev/null +++ b/src/boost/libs/contract/test/specify/old_pre_error.cpp @@ -0,0 +1,23 @@ + +// 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 pre after old error (same if not free func). + +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> + +void f() { + boost::contract::check c = boost::contract::function() + .old([] {}) + .precondition([] {}) // Error (pre after old). + ; +} + +int main() { + f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/specify/post.cpp b/src/boost/libs/contract/test/specify/post.cpp new file mode 100644 index 00000000..4930c238 --- /dev/null +++ b/src/boost/libs/contract/test/specify/post.cpp @@ -0,0 +1,39 @@ + +// 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 specifying post, no pre, old, or except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .postcondition([] { out << "f::post" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); ok + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/post_except.cpp b/src/boost/libs/contract/test/specify/post_except.cpp new file mode 100644 index 00000000..115ab6ef --- /dev/null +++ b/src/boost/libs/contract/test/specify/post_except.cpp @@ -0,0 +1,41 @@ + +// 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 specifying post and except, no pre or old (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .postcondition([] { out << "f::post" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/post_old_error.cpp b/src/boost/libs/contract/test/specify/post_old_error.cpp new file mode 100644 index 00000000..7a3361a7 --- /dev/null +++ b/src/boost/libs/contract/test/specify/post_old_error.cpp @@ -0,0 +1,23 @@ + +// 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 old after post error (same if not free func). + +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> + +void f() { + boost::contract::check c = boost::contract::function() + .postcondition([] {}) + .old([] {}) // Error (old after post). + ; +} + +int main() { + f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/specify/post_pre_error.cpp b/src/boost/libs/contract/test/specify/post_pre_error.cpp new file mode 100644 index 00000000..3e50b533 --- /dev/null +++ b/src/boost/libs/contract/test/specify/post_pre_error.cpp @@ -0,0 +1,23 @@ + +// 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 pre after post error (same if not free func). + +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> + +void f() { + boost::contract::check c = boost::contract::function() + .postcondition([] {}) + .precondition([] {}) // Error (pre after post). + ; +} + +int main() { + f(); + return 0; +} + diff --git a/src/boost/libs/contract/test/specify/pre.cpp b/src/boost/libs/contract/test/specify/pre.cpp new file mode 100644 index 00000000..4c02acd2 --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre.cpp @@ -0,0 +1,39 @@ + +// 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 specifying pre, no old, post, or except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_except.cpp b/src/boost/libs/contract/test/specify/pre_except.cpp new file mode 100644 index 00000000..1e7095ce --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_except.cpp @@ -0,0 +1,41 @@ + +// 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 specifying pre and except, no old or post (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_old.cpp b/src/boost/libs/contract/test/specify/pre_old.cpp new file mode 100644 index 00000000..8c1cc763 --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_old.cpp @@ -0,0 +1,44 @@ + +// 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 specifying pre and old, no post or except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .old([] { out << "f::old" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_old_except.cpp b/src/boost/libs/contract/test/specify/pre_old_except.cpp new file mode 100644 index 00000000..99de5bc2 --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_old_except.cpp @@ -0,0 +1,45 @@ + +// 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 specify pre, old, and except, no post (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .old([] { out << "f::old" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_old_post.cpp b/src/boost/libs/contract/test/specify/pre_old_post.cpp new file mode 100644 index 00000000..0ea576f2 --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_old_post.cpp @@ -0,0 +1,48 @@ + +// 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 specifying pre, old, and post, no except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .old([] { out << "f::old" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_old_post_except.cpp b/src/boost/libs/contract/test/specify/pre_old_post_except.cpp new file mode 100644 index 00000000..b6992906 --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_old_post_except.cpp @@ -0,0 +1,49 @@ + +// 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 specifying pre, old, post, and except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .old([] { out << "f::old" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_OLDS + << "f::old" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_post.cpp b/src/boost/libs/contract/test/specify/pre_post.cpp new file mode 100644 index 00000000..ecedebf5 --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_post.cpp @@ -0,0 +1,44 @@ + +// 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 specifying pre and post, no old or except (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/contract/test/specify/pre_post_except.cpp b/src/boost/libs/contract/test/specify/pre_post_except.cpp new file mode 100644 index 00000000..1b22e2ec --- /dev/null +++ b/src/boost/libs/contract/test/specify/pre_post_except.cpp @@ -0,0 +1,45 @@ + +// 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 specify pre, post, and except, no old (same if not free func). + +#include "../detail/oteststream.hpp" +#include <boost/contract/function.hpp> +#include <boost/contract/check.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <sstream> + +boost::contract::test::detail::oteststream out; + +void f() { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) + ; + out << "f::body" << std::endl; +} + +int main() { + std::ostringstream ok; + + out.str(""); + f(); + ok.str(""); + ok + #ifndef BOOST_CONTRACT_NO_PRECONDITIONS + << "f::pre" << std::endl + #endif + << "f::body" << std::endl + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + << "f::post" << std::endl + #endif + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + |