passing all tests with all link combinations shared, static, and header

This commit is contained in:
Lorenzo Caminiti
2016-12-15 02:15:50 -08:00
parent ca2071b6a3
commit c5df888fc4
25 changed files with 142 additions and 100 deletions

View File

@@ -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 :
<link>shared:<define>BOOST_CONTRACT_TEST_LIB_A_DYN_LINK ]
[ subdir-lib disable : lib_b : <library>disable-lib_a
<link>shared:<define>BOOST_CONTRACT_TEST_LIB_B_DYN_LINK ]
[ subdir-run disable : lib_ab :
[ subdir-run disable : assertions_disable_assertions_lib :
<library>disable-lib_a <library>disable-lib_b ]
[ subdir-lib disable : lib_x :
<link>shared:<define>BOOST_CONTRACT_TEST_LIB_X_DYN_LINK ]
[ subdir-lib disable : lib_y : <library>disable-lib_x
<link>shared:<define>BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK ]
[ subdir-run disable : lib_xy :
[ subdir-run disable : always_disable_post_except_lib :
<library>disable-lib_x <library>disable-lib_y ]
;

View File

@@ -13,31 +13,6 @@
#include <sstream>
#include <iostream>
// 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_ {

18
test/detail/out.hpp Normal file
View File

@@ -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 <string>
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

View File

@@ -0,0 +1,28 @@
#ifndef BOOST_CONTRACT_TEST_OUT_INLINED_HPP_
#define BOOST_CONTRACT_TEST_OUT_INLINED_HPP_
#include "out.hpp"
#include <iostream>
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

View File

@@ -8,12 +8,14 @@
#include "lib_x.hpp"
#include "lib_y.hpp"
#include "../detail/oteststream.hpp"
#include <boost/contract/function.hpp>
#include <boost/contract/check.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <sstream>
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("");

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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 <boost/config.hpp>
#include <string>
// 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

View File

@@ -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 <boost/contract/public_function.hpp>
#include <boost/contract/old.hpp>
#include <boost/contract/check.hpp>
#include <boost/contract/assert.hpp>
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<x_type> 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"); });
}

View File

@@ -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 <boost/contract/core/exception.hpp>
#include <boost/contract/core/config.hpp>
#include <boost/detail/lightweight_test.hpp>
@@ -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()));

View File

@@ -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"

View File

@@ -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 <boost/config.hpp>
#ifdef BOOST_CONTRACT_TEST_LIB_B_DYN_LINK

View File

@@ -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 <boost/contract/public_function.hpp>
#include <boost/contract/check.hpp>
#include <boost/contract/assert.hpp>
@@ -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;
}

View File

@@ -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 <boost/contract/function.hpp>
#include <boost/contract/check.hpp>
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"); })

View File

@@ -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 <boost/config.hpp>
#include <string>
@@ -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();

View File

@@ -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");
}
}

View File

@@ -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 <boost/contract/function.hpp>
#include <boost/contract/check.hpp>
@@ -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"); })

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -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