From 524d58ac9a4a44b9454d339f2e8abc5d341f65c1 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 25 Apr 2015 19:33:48 -0700 Subject: [PATCH] compiling all tests after some reorganization --- Jamroot | 13 ++++++ include/boost/contract/exception.hpp | 45 ++++++++++--------- include/boost/contract/set/nothing.hpp | 17 +++---- .../boost/contract/set/postcondition_only.hpp | 18 +++----- .../boost/contract/set/precondition_only.hpp | 16 +++---- .../set/precondition_postcondition.hpp | 19 +++----- include/boost/contract/type.hpp | 2 +- test/Jamfile.v2 | 44 +++++++++--------- test/constructor/Jamfile.v2 | 9 ---- test/constructor/set_post_post_error.cpp | 20 --------- test/constructor/set_post_pre_error.cpp | 20 --------- test/constructor/set_pre_error.cpp | 19 -------- test/free_function/Jamfile.v2 | 12 ----- test/free_function/set_post_post_error.cpp | 12 ----- .../free_function/set_post_pre_post_error.cpp | 13 ------ test/free_function/set_post_pre_pre_error.cpp | 13 ------ .../free_function/set_pre_post_post_error.cpp | 13 ------ test/free_function/set_pre_post_pre_error.cpp | 13 ------ test/free_function/set_pre_pre_error.cpp | 12 ----- .../constructor_bases.cpp} | 0 test/{ => function}/destructor_bases.cpp | 2 +- .../call.cpp => function/free_function.cpp} | 0 test/{ => function}/private_member_bases.cpp | 2 +- .../{ => function}/protected_member_bases.cpp | 2 +- .../public_member_bases_static.cpp | 2 +- .../public_member_bases_virtual.cpp | 2 +- .../creation_set_post_nothing_comb.cpp} | 12 ++--- test/set/creation_set_post_post_error.cpp | 20 +++++++++ test/set/creation_set_post_pre_error.cpp | 20 +++++++++ test/set/creation_set_pre_error.cpp | 19 ++++++++ test/set/function_set_post_post_error.cpp | 14 ++++++ test/set/function_set_post_pre_post_error.cpp | 15 +++++++ test/set/function_set_post_pre_pre_error.cpp | 15 +++++++ .../function_set_pre_post_nothing_comb.cpp} | 19 ++++---- test/set/function_set_pre_post_post_error.cpp | 15 +++++++ test/set/function_set_pre_post_pre_error.cpp | 15 +++++++ test/set/function_set_pre_pre_error.cpp | 14 ++++++ test/{ => type_traits}/base_types.cpp | 0 test/{ => type_traits}/has_bases.cpp | 0 test/{ => type_traits}/has_invariant.cpp | 0 test/{ => type_traits}/introspect.cpp | 0 41 files changed, 250 insertions(+), 268 deletions(-) delete mode 100644 test/constructor/Jamfile.v2 delete mode 100644 test/constructor/set_post_post_error.cpp delete mode 100644 test/constructor/set_post_pre_error.cpp delete mode 100644 test/constructor/set_pre_error.cpp delete mode 100644 test/free_function/Jamfile.v2 delete mode 100644 test/free_function/set_post_post_error.cpp delete mode 100644 test/free_function/set_post_pre_post_error.cpp delete mode 100644 test/free_function/set_post_pre_pre_error.cpp delete mode 100644 test/free_function/set_pre_post_post_error.cpp delete mode 100644 test/free_function/set_pre_post_pre_error.cpp delete mode 100644 test/free_function/set_pre_pre_error.cpp rename test/{constructor/with_bases.cpp => function/constructor_bases.cpp} (100%) rename test/{ => function}/destructor_bases.cpp (98%) rename test/{free_function/call.cpp => function/free_function.cpp} (100%) rename test/{ => function}/private_member_bases.cpp (98%) rename test/{ => function}/protected_member_bases.cpp (98%) rename test/{ => function}/public_member_bases_static.cpp (98%) rename test/{ => function}/public_member_bases_virtual.cpp (99%) rename test/{constructor/set.cpp => set/creation_set_post_nothing_comb.cpp} (87%) create mode 100644 test/set/creation_set_post_post_error.cpp create mode 100644 test/set/creation_set_post_pre_error.cpp create mode 100644 test/set/creation_set_pre_error.cpp create mode 100644 test/set/function_set_post_post_error.cpp create mode 100644 test/set/function_set_post_pre_post_error.cpp create mode 100644 test/set/function_set_post_pre_pre_error.cpp rename test/{free_function/set.cpp => set/function_set_pre_post_nothing_comb.cpp} (72%) create mode 100644 test/set/function_set_pre_post_post_error.cpp create mode 100644 test/set/function_set_pre_post_pre_error.cpp create mode 100644 test/set/function_set_pre_pre_error.cpp rename test/{ => type_traits}/base_types.cpp (100%) rename test/{ => type_traits}/has_bases.cpp (100%) rename test/{ => type_traits}/has_invariant.cpp (100%) rename test/{ => type_traits}/introspect.cpp (100%) diff --git a/Jamroot b/Jamroot index 15a34ea..efad850 100644 --- a/Jamroot +++ b/Jamroot @@ -1,6 +1,19 @@ +import testing ; import os ; +rule subdir-run ( subdir : cpp_fname : requirements * ) +{ + run $(subdir)/$(cpp_fname).cpp : : : $(subdir) $(requirements) : + $(subdir)/$(cpp_fname) ; +} + +rule subdir-compile-fail ( subdir : cpp_fname : requirements * ) +{ + compile-fail $(subdir)/$(cpp_fname).cpp : + $(subdir) $(requirements) : $(subdir)/$(cpp_fname) ; +} + if ! [ os.environ BOOST_ROOT ] { exit "Error: Set BOOST_ROOT environment variable to Boost root directory" ; } diff --git a/include/boost/contract/exception.hpp b/include/boost/contract/exception.hpp index 5e7ee43..f06aaba 100644 --- a/include/boost/contract/exception.hpp +++ b/include/boost/contract/exception.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include // TODO: Implement set_precondition/postcondition/invariant/entry_invariant/ @@ -24,10 +25,10 @@ struct assertion_failure : public std::exception { file_(""), line_(0), code_(code) { init(); } - virtual ~assertion_failue() {} + virtual ~assertion_failure() {} // Return `assertion "XYZ" failed: file "ABC", line 123`. - virtual char const* const what() const { return what_.c_str(); } + virtual char const* what() const BOOST_NOEXCEPT { return what_.c_str(); } char const* const file() const { return file_; } unsigned long line() const { return line_; } @@ -35,13 +36,15 @@ struct assertion_failure : public std::exception { private: void init() { - what_ = "assertion"; - if(std::string(code_) != "") what_ += " \"" + code_ + "\""; - what_ += " failed"; + std::ostringstream text; + text.str("assertion"); + if(std::string(code_) != "") text << " \"" << code_ << "\""; + text << " failed"; if(std::string(file_) != "") { - what_ += ": \"" + file_ + "\""; - if(line != 0) what_ += ", line " + std::string(line_); + text << ": \"" << file_ << "\""; + if(line_ != 0) text << ", line " << line_; } + what_ = text.str(); } char const* const file_; @@ -53,9 +56,9 @@ private: struct precondition_failure : public assertion_failure { explicit precondition_failure(assertion_failure const& failure) : assertion_failure(failure) { - what_ = "precondition " + assertion_failure::what(); + what_ = std::string("precondition ") + assertion_failure::what(); } - virtual char const* const what() const { return what_.c_str(); } + virtual char const* what() const BOOST_NOEXCEPT { return what_.c_str(); } private: std::string what_; }; @@ -63,9 +66,9 @@ private: struct postcondition_failure : public assertion_failure { explicit postcondition_failure(assertion_failure const& failure) : assertion_failure(failure) { - what_ = "postcondition " + assertion_failure::what(); + what_ = std::string("postcondition ") + assertion_failure::what(); } - virtual char const* const what() const { return what_.c_str(); } + virtual char const* what() const BOOST_NOEXCEPT { return what_.c_str(); } private: std::string what_; }; @@ -75,9 +78,9 @@ struct invariant_failure : public assertion_failure {}; struct entry_invariant_failure : public assertion_failure { explicit entry_invariant_failure(assertion_failure const& failure) : assertion_failure(failure) { - what_ = "exit invariant " + assertion_failure::what(); + what_ = std::string("exit invariant ") + assertion_failure::what(); } - virtual char const* const what() const { return what_.c_str(); } + virtual char const* what() const BOOST_NOEXCEPT { return what_.c_str(); } private: std::string what_; }; @@ -85,9 +88,9 @@ private: struct exit_invariant_failure : public assertion_failure { explicit exit_invariant_failure(assertion_failure const& failure) : assertion_failure(failure) { - what_ = "exit invariant " + assertion_failure::what(); + what_ = std::string("exit invariant ") + assertion_failure::what(); } - virtual char const* const what() const { return what_.c_str(); } + virtual char const* what() const BOOST_NOEXCEPT { return what_.c_str(); } private: std::string what_; }; @@ -112,7 +115,7 @@ namespace aux { void default_handler(from const) { try { throw; - } catch(boost::contract::failure const& error) { + } catch(boost::contract::assertion_failure const& error) { std::cerr << error.what() << std::endl; std::terminate(); } catch(...) { @@ -120,10 +123,10 @@ namespace aux { } } - failure_hander precondition_failure_handler = &default_handler; - failure_hander postcondition_failure_handler = &default_handler; - failure_hander entry_invariant_failure_handler = &default_handler; - failure_hander exit_invariant_failure_handler = &default_handler; + failure_handler precondition_failure_handler = &default_handler; + failure_handler postcondition_failure_handler = &default_handler; + failure_handler entry_invariant_failure_handler = &default_handler; + failure_handler exit_invariant_failure_handler = &default_handler; } failure_handler set_precondition_failure(failure_handler f) @@ -164,3 +167,5 @@ void set_invariant_failure(failure_handler f) BOOST_NOEXCEPT_OR_NOTHROW { } } // namespace +#endif // #include guard + diff --git a/include/boost/contract/set/nothing.hpp b/include/boost/contract/set/nothing.hpp index 9df1775..5ae00c2 100644 --- a/include/boost/contract/set/nothing.hpp +++ b/include/boost/contract/set/nothing.hpp @@ -18,25 +18,20 @@ namespace boost { namespace boost { namespace contract { namespace set { -class nothing { +class nothing { // Allow (shallow ptr) copy for `auto c = ...`. public: // Allow to set nothing (neither precondition, nor postcondition). private: - explicit nothing(boost::shared_ptr - const contract) : contract_(contract) {} - - /* implicit */ nothing(nothing const& other) : contract_(other.contract_) {} - nothing& operator=(nothing const&) /* = delete */; - nothing() /* = delete */; - - boost::shared_ptr contract_; - // Use friendship and deleted constructors to limit public API. - friend class boost::contract::type; friend class boost::contract::set::precondition_only; friend class boost::contract::set::postcondition_only; + + explicit nothing(boost::shared_ptr + const contract) : contract_(contract) {} + + boost::shared_ptr contract_; }; } } } // namespace diff --git a/include/boost/contract/set/postcondition_only.hpp b/include/boost/contract/set/postcondition_only.hpp index d5a0d31..04199ce 100644 --- a/include/boost/contract/set/postcondition_only.hpp +++ b/include/boost/contract/set/postcondition_only.hpp @@ -24,7 +24,7 @@ namespace boost { namespace boost { namespace contract { namespace set { -class postcondition_only { +class postcondition_only { // Allow (shallow ptr) copy for `auto c = ...`. public: template boost::contract::set::nothing postcondition(Postcondition const& f) { @@ -33,18 +33,7 @@ public: } private: - explicit postcondition_only(boost::shared_ptr const contract) : contract_(contract) {} - - /* implicit */ postcondition_only(postcondition_only const& other) : - contract_(other.contract_) {} - postcondition_only& operator=(postcondition_only const&) /* = delete */; - postcondition_only() /* = delete */; - - boost::shared_ptr contract_; - // Use friendship and deleted constructors to limit public API. - friend class boost::contract::type; friend class boost::contract::set::precondition_postcondition; @@ -53,6 +42,11 @@ private: template friend postcondition_only boost::contract::destructor(Class* const); + + explicit postcondition_only(boost::shared_ptr const contract) : contract_(contract) {} + + boost::shared_ptr contract_; }; } } } // namespace diff --git a/include/boost/contract/set/precondition_only.hpp b/include/boost/contract/set/precondition_only.hpp index 1006952..c800ae0 100644 --- a/include/boost/contract/set/precondition_only.hpp +++ b/include/boost/contract/set/precondition_only.hpp @@ -18,7 +18,7 @@ namespace boost { namespace boost { namespace contract { namespace set { -class precondition_only { +class precondition_only { // Allow (shallow ptr) copy for `auto c = ...`. public: template boost::contract::set::nothing precondition(Precondition const& f) { @@ -27,20 +27,14 @@ public: } private: + // Use friendship and deleted constructors to limit public API. + friend class boost::contract::type; + friend class boost::contract::set::precondition_postcondition; + explicit precondition_only(boost::shared_ptr const contract) : contract_(contract) {} - /* implicit */ precondition_only(precondition_only const& other) : - contract_(other.contract_) {} - precondition_only& operator=(precondition_only const&) /* = delete */; - precondition_only() /* = delete */; - boost::shared_ptr contract_; - - // Use friendship and deleted constructors to limit public API. - - friend class boost::contract::type; - friend class boost::contract::set::precondition_postcondition; }; } } } // namespace diff --git a/include/boost/contract/set/precondition_postcondition.hpp b/include/boost/contract/set/precondition_postcondition.hpp index e76aa38..d7cf905 100644 --- a/include/boost/contract/set/precondition_postcondition.hpp +++ b/include/boost/contract/set/precondition_postcondition.hpp @@ -43,7 +43,7 @@ namespace boost { namespace boost { namespace contract { namespace set { -class precondition_postcondition { +class precondition_postcondition { // Allow (shallow ptr) copy for auto c = ... public: template boost::contract::set::postcondition_only precondition( @@ -60,19 +60,7 @@ public: } private: - explicit precondition_postcondition(boost::shared_ptr const contract) : contract_(contract) {} - - /* implicit */ precondition_postcondition(precondition_postcondition const& - other) : contract_(other.contract_) {} - precondition_postcondition& operator=(precondition_postcondition const&) - /* = delete */; - precondition_postcondition() /* = delete */; - - boost::shared_ptr contract_; - // Use friendship and deleted constructors to limit public API. - friend class boost::contract::type; template const contract) : contract_(contract) {} + + boost::shared_ptr contract_; }; } } } // namespace diff --git a/include/boost/contract/type.hpp b/include/boost/contract/type.hpp index df02319..58d4e6f 100644 --- a/include/boost/contract/type.hpp +++ b/include/boost/contract/type.hpp @@ -11,7 +11,7 @@ namespace boost { namespace contract { -class type { // Must allow copy for `type c = ...` (shallow smart ptr copy). +class type { // Allow (shallow ptr) copy for `type c = ...`. public: /* implicit */ type(boost::contract::set::precondition_postcondition const& c) : contract_(c.contract_) {} diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 96611c4..1e357fa 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,26 +1,26 @@ -import testing ; +subdir-run function : constructor_bases ; +subdir-run function : destructor_bases ; +subdir-run function : public_member_bases_virtual ; +subdir-run function : public_member_bases_static ; +subdir-run function : protected_member_bases ; +subdir-run function : private_member_bases ; +subdir-run function : free_function ; -run base_types.cpp ; -run has_bases.cpp ; -run has_invariant.cpp ; -run introspect.cpp ; +subdir-run set : creation_set_post_nothing_comb ; +subdir-compile-fail set : creation_set_post_post_error ; +subdir-compile-fail set : creation_set_post_pre_error ; +subdir-compile-fail set : creation_set_pre_error ; +subdir-run set : function_set_pre_post_nothing_comb ; +subdir-compile-fail set : function_set_post_post_error ; +subdir-compile-fail set : function_set_post_pre_post_error ; +subdir-compile-fail set : function_set_post_pre_pre_error ; +subdir-compile-fail set : function_set_pre_post_post_error ; +subdir-compile-fail set : function_set_pre_post_pre_error ; +subdir-compile-fail set : function_set_pre_pre_error ; -run constructor_bases.cpp ; -run destructor_bases.cpp ; - -run public_member_bases_virtual.cpp ; -run public_member_bases_static.cpp ; - -run protected_member_bases.cpp ; -run private_member_bases.cpp ; - -run free_function/call.cpp ; -run free_function/set.cpp ; -compile-fail free_function/set_pre_pre_error.cpp ; -compile-fail free_function/set_pre_post_pre_error.cpp ; -compile-fail free_function/set_post_pre_pre_error.cpp ; -compile-fail free_function/set_post_post_error.cpp ; -compile-fail free_function/set_post_pre_post_error.cpp ; -compile-fail free_function/set_pre_post_post_error.cpp ; +subdir-run type_traits : introspect ; +subdir-run type_traits : base_types ; +subdir-run type_traits : has_bases ; +subdir-run type_traits : has_invariant ; diff --git a/test/constructor/Jamfile.v2 b/test/constructor/Jamfile.v2 deleted file mode 100644 index 4c0e50c..0000000 --- a/test/constructor/Jamfile.v2 +++ /dev/null @@ -1,9 +0,0 @@ - -import testing ; - -run with_bases.cpp ; -run set.cpp ; -compile-fail set_pre_error.cpp ; -compile-fail set_post_pre_error.cpp ; -compile-fail set_post_post_error.cpp ; - diff --git a/test/constructor/set_post_post_error.cpp b/test/constructor/set_post_post_error.cpp deleted file mode 100644 index e3cceb8..0000000 --- a/test/constructor/set_post_post_error.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include -#include - -// Test double post error. - -struct a { - explicit a() { - boost::contract::type c = boost::contract::constructor(this) - .postcondition([&] {}) - .postcondition([&] {}) - ; - } -}; - -int main() { - a aa; - return 0; -} - diff --git a/test/constructor/set_post_pre_error.cpp b/test/constructor/set_post_pre_error.cpp deleted file mode 100644 index 79c0e13..0000000 --- a/test/constructor/set_post_pre_error.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include -#include - -// Test pre after post error (must use constructor_precondition instead). - -struct a { - explicit a() { - boost::contract::type c = boost::contract::constructor(this) - .postcondition([&] {}) - .precondition([&] {}) - ; - } -}; - -int main() { - a aa; - return 0; -} - diff --git a/test/constructor/set_pre_error.cpp b/test/constructor/set_pre_error.cpp deleted file mode 100644 index a47eebf..0000000 --- a/test/constructor/set_pre_error.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include -#include - -// Test pre error (must use constructor_precondition instead). - -struct a { - explicit a() { - boost::contract::type c = boost::contract::constructor(this) - .precondition([&] {}) - ; - } -}; - -int main() { - a aa; - return 0; -} - diff --git a/test/free_function/Jamfile.v2 b/test/free_function/Jamfile.v2 deleted file mode 100644 index d455828..0000000 --- a/test/free_function/Jamfile.v2 +++ /dev/null @@ -1,12 +0,0 @@ - -import testing ; - -run call.cpp ; -run set.cpp ; -compile-fail set_pre_pre_error.cpp ; -compile-fail set_pre_post_pre_error.cpp ; -compile-fail set_post_pre_pre_error.cpp ; -compile-fail set_post_post_error.cpp ; -compile-fail set_post_pre_post_error.cpp ; -compile-fail set_pre_post_post_error.cpp ; - diff --git a/test/free_function/set_post_post_error.cpp b/test/free_function/set_post_post_error.cpp deleted file mode 100644 index cf21cdb..0000000 --- a/test/free_function/set_post_post_error.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -#include -#include - -int main() { - boost::contract::type c = boost::contract::free_function() - .postcondition([&] {}) - .postcondition([&] {}) - ; - return 0; -} - diff --git a/test/free_function/set_post_pre_post_error.cpp b/test/free_function/set_post_pre_post_error.cpp deleted file mode 100644 index bde2186..0000000 --- a/test/free_function/set_post_pre_post_error.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include -#include - -int main() { - boost::contract::type c = boost::contract::free_function() - .postcondition([&] {}) - .precondition([&] {}) - .postcondition([&] {}) - ; - return 0; -} - diff --git a/test/free_function/set_post_pre_pre_error.cpp b/test/free_function/set_post_pre_pre_error.cpp deleted file mode 100644 index 27d9d5f..0000000 --- a/test/free_function/set_post_pre_pre_error.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include -#include - -int main() { - boost::contract::type c = boost::contract::free_function() - .postcondition([&] {}) - .precondition([&] {}) - .precondition([&] {}) - ; - return 0; -} - diff --git a/test/free_function/set_pre_post_post_error.cpp b/test/free_function/set_pre_post_post_error.cpp deleted file mode 100644 index f137048..0000000 --- a/test/free_function/set_pre_post_post_error.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include -#include - -int main() { - boost::contract::type c = boost::contract::free_function() - .precondition([&] {}) - .postcondition([&] {}) - .postcondition([&] {}) - ; - return 0; -} - diff --git a/test/free_function/set_pre_post_pre_error.cpp b/test/free_function/set_pre_post_pre_error.cpp deleted file mode 100644 index fa59bfe..0000000 --- a/test/free_function/set_pre_post_pre_error.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include -#include - -int main() { - boost::contract::type c = boost::contract::free_function() - .precondition([&] {}) - .postcondition([&] {}) - .precondition([&] {}) - ; - return 0; -} - diff --git a/test/free_function/set_pre_pre_error.cpp b/test/free_function/set_pre_pre_error.cpp deleted file mode 100644 index f8db4c5..0000000 --- a/test/free_function/set_pre_pre_error.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -#include -#include - -int main() { - boost::contract::type c = boost::contract::free_function() - .precondition([&] {}) - .precondition([&] {}) - ; - return 0; -} - diff --git a/test/constructor/with_bases.cpp b/test/function/constructor_bases.cpp similarity index 100% rename from test/constructor/with_bases.cpp rename to test/function/constructor_bases.cpp diff --git a/test/destructor_bases.cpp b/test/function/destructor_bases.cpp similarity index 98% rename from test/destructor_bases.cpp rename to test/function/destructor_bases.cpp index eba81ce..0f22479 100644 --- a/test/destructor_bases.cpp +++ b/test/function/destructor_bases.cpp @@ -1,5 +1,5 @@ -#include "aux_/oteststream.hpp" +#include "../aux_/oteststream.hpp" #include #include #include diff --git a/test/free_function/call.cpp b/test/function/free_function.cpp similarity index 100% rename from test/free_function/call.cpp rename to test/function/free_function.cpp diff --git a/test/private_member_bases.cpp b/test/function/private_member_bases.cpp similarity index 98% rename from test/private_member_bases.cpp rename to test/function/private_member_bases.cpp index 2ef8e13..d46794c 100644 --- a/test/private_member_bases.cpp +++ b/test/function/private_member_bases.cpp @@ -1,5 +1,5 @@ -#include "aux_/oteststream.hpp" +#include "../aux_/oteststream.hpp" #include #include #include diff --git a/test/protected_member_bases.cpp b/test/function/protected_member_bases.cpp similarity index 98% rename from test/protected_member_bases.cpp rename to test/function/protected_member_bases.cpp index 8a59a96..59c326f 100644 --- a/test/protected_member_bases.cpp +++ b/test/function/protected_member_bases.cpp @@ -1,5 +1,5 @@ -#include "aux_/oteststream.hpp" +#include "../aux_/oteststream.hpp" #include #include #include diff --git a/test/public_member_bases_static.cpp b/test/function/public_member_bases_static.cpp similarity index 98% rename from test/public_member_bases_static.cpp rename to test/function/public_member_bases_static.cpp index d70e3aa..e1875bb 100644 --- a/test/public_member_bases_static.cpp +++ b/test/function/public_member_bases_static.cpp @@ -1,5 +1,5 @@ -#include "aux_/oteststream.hpp" +#include "../aux_/oteststream.hpp" #include #include #include diff --git a/test/public_member_bases_virtual.cpp b/test/function/public_member_bases_virtual.cpp similarity index 99% rename from test/public_member_bases_virtual.cpp rename to test/function/public_member_bases_virtual.cpp index f3e44b7..6c8f0e3 100644 --- a/test/public_member_bases_virtual.cpp +++ b/test/function/public_member_bases_virtual.cpp @@ -1,5 +1,5 @@ -#include "aux_/oteststream.hpp" +#include "../aux_/oteststream.hpp" #include #include #include diff --git a/test/constructor/set.cpp b/test/set/creation_set_post_nothing_comb.cpp similarity index 87% rename from test/constructor/set.cpp rename to test/set/creation_set_post_nothing_comb.cpp index ed5649d..b7067b2 100644 --- a/test/constructor/set.cpp +++ b/test/set/creation_set_post_nothing_comb.cpp @@ -1,11 +1,11 @@ #include "../aux_/oteststream.hpp" #include -#include #include #include -// Test all possible orders in which pre/post can be set. +// Test post or nothing combinations that can be set for constructors +// (destructors use same setter objects, so no need to test those too). boost::contract::aux::test::oteststream out; @@ -14,7 +14,7 @@ struct nothing { static void static_invariant() { out << "static_inv" << std::endl; } explicit nothing() { - boost::contract::type c = boost::contract::constructor(this); + auto c = boost::contract::constructor(this); out << "body" << std::endl; } }; @@ -28,7 +28,7 @@ struct pre_only : private boost::contract::constructor_precondition { out << "pre" << std::endl; }) { - boost::contract::type c = boost::contract::constructor(this); + auto c = boost::contract::constructor(this); out << "body" << std::endl; } }; @@ -38,7 +38,7 @@ struct post_only { static void static_invariant() { out << "static_inv" << std::endl; } explicit post_only() { - boost::contract::type c = boost::contract::constructor(this) + auto c = boost::contract::constructor(this) .postcondition([&] { out << "post" << std::endl; }) ; out << "body" << std::endl; @@ -54,7 +54,7 @@ struct pre_post : private boost::contract::constructor_precondition { out << "pre" << std::endl; }) { - boost::contract::type c = boost::contract::constructor(this) + auto c = boost::contract::constructor(this) .postcondition([&] { out << "post" << std::endl; }) ; out << "body" << std::endl; diff --git a/test/set/creation_set_post_post_error.cpp b/test/set/creation_set_post_post_error.cpp new file mode 100644 index 0000000..1010a94 --- /dev/null +++ b/test/set/creation_set_post_post_error.cpp @@ -0,0 +1,20 @@ + +#include + +// Test post cannot be set twice for constructors +// (destructors use same setter objects, so no need to test those too). + +struct a { + explicit a() { + auto c = boost::contract::constructor(this) + .postcondition([&] {}) + .postcondition([&] {}) // Error. + ; + } +}; + +int main() { + a aa; + return 0; +} + diff --git a/test/set/creation_set_post_pre_error.cpp b/test/set/creation_set_post_pre_error.cpp new file mode 100644 index 0000000..d8ef05d --- /dev/null +++ b/test/set/creation_set_post_pre_error.cpp @@ -0,0 +1,20 @@ + +#include + +// Test pre cannot be set (not even after post) for constructors +// (destructors use same setter objects, so no need to test those too). + +struct a { + explicit a() { + auto c = boost::contract::constructor(this) + .postcondition([&] {}) + .precondition([&] {}) // Error. + ; + } +}; + +int main() { + a aa; + return 0; +} + diff --git a/test/set/creation_set_pre_error.cpp b/test/set/creation_set_pre_error.cpp new file mode 100644 index 0000000..0aee147 --- /dev/null +++ b/test/set/creation_set_pre_error.cpp @@ -0,0 +1,19 @@ + +#include + +// Test pre cannot be set for constructors +// (destructors use same setter objects, so no need to test those too). + +struct a { + explicit a() { + auto c = boost::contract::constructor(this) + .precondition([&] {}) // Error. + ; + } +}; + +int main() { + a aa; + return 0; +} + diff --git a/test/set/function_set_post_post_error.cpp b/test/set/function_set_post_post_error.cpp new file mode 100644 index 0000000..64d5dbf --- /dev/null +++ b/test/set/function_set_post_post_error.cpp @@ -0,0 +1,14 @@ + +#include + +// Test post cannot be set twice for free functions +// (member functions use same setter objects, so no need to test those too). + +int main() { + auto c = boost::contract::free_function() + .postcondition([&] {}) + .postcondition([&] {}) // Error. + ; + return 0; +} + diff --git a/test/set/function_set_post_pre_post_error.cpp b/test/set/function_set_post_pre_post_error.cpp new file mode 100644 index 0000000..8354a43 --- /dev/null +++ b/test/set/function_set_post_pre_post_error.cpp @@ -0,0 +1,15 @@ + +#include + +// Test post cannot be set twice (not even after pre) for free functions +// (member functions use same setter objects, so no need to test those too). + +int main() { + auto c = boost::contract::free_function() + .postcondition([&] {}) + .precondition([&] {}) + .postcondition([&] {}) // Error. + ; + return 0; +} + diff --git a/test/set/function_set_post_pre_pre_error.cpp b/test/set/function_set_post_pre_pre_error.cpp new file mode 100644 index 0000000..412e585 --- /dev/null +++ b/test/set/function_set_post_pre_pre_error.cpp @@ -0,0 +1,15 @@ + +#include + +// Test pre cannot be set twice (not even after post) for free functions +// (member functions use same setter objects, so no need to test those too). + +int main() { + auto c = boost::contract::free_function() + .postcondition([&] {}) + .precondition([&] {}) + .precondition([&] {}) // Error. + ; + return 0; +} + diff --git a/test/free_function/set.cpp b/test/set/function_set_pre_post_nothing_comb.cpp similarity index 72% rename from test/free_function/set.cpp rename to test/set/function_set_pre_post_nothing_comb.cpp index dd724f6..b06213b 100644 --- a/test/free_function/set.cpp +++ b/test/set/function_set_pre_post_nothing_comb.cpp @@ -1,46 +1,43 @@ #include "../aux_/oteststream.hpp" #include -#include #include #include +// Test pre and post, or nothing combinations that can be set for free functions +// (member functions use same setter objects, so no need to test those too). + boost::contract::aux::test::oteststream out; -// Test free-function with neither pre nor post set. void nothing() { - boost::contract::type c = boost::contract::free_function(); + auto c = boost::contract::free_function(); out << "body" << std::endl; } -// Test free-function with only pre set. void pre_only() { - boost::contract::type c = boost::contract::free_function() + auto c = boost::contract::free_function() .precondition([&] { out << "pre" << std::endl; }) ; out << "body" << std::endl; } -// Test free-function with only post set. void post_only() { - boost::contract::type c = boost::contract::free_function() + auto c = boost::contract::free_function() .postcondition([&] { out << "post" << std::endl; }) ; out << "body" << std::endl; } -// Test free-function with pre set before post. void pre_post() { - boost::contract::type c = boost::contract::free_function() + auto c = boost::contract::free_function() .precondition([&] { out << "pre" << std::endl; }) .postcondition([&] { out << "post" << std::endl; }) ; out << "body" << std::endl; } -// Test free-function with post set before pre. void post_pre() { - boost::contract::type c = boost::contract::free_function() + auto c = boost::contract::free_function() .postcondition([&] { out << "post" << std::endl; }) .precondition([&] { out << "pre" << std::endl; }) ; diff --git a/test/set/function_set_pre_post_post_error.cpp b/test/set/function_set_pre_post_post_error.cpp new file mode 100644 index 0000000..637f722 --- /dev/null +++ b/test/set/function_set_pre_post_post_error.cpp @@ -0,0 +1,15 @@ + +#include + +// Test post cannot be set twice (not even after pre) for free functions +// (member functions use same setter object, so no need to test those too). + +int main() { + auto c = boost::contract::free_function() + .precondition([&] {}) + .postcondition([&] {}) + .postcondition([&] {}) // Error. + ; + return 0; +} + diff --git a/test/set/function_set_pre_post_pre_error.cpp b/test/set/function_set_pre_post_pre_error.cpp new file mode 100644 index 0000000..c5b4f9c --- /dev/null +++ b/test/set/function_set_pre_post_pre_error.cpp @@ -0,0 +1,15 @@ + +#include + +// Test pre cannot be set twice (not even after post) for free functions +// (member functions use same setter objects, so no need to test those too). + +int main() { + auto c = boost::contract::free_function() + .precondition([&] {}) + .postcondition([&] {}) + .precondition([&] {}) // Error. + ; + return 0; +} + diff --git a/test/set/function_set_pre_pre_error.cpp b/test/set/function_set_pre_pre_error.cpp new file mode 100644 index 0000000..81757cb --- /dev/null +++ b/test/set/function_set_pre_pre_error.cpp @@ -0,0 +1,14 @@ + +#include + +// Test pre cannot be set twice for free functions +// (member functions use same setter objects, so no need to test those too). + +int main() { + auto c = boost::contract::free_function() + .precondition([&] {}) + .precondition([&] {}) // Error. + ; + return 0; +} + diff --git a/test/base_types.cpp b/test/type_traits/base_types.cpp similarity index 100% rename from test/base_types.cpp rename to test/type_traits/base_types.cpp diff --git a/test/has_bases.cpp b/test/type_traits/has_bases.cpp similarity index 100% rename from test/has_bases.cpp rename to test/type_traits/has_bases.cpp diff --git a/test/has_invariant.cpp b/test/type_traits/has_invariant.cpp similarity index 100% rename from test/has_invariant.cpp rename to test/type_traits/has_invariant.cpp diff --git a/test/introspect.cpp b/test/type_traits/introspect.cpp similarity index 100% rename from test/introspect.cpp rename to test/type_traits/introspect.cpp