Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Split the NonCopyable helper out of catch_common.hpp

Commit
e7eb74981513364e6543aeec30446fda4c9a3de9
Author
Martin Hořeňovský ·
Parents
c1bb699d45fd

Files · Download .tar.gz

Changes

 src/CMakeLists.txt                                  |  1 +
 src/catch2/catch_all.hpp                            |  1 +
 src/catch2/catch_registry_hub.cpp                   |  6 ++++--
 src/catch2/catch_session.hpp                        |  4 +++-
 src/catch2/catch_test_case_info.hpp                 |  3 ++-
 src/catch2/interfaces/catch_interfaces_config.hpp   |  4 ++--
 .../interfaces/catch_interfaces_registry_hub.hpp    |  2 +-
 src/catch2/internal/catch_clara.hpp                 | 12 +++---------
 src/catch2/internal/catch_common.hpp                |  9 ---------
 src/catch2/internal/catch_context.cpp               |  4 ++--
 src/catch2/internal/catch_noncopyable.hpp           | 21 +++++++++++++++++++++
 src/catch2/internal/catch_section.hpp               |  3 ++-
 src/catch2/internal/catch_stream.hpp                |  4 ++--
 src/catch2/internal/catch_test_registry.hpp         |  3 ++-
 src/catch2/internal/catch_xmlwriter.hpp             |  7 +++++++
 15 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index de7010be..932ff876 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,6 +38,7 @@ set(INTERNAL_HEADERS
     ${SOURCES_DIR}/matchers/internal/catch_matchers_impl.hpp
     ${SOURCES_DIR}/internal/catch_console_width.hpp
     ${SOURCES_DIR}/internal/catch_container_nonmembers.hpp
+    ${SOURCES_DIR}/internal/catch_noncopyable.hpp
     ${SOURCES_DIR}/catch_approx.hpp
     ${SOURCES_DIR}/internal/catch_assertion_handler.hpp
     ${SOURCES_DIR}/catch_assertion_info.hpp
diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp
index a6448229..a5bdd50b 100644
--- a/src/catch2/catch_all.hpp
+++ b/src/catch2/catch_all.hpp
@@ -60,6 +60,7 @@
 #include <catch2/internal/catch_list.hpp>
 #include <catch2/internal/catch_message_info.hpp>
 #include <catch2/internal/catch_meta.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 #include <catch2/internal/catch_option.hpp>
 #include <catch2/internal/catch_output_redirect.hpp>
 #include <catch2/internal/catch_platform.hpp>
diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp
index af4db897..c25b1cec 100644
--- a/src/catch2/catch_registry_hub.cpp
+++ b/src/catch2/catch_registry_hub.cpp
@@ -18,13 +18,15 @@
 #include <catch2/internal/catch_singletons.hpp>
 #include <catch2/internal/catch_enum_values_registry.hpp>
 #include <catch2/catch_test_case_info.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 
 namespace Catch {
 
     namespace {
 
-        class RegistryHub : public IRegistryHub, public IMutableRegistryHub,
-                            private NonCopyable {
+        class RegistryHub : public IRegistryHub,
+                            public IMutableRegistryHub,
+                            private Detail::NonCopyable {
 
         public: // IRegistryHub
             RegistryHub() = default;
diff --git a/src/catch2/catch_session.hpp b/src/catch2/catch_session.hpp
index 6c560c63..3c7f3c22 100644
--- a/src/catch2/catch_session.hpp
+++ b/src/catch2/catch_session.hpp
@@ -9,12 +9,14 @@
 #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
 
 #include <catch2/internal/catch_commandline.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 #include <catch2/catch_config.hpp>
 #include <catch2/internal/catch_unique_ptr.hpp>
+#include <catch2/internal/catch_compiler_capabilities.hpp>
 
 namespace Catch {
 
-    class Session : NonCopyable {
+    class Session : Detail::NonCopyable {
     public:
 
         Session();
diff --git a/src/catch2/catch_test_case_info.hpp b/src/catch2/catch_test_case_info.hpp
index 991cca61..1d2c1b12 100644
--- a/src/catch2/catch_test_case_info.hpp
+++ b/src/catch2/catch_test_case_info.hpp
@@ -9,6 +9,7 @@
 #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
 
 #include <catch2/internal/catch_common.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 #include <catch2/internal/catch_stringref.hpp>
 #include <catch2/internal/catch_test_registry.hpp>
 #include <catch2/internal/catch_unique_ptr.hpp>
@@ -44,7 +45,7 @@ namespace Catch {
     };
 
 
-    struct TestCaseInfo : NonCopyable {
+    struct TestCaseInfo : Detail::NonCopyable {
 
         TestCaseInfo(std::string const& _className,
                      NameAndTags const& _tags,
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index a2cb88a8..f0f19167 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -8,7 +8,7 @@
 #ifndef TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
 #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
 
-#include <catch2/internal/catch_common.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 
 #include <chrono>
 #include <iosfwd>
@@ -53,7 +53,7 @@ namespace Catch {
 
     class TestSpec;
 
-    struct IConfig : NonCopyable {
+    struct IConfig : Detail::NonCopyable {
 
         virtual ~IConfig();
 
diff --git a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
index 3e99d215..14fa06a5 100644
--- a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
+++ b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp
@@ -8,7 +8,6 @@
 #ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
 #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
 
-#include <catch2/internal/catch_common.hpp>
 #include <catch2/internal/catch_unique_ptr.hpp>
 
 #include <string>
@@ -25,6 +24,7 @@ namespace Catch {
     struct ITagAliasRegistry;
     struct ITestInvoker;
     struct IMutableEnumValuesRegistry;
+    struct SourceLineInfo;
 
     class StartupExceptionRegistry;
 
diff --git a/src/catch2/internal/catch_clara.hpp b/src/catch2/internal/catch_clara.hpp
index f85c8e14..d4aca873 100644
--- a/src/catch2/internal/catch_clara.hpp
+++ b/src/catch2/internal/catch_clara.hpp
@@ -30,6 +30,8 @@
 #    endif
 #endif
 
+#include <catch2/internal/catch_noncopyable.hpp>
+
 #include <cassert>
 #include <cctype>
 #include <memory>
@@ -286,15 +288,7 @@ namespace Catch {
             }
 #endif // CLARA_CONFIG_OPTIONAL_TYPE
 
-            struct NonCopyable {
-                NonCopyable() = default;
-                NonCopyable( NonCopyable const& ) = delete;
-                NonCopyable( NonCopyable&& ) = delete;
-                NonCopyable& operator=( NonCopyable const& ) = delete;
-                NonCopyable& operator=( NonCopyable&& ) = delete;
-            };
-
-            struct BoundRef : NonCopyable {
+            struct BoundRef : Catch::Detail::NonCopyable {
                 virtual ~BoundRef() = default;
                 virtual auto isContainer() const -> bool { return false; }
                 virtual auto isFlag() const -> bool { return false; }
diff --git a/src/catch2/internal/catch_common.hpp b/src/catch2/internal/catch_common.hpp
index 45a1eca5..1229b9e2 100644
--- a/src/catch2/internal/catch_common.hpp
+++ b/src/catch2/internal/catch_common.hpp
@@ -32,15 +32,6 @@ namespace Catch {
         No
     }; };
 
-    class NonCopyable {
-        NonCopyable( NonCopyable const& )              = delete;
-        NonCopyable( NonCopyable && )                  = delete;
-        NonCopyable& operator = ( NonCopyable const& ) = delete;
-        NonCopyable& operator = ( NonCopyable && )     = delete;
-    protected:
-        NonCopyable() noexcept = default;
-    };
-
     struct SourceLineInfo {
 
         SourceLineInfo() = delete;
diff --git a/src/catch2/internal/catch_context.cpp b/src/catch2/internal/catch_context.cpp
index ed7b0150..821380da 100644
--- a/src/catch2/internal/catch_context.cpp
+++ b/src/catch2/internal/catch_context.cpp
@@ -6,12 +6,12 @@
  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  */
 #include <catch2/internal/catch_context.hpp>
-#include <catch2/internal/catch_common.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 #include <catch2/internal/catch_random_number_generator.hpp>
 
 namespace Catch {
 
-    class Context : public IMutableContext, NonCopyable {
+    class Context : public IMutableContext, private Detail::NonCopyable {
 
     public: // IContext
         IResultCapture* getResultCapture() override {
diff --git a/src/catch2/internal/catch_noncopyable.hpp b/src/catch2/internal/catch_noncopyable.hpp
new file mode 100644
index 00000000..217bac4d
--- /dev/null
+++ b/src/catch2/internal/catch_noncopyable.hpp
@@ -0,0 +1,21 @@
+#ifndef CATCH_NONCOPYABLE_HPP_INCLUDED
+#define CATCH_NONCOPYABLE_HPP_INCLUDED
+
+namespace Catch {
+    namespace Detail {
+
+        //! Deriving classes become noncopyable and nonmovable
+        class NonCopyable {
+            NonCopyable( NonCopyable const& ) = delete;
+            NonCopyable( NonCopyable&& ) = delete;
+            NonCopyable& operator=( NonCopyable const& ) = delete;
+            NonCopyable& operator=( NonCopyable&& ) = delete;
+
+        protected:
+            NonCopyable() noexcept = default;
+        };
+
+    } // namespace Detail
+} // namespace Catch
+
+#endif // CATCH_NONCOPYABLE_HPP_INCLUDED
diff --git a/src/catch2/internal/catch_section.hpp b/src/catch2/internal/catch_section.hpp
index bdaf54af..fa0a64ae 100644
--- a/src/catch2/internal/catch_section.hpp
+++ b/src/catch2/internal/catch_section.hpp
@@ -9,6 +9,7 @@
 #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
 
 #include <catch2/internal/catch_compiler_capabilities.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 #include <catch2/catch_section_info.hpp>
 #include <catch2/catch_timer.hpp>
 #include <catch2/catch_totals.hpp>
@@ -17,7 +18,7 @@
 
 namespace Catch {
 
-    class Section : NonCopyable {
+    class Section : Detail::NonCopyable {
     public:
         Section( SectionInfo&& info );
         ~Section();
diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp
index 51d32e62..98788fea 100644
--- a/src/catch2/internal/catch_stream.hpp
+++ b/src/catch2/internal/catch_stream.hpp
@@ -9,7 +9,7 @@
 #ifndef TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
 #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
 
-#include <catch2/internal/catch_common.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 
 #include <iosfwd>
 #include <cstddef>
@@ -30,7 +30,7 @@ namespace Catch {
 
     auto makeStream( StringRef const &filename ) -> IStream const*;
 
-    class ReusableStringStream : NonCopyable {
+    class ReusableStringStream : Detail::NonCopyable {
         std::size_t m_index;
         std::ostream* m_oss;
     public:
diff --git a/src/catch2/internal/catch_test_registry.hpp b/src/catch2/internal/catch_test_registry.hpp
index fd6d7d21..f9dc6255 100644
--- a/src/catch2/internal/catch_test_registry.hpp
+++ b/src/catch2/internal/catch_test_registry.hpp
@@ -9,6 +9,7 @@
 #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
 
 #include <catch2/internal/catch_common.hpp>
+#include <catch2/internal/catch_noncopyable.hpp>
 #include <catch2/interfaces/catch_interfaces_testcase.hpp>
 #include <catch2/internal/catch_compiler_capabilities.hpp>
 #include <catch2/internal/catch_stringref.hpp>
@@ -52,7 +53,7 @@ struct NameAndTags {
     StringRef tags;
 };
 
-struct AutoReg : NonCopyable {
+struct AutoReg : Detail::NonCopyable {
     AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
 };
 
diff --git a/src/catch2/internal/catch_xmlwriter.hpp b/src/catch2/internal/catch_xmlwriter.hpp
index 3102dc6a..56de2e43 100644
--- a/src/catch2/internal/catch_xmlwriter.hpp
+++ b/src/catch2/internal/catch_xmlwriter.hpp
@@ -11,6 +11,13 @@
 #include <catch2/internal/catch_stream.hpp>
 #include <catch2/internal/catch_compiler_capabilities.hpp>
 
+// FixMe: Without this include (and something inside it), MSVC goes crazy
+//        and reports that calls to XmlEncode's op << are ambiguous between
+//        the declaration and definition.
+//        It also has to be in the header.
+#include <catch2/internal/catch_common.hpp>
+
+
 #include <vector>
 
 namespace Catch {