From c5df888fc4d3be374f178d026a76e20a94cc2b70 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Thu, 15 Dec 2016 02:15:50 -0800 Subject: [PATCH] passing all tests with all link combinations shared, static, and header --- include/boost/contract.hpp | 2 +- include/boost/contract/core/config.hpp | 2 -- include/boost/contract/function.hpp | 2 +- test/Jamfile.v2 | 10 +++---- test/detail/oteststream.hpp | 25 ---------------- test/detail/out.hpp | 18 ++++++++++++ test/detail/out_inlined.hpp | 28 ++++++++++++++++++ ...cpp => always_disable_post_except_lib.cpp} | 3 ++ ... => assertions_disable_assertions_lib.cpp} | 2 +- .../assertions_disable_assertions_prog.cpp | 10 +++++++ test/disable/lib_a.cpp | 8 +++-- test/disable/lib_a.hpp | 12 ++++---- test/disable/lib_a_inlined.hpp | 24 ++++++++++----- test/disable/lib_ab.hpp | 24 +++++---------- test/disable/lib_b.cpp | 2 -- test/disable/lib_b.hpp | 2 -- test/disable/lib_b_inlined.hpp | 29 +++++++++++++++---- test/disable/lib_x.cpp | 6 ++-- test/disable/lib_x.hpp | 8 ++--- test/disable/lib_y.cpp | 7 +++-- test/disable/lib_y.hpp | 3 +- ....cpp => pre_disable_no_assertion_prog.cpp} | 8 ++--- test/disable/{prog.cpp => prog.hpp} | 3 +- test/function/throwing_old.cpp | 2 +- test/function/throwing_pre.cpp | 2 +- 25 files changed, 142 insertions(+), 100 deletions(-) create mode 100644 test/detail/out.hpp create mode 100644 test/detail/out_inlined.hpp rename test/disable/{lib_xy.cpp => always_disable_post_except_lib.cpp} (94%) rename test/disable/{lib_ab.cpp => assertions_disable_assertions_lib.cpp} (79%) create mode 100644 test/disable/assertions_disable_assertions_prog.cpp rename test/disable/{prog_pre_disable_nothing.cpp => pre_disable_no_assertion_prog.cpp} (63%) rename test/disable/{prog.cpp => prog.hpp} (83%) diff --git a/include/boost/contract.hpp b/include/boost/contract.hpp index fd5d9f6..fa5f696 100644 --- a/include/boost/contract.hpp +++ b/include/boost/contract.hpp @@ -25,7 +25,7 @@ never be used directly by programmers. @see @RefSect{getting_started, Getting Started} */ -// TODO: Make all tests pass also with link=static and link=header (some tests fails now...). +// TODO: Document that this lib will not work in general if link!=shared (link=static and link=header only provided for convenience because they might work OK in simple cases of a single program, but won't work in general with multiple programs/libs so only link=shared should be used in real code). // TODO: Document that boost::contract::function() can be used to program contracts for lambda functions. And also "abused" a bit to program pre/postconditions for any arbitrary scope of code in function body. diff --git a/include/boost/contract/core/config.hpp b/include/boost/contract/core/config.hpp index b79f6ac..be68bb0 100644 --- a/include/boost/contract/core/config.hpp +++ b/include/boost/contract/core/config.hpp @@ -7,8 +7,6 @@ // 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 -// TODO: Find out the C++ example that gives linker error on global variables that are not static/extern and then test this library against that example (for all boost_link mode: shared, static, and header-only). - /** @file Facilities to configure this library compile-time and run-time behaviour. */ diff --git a/include/boost/contract/function.hpp b/include/boost/contract/function.hpp index 55eb9cb..528332d 100644 --- a/include/boost/contract/function.hpp +++ b/include/boost/contract/function.hpp @@ -34,7 +34,7 @@ preconditions and postconditions. of the contracted function (otherwise this library will generate a run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}). */ -specify_precondition_old_postcondition_except<> function() { +inline specify_precondition_old_postcondition_except<> function() { // Must #if also on ..._INVARIANTS here because specify_... is generic. #if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \ !defined(BOOST_CONTRACT_NO_INVARIANTS) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6c965b9..4b162c8 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -158,7 +158,7 @@ test-suite public_function : [ subdir-run public_function : override_permissive ] [ subdir-run public_function : static ] - [ subdir-run public_function : static_ifdef ] + [ subdir-run public_function : static_ifdef_contracts ] [ subdir-run public_function : static_throwing_pre ] [ subdir-run public_function : static_throwing_old ] @@ -237,21 +237,21 @@ test-suite old : ; test-suite disable : - [ subdir-run disable : prog ] - [ subdir-run disable : prog_pre_disable_nothing ] + [ subdir-run disable : pre_disable_no_assertion_prog ] + [ subdir-run disable : assertions_disable_assertions_prog ] [ subdir-lib disable : lib_a : shared:BOOST_CONTRACT_TEST_LIB_A_DYN_LINK ] [ subdir-lib disable : lib_b : disable-lib_a shared:BOOST_CONTRACT_TEST_LIB_B_DYN_LINK ] - [ subdir-run disable : lib_ab : + [ subdir-run disable : assertions_disable_assertions_lib : disable-lib_a disable-lib_b ] [ subdir-lib disable : lib_x : shared:BOOST_CONTRACT_TEST_LIB_X_DYN_LINK ] [ subdir-lib disable : lib_y : disable-lib_x shared:BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK ] - [ subdir-run disable : lib_xy : + [ subdir-run disable : always_disable_post_except_lib : disable-lib_x disable-lib_y ] ; diff --git a/test/detail/oteststream.hpp b/test/detail/oteststream.hpp index 343e3ec..a91a5b3 100644 --- a/test/detail/oteststream.hpp +++ b/test/detail/oteststream.hpp @@ -13,31 +13,6 @@ #include #include -// Convenience to declare test string functions across shared libs. -#define BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DECL(declspec, func) \ - std::string declspec func(); \ - void declspec func(std::string const& text); - -#define BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DEF(func) \ - namespace boost { namespace contract { namespace test { namespace detail { \ - namespace oteststream_ { \ - std::string func; \ - } } } } } \ - \ - std::string func() { \ - return boost::contract::test::detail::oteststream_::func; \ - } \ - \ - void func(std::string const& text) { \ - if(text == "") boost::contract::test::detail::oteststream_::func = ""; \ - else { \ - boost::contract::test::detail::oteststream_::func = \ - boost::contract::test::detail::oteststream_::func + text; \ - std::clog << text; \ - std::clog.flush(); \ - } \ - } - namespace boost { namespace contract { namespace test { namespace detail { namespace oteststream_ { diff --git a/test/detail/out.hpp b/test/detail/out.hpp new file mode 100644 index 0000000..689ceed --- /dev/null +++ b/test/detail/out.hpp @@ -0,0 +1,18 @@ + +#ifndef BOOST_CONTRACT_TEST_DETAIL_OUT_HPP_ +#define BOOST_CONTRACT_TEST_DETAIL_OUT_HPP_ + +// To declare test string functions across shared libraries. + +#include + +namespace boost { namespace contract { namespace test { namespace detail { + +std::string BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC out(); + +void BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC out(std::string const& text); + +} } } } + +#endif // #include guard + diff --git a/test/detail/out_inlined.hpp b/test/detail/out_inlined.hpp new file mode 100644 index 0000000..65585c3 --- /dev/null +++ b/test/detail/out_inlined.hpp @@ -0,0 +1,28 @@ + +#ifndef BOOST_CONTRACT_TEST_OUT_INLINED_HPP_ +#define BOOST_CONTRACT_TEST_OUT_INLINED_HPP_ + +#include "out.hpp" +#include + +namespace boost { namespace contract { namespace test { namespace detail { + +namespace out_ { + std::string out; +} + +std::string out() { return out_::out; } + +void out(std::string const& text) { + if(text == "") out_::out = ""; + else { + out_::out = out_::out + text; + std::clog << text; + std::clog.flush(); + } +} + +} } } } + +#endif // #include guard + diff --git a/test/disable/lib_xy.cpp b/test/disable/always_disable_post_except_lib.cpp similarity index 94% rename from test/disable/lib_xy.cpp rename to test/disable/always_disable_post_except_lib.cpp index 6463d9b..388d188 100644 --- a/test/disable/lib_xy.cpp +++ b/test/disable/always_disable_post_except_lib.cpp @@ -8,12 +8,14 @@ #include "lib_x.hpp" #include "lib_y.hpp" +#include "../detail/oteststream.hpp" #include #include #include #include void f() { + using boost::contract::test::detail::out; boost::contract::check c = boost::contract::function() .precondition([] { out("f::pre\n"); }) .old([] { out("f::old\n"); }) @@ -23,6 +25,7 @@ void f() { } int main() { + using boost::contract::test::detail::out; std::ostringstream ok; out(""); diff --git a/test/disable/lib_ab.cpp b/test/disable/assertions_disable_assertions_lib.cpp similarity index 79% rename from test/disable/lib_ab.cpp rename to test/disable/assertions_disable_assertions_lib.cpp index 9e18005..172ddf3 100644 --- a/test/disable/lib_ab.cpp +++ b/test/disable/assertions_disable_assertions_lib.cpp @@ -4,7 +4,7 @@ // 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 other contract checking disabled within contract checking (among libs). +// Test assertion checking disables other assertion checking (in libraries). #include "lib_ab.hpp" diff --git a/test/disable/assertions_disable_assertions_prog.cpp b/test/disable/assertions_disable_assertions_prog.cpp new file mode 100644 index 0000000..687a8bc --- /dev/null +++ b/test/disable/assertions_disable_assertions_prog.cpp @@ -0,0 +1,10 @@ + +// Copyright (C) 2008-2016 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 assertion checking disables other assertion checking (in programs). + +#include "prog.hpp" + diff --git a/test/disable/lib_a.cpp b/test/disable/lib_a.cpp index 36f3b98..61bcb88 100644 --- a/test/disable/lib_a.cpp +++ b/test/disable/lib_a.cpp @@ -4,8 +4,10 @@ // 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 other contract checking disabled within contract checking (among libs). - #define BOOST_CONTRACT_TEST_LIB_A_SOURCE -#include "lib_a_inlined.hpp" +#include "lib_a.hpp" +#ifndef BOOST_CONTRACT_HEADER_ONLY + #include "lib_a_inlined.hpp" +#endif +#include "../detail/out_inlined.hpp" diff --git a/test/disable/lib_a.hpp b/test/disable/lib_a.hpp index 0c014b7..7c3403c 100644 --- a/test/disable/lib_a.hpp +++ b/test/disable/lib_a.hpp @@ -7,13 +7,10 @@ // 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 -#include "../detail/oteststream.hpp" #include "../detail/counter.hpp" #include #include -// Test other contract checking disabled within contract checking (among libs). - #ifdef BOOST_CONTRACT_TEST_LIB_A_DYN_LINK #ifdef BOOST_CONTRACT_TEST_LIB_A_SOURCE #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC BOOST_SYMBOL_EXPORT @@ -24,8 +21,9 @@ #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC /* nothing */ #endif -BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DECL( - BOOST_CONTRACT_TEST_LIB_A_DECLSPEC, out) +#define BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC \ + BOOST_CONTRACT_TEST_LIB_A_DECLSPEC +#include "../detail/out.hpp" struct BOOST_CONTRACT_TEST_LIB_A_DECLSPEC a { static void static_invariant(); @@ -44,5 +42,9 @@ struct BOOST_CONTRACT_TEST_LIB_A_DECLSPEC a { static void disable_failure(); }; +#ifdef BOOST_CONTRACT_HEADER_ONLY + #include "lib_a_inlined.hpp" +#endif + #endif // #include guard diff --git a/test/disable/lib_a_inlined.hpp b/test/disable/lib_a_inlined.hpp index ab84db7..42fea7c 100644 --- a/test/disable/lib_a_inlined.hpp +++ b/test/disable/lib_a_inlined.hpp @@ -1,26 +1,30 @@ -#ifndef BOOST_TEST_LIB_A_INLINED_HPP_ -#define BOOST_TEST_LIB_A_INLINED_HPP_ +#ifndef BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ +#define BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ // Copyright (C) 2008-2016 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 other contract checking disabled within contract checking (among libs). - #include "lib_a.hpp" #include #include #include #include -BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DEF(out) +void a::static_invariant() { + using boost::contract::test::detail::out; + out("a::static_inv\n"); +} -void a::static_invariant() { out("a::static_inv\n"); } -void a::invariant() const { out("a::inv\n"); } +void a::invariant() const { + using boost::contract::test::detail::out; + out("a::inv\n"); +} int a::f(x_type& x) { + using boost::contract::test::detail::out; int result; boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD( x_type::eval(x)); @@ -40,31 +44,37 @@ int a::f(x_type& x) { } void a::disable_pre_failure() { + using boost::contract::test::detail::out; boost::contract::set_precondition_failure([] (boost::contract::from) { out("a::pre_failure\n"); }); } void a::disable_post_failure() { + using boost::contract::test::detail::out; boost::contract::set_postcondition_failure([] (boost::contract::from) { out("a::post_failure\n"); }); } void a::disable_entry_inv_failure() { + using boost::contract::test::detail::out; boost::contract::set_entry_invariant_failure([] (boost::contract::from) { out("a::entry_inv_failure\n"); }); } void a::disable_exit_inv_failure() { + using boost::contract::test::detail::out; boost::contract::set_exit_invariant_failure([] (boost::contract::from) { out("a::exit_inv_failure\n"); }); } void a::disable_inv_failure() { + using boost::contract::test::detail::out; boost::contract::set_invariant_failure([] (boost::contract::from) { out("a::inv_failure\n"); }); } void a::disable_failure() { + using boost::contract::test::detail::out; boost::contract::set_specification_failure([] (boost::contract::from) { out("a::failure\n"); }); } diff --git a/test/disable/lib_ab.hpp b/test/disable/lib_ab.hpp index 6555066..95ac35c 100644 --- a/test/disable/lib_ab.hpp +++ b/test/disable/lib_ab.hpp @@ -4,10 +4,9 @@ // 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 other contract checking disabled within contract checking (among libs). - #include "lib_a.hpp" #include "lib_b.hpp" +#include "../detail/oteststream.hpp" #include #include #include @@ -40,6 +39,7 @@ std::string ok_f() { } int main() { + using boost::contract::test::detail::out; std::ostringstream ok; b bb; @@ -52,11 +52,7 @@ int main() { #endif #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "b::g::pre" << std::endl - #ifdef BOOST_CONTRACT_HEADER_ONLY - // Test preconditions have disabled no contract (incorrect, but - // only possible behaviour if shared linking not used ad doc). - << ok_f() - #elif defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION) + #ifdef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION // Test preconditions have disabled no contract. << ok_f() #else @@ -75,19 +71,14 @@ int main() { #endif #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "b::g::post" << std::endl - #ifdef BOOST_CONTRACT_HEADER_ONLY - // Test preconditions have disabled no contract (incorrect, but - // only possible behaviour if shared linking not used ad doc). - << ok_f() - #else - // Test call while checking executes body (but no contracts). - << "a::f::body" << std::endl - #endif + // Test call while checking executes body (but no contracts). + << "a::f::body" << std::endl #endif ; BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); // Test old values not copied for disabled contracts. + #if defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION) && \ !defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ ( \ @@ -98,12 +89,13 @@ int main() { #else #define BOOST_CONTRACT_TEST_old 0u #endif - ; + BOOST_TEST_EQ(a::x_type::copies(), BOOST_CONTRACT_TEST_old); BOOST_TEST_EQ(a::x_type::evals(), BOOST_CONTRACT_TEST_old); BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); // Double check a call to f outside another contract checks f's contracts. + out(""); call_f(); BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok_f())); diff --git a/test/disable/lib_b.cpp b/test/disable/lib_b.cpp index fecfde5..9e264c0 100644 --- a/test/disable/lib_b.cpp +++ b/test/disable/lib_b.cpp @@ -4,8 +4,6 @@ // 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 other contract checking disabled within contract checking (among libs). - #define BOOST_CONTRACT_TEST_LIB_B_SOURCE #include "lib_b_inlined.hpp" diff --git a/test/disable/lib_b.hpp b/test/disable/lib_b.hpp index 2a18917..37d5799 100644 --- a/test/disable/lib_b.hpp +++ b/test/disable/lib_b.hpp @@ -7,8 +7,6 @@ // 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 other contract checking disabled within contract checking (among libs). - #include #ifdef BOOST_CONTRACT_TEST_LIB_B_DYN_LINK diff --git a/test/disable/lib_b_inlined.hpp b/test/disable/lib_b_inlined.hpp index 23c3138..13aebaa 100644 --- a/test/disable/lib_b_inlined.hpp +++ b/test/disable/lib_b_inlined.hpp @@ -1,16 +1,15 @@ -#ifndef BOOST_TEST_LIB_B_INLINED_HPP_ -#define BOOST_TEST_LIB_B_INLINED_HPP_ +#ifndef BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_ +#define BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_ // Copyright (C) 2008-2016 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 other contract checking disabled within contract checking (among libs). - #include "lib_b.hpp" #include "lib_a.hpp" +#include "../detail/oteststream.hpp" #include #include #include @@ -21,10 +20,18 @@ bool call_f() { return aa.f(x) == -123; } -void b::static_invariant() { out("b::static_inv\n"); } -void b::invariant() const { out("b::inv\n"); } +void b::static_invariant() { + using boost::contract::test::detail::out; + out("b::static_inv\n"); +} + +void b::invariant() const { + using boost::contract::test::detail::out; + out("b::inv\n"); +} void b::g() { + using boost::contract::test::detail::out; boost::contract::check c = boost::contract::public_function(this) .precondition([&] { out("b::g::pre\n"); @@ -40,6 +47,7 @@ void b::g() { } bool b::test_disable_pre_failure() { + using boost::contract::test::detail::out; a::disable_pre_failure(); out(""); boost::contract::precondition_failure(boost::contract::from()); @@ -48,6 +56,7 @@ bool b::test_disable_pre_failure() { } bool b::test_disable_post_failure() { + using boost::contract::test::detail::out; a::disable_post_failure(); out(""); boost::contract::postcondition_failure(boost::contract::from()); @@ -56,6 +65,7 @@ bool b::test_disable_post_failure() { } bool b::test_disable_entry_inv_failure() { + using boost::contract::test::detail::out; a::disable_entry_inv_failure(); out(""); boost::contract::entry_invariant_failure(boost::contract::from()); @@ -64,6 +74,7 @@ bool b::test_disable_entry_inv_failure() { } bool b::test_disable_exit_inv_failure() { + using boost::contract::test::detail::out; a::disable_exit_inv_failure(); out(""); boost::contract::exit_invariant_failure(boost::contract::from()); @@ -72,6 +83,8 @@ bool b::test_disable_exit_inv_failure() { } bool b::test_disable_inv_failure() { + using boost::contract::test::detail::out; + a::disable_inv_failure(); out(""); boost::contract::entry_invariant_failure(boost::contract::from()); @@ -81,10 +94,13 @@ bool b::test_disable_inv_failure() { boost::contract::exit_invariant_failure(boost::contract::from()); bool exit_inv = boost::contract::test::detail::oteststream::eq(out(), "a::inv_failure\n"); + return entry_inv && exit_inv; } bool b::test_disable_failure() { + using boost::contract::test::detail::out; + a::disable_failure(); out(""); boost::contract::precondition_failure(boost::contract::from()); @@ -102,6 +118,7 @@ bool b::test_disable_failure() { boost::contract::exit_invariant_failure(boost::contract::from()); bool exit_inv = boost::contract::test::detail::oteststream::eq(out(), "a::failure\n"); + return pre && post && entry_inv && exit_inv; } diff --git a/test/disable/lib_x.cpp b/test/disable/lib_x.cpp index 2b25b90..bb3af6c 100644 --- a/test/disable/lib_x.cpp +++ b/test/disable/lib_x.cpp @@ -4,8 +4,6 @@ // 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 contracts in .cpp compiled to never check post/except. - // Force .cpp never check post/except. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS #define BOOST_CONTRACT_NO_POSTCONDITIONS @@ -18,10 +16,10 @@ #include "lib_x.hpp" #include #include - -BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DEF(out) +#include "../detail/out_inlined.hpp" void x() { + using boost::contract::test::detail::out; boost::contract::check c = boost::contract::function() .precondition([] { out("x::pre\n"); }) .old([] { out("x::old\n"); }) diff --git a/test/disable/lib_x.hpp b/test/disable/lib_x.hpp index 2209ff1..639be3d 100644 --- a/test/disable/lib_x.hpp +++ b/test/disable/lib_x.hpp @@ -7,9 +7,6 @@ // 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 contracts in .cpp compiled to never check post/except. - -#include "../detail/oteststream.hpp" #include #include @@ -23,8 +20,9 @@ #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC /* nothing */ #endif -BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DECL( - BOOST_CONTRACT_TEST_LIB_X_DECLSPEC, out) +#define BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC \ + BOOST_CONTRACT_TEST_LIB_X_DECLSPEC +#include "../detail/out.hpp" void BOOST_CONTRACT_TEST_LIB_X_DECLSPEC x(); diff --git a/test/disable/lib_y.cpp b/test/disable/lib_y.cpp index 6773a56..135f4e3 100644 --- a/test/disable/lib_y.cpp +++ b/test/disable/lib_y.cpp @@ -4,8 +4,6 @@ // 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 contracts in .cpp compiled to never check post/except. - // Force .cpp never check post/except. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS #define BOOST_CONTRACT_NO_POSTCONDITIONS @@ -18,6 +16,9 @@ #include "lib_y.hpp" namespace lib_y_ { - void y_body() { out("y::body\n"); } + void y_body() { + using boost::contract::test::detail::out; + out("y::body\n"); + } } diff --git a/test/disable/lib_y.hpp b/test/disable/lib_y.hpp index 7e411ea..0dff599 100644 --- a/test/disable/lib_y.hpp +++ b/test/disable/lib_y.hpp @@ -7,8 +7,6 @@ // 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 contracts in .cpp compiled to never check post/except. - #include "lib_x.hpp" #include #include @@ -29,6 +27,7 @@ namespace lib_y_ { // Internal namepsace. } inline void y() { + using boost::contract::test::detail::out; boost::contract::check c = boost::contract::function() .precondition([] { out("y::pre\n"); }) .old([] { out("y::old\n"); }) diff --git a/test/disable/prog_pre_disable_nothing.cpp b/test/disable/pre_disable_no_assertion_prog.cpp similarity index 63% rename from test/disable/prog_pre_disable_nothing.cpp rename to test/disable/pre_disable_no_assertion_prog.cpp index 844d784..1bed5b7 100644 --- a/test/disable/prog_pre_disable_nothing.cpp +++ b/test/disable/pre_disable_no_assertion_prog.cpp @@ -4,12 +4,8 @@ // 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 other contract checking but pre disabled within contract checking. +// Test pre disable no assertion (in programs, but same for libraries). #define BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION -#include "lib_a.hpp" -#include "lib_a_inlined.hpp" -#include "lib_b.hpp" -#include "lib_b_inlined.hpp" -#include "lib_ab.hpp" +#include "prog.hpp" diff --git a/test/disable/prog.cpp b/test/disable/prog.hpp similarity index 83% rename from test/disable/prog.cpp rename to test/disable/prog.hpp index e4131d1..28fa359 100644 --- a/test/disable/prog.cpp +++ b/test/disable/prog.hpp @@ -4,11 +4,10 @@ // 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 other contract checking disabled within contract checking (in a prog). - #include "lib_a.hpp" #include "lib_a_inlined.hpp" #include "lib_b.hpp" #include "lib_b_inlined.hpp" #include "lib_ab.hpp" +#include "../detail/out_inlined.hpp" diff --git a/test/function/throwing_old.cpp b/test/function/throwing_old.cpp index 596a1b6..aaabbfb 100644 --- a/test/function/throwing_old.cpp +++ b/test/function/throwing_old.cpp @@ -42,7 +42,7 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif - ok.str(""); ok << + ok.str(""); ok #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "f::pre" << std::endl #endif diff --git a/test/function/throwing_pre.cpp b/test/function/throwing_pre.cpp index c16747d..3c27810 100644 --- a/test/function/throwing_pre.cpp +++ b/test/function/throwing_pre.cpp @@ -42,7 +42,7 @@ int main() { BOOST_TEST(false); } catch(err const&) { #endif - ok.str(""); ok << + ok.str(""); ok #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "f::pre" << std::endl // Test this threw. #else