mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-30 19:57:10 +01:00 
			
		
		
		
	| @@ -74,6 +74,7 @@ function(add_warnings_to_targets targets) | |||||||
|           "-Woverloaded-virtual" |           "-Woverloaded-virtual" | ||||||
|           "-Wparentheses" |           "-Wparentheses" | ||||||
|           "-Wpedantic" |           "-Wpedantic" | ||||||
|  |           "-Wredundant-decls" | ||||||
|           "-Wreorder" |           "-Wreorder" | ||||||
|           "-Wreturn-std-move" |           "-Wreturn-std-move" | ||||||
|           "-Wshadow" |           "-Wshadow" | ||||||
|   | |||||||
| @@ -13,9 +13,9 @@ | |||||||
| #include <catch2/internal/catch_run_context.hpp> | #include <catch2/internal/catch_run_context.hpp> | ||||||
| #include <catch2/catch_test_spec.hpp> | #include <catch2/catch_test_spec.hpp> | ||||||
| #include <catch2/catch_version.hpp> | #include <catch2/catch_version.hpp> | ||||||
| #include <catch2/interfaces/catch_interfaces_testcase.hpp> |  | ||||||
| #include <catch2/internal/catch_startup_exception_registry.hpp> | #include <catch2/internal/catch_startup_exception_registry.hpp> | ||||||
| #include <catch2/internal/catch_sharding.hpp> | #include <catch2/internal/catch_sharding.hpp> | ||||||
|  | #include <catch2/internal/catch_test_case_registry_impl.hpp> | ||||||
| #include <catch2/internal/catch_textflow.hpp> | #include <catch2/internal/catch_textflow.hpp> | ||||||
| #include <catch2/internal/catch_windows_h_proxy.hpp> | #include <catch2/internal/catch_windows_h_proxy.hpp> | ||||||
| #include <catch2/reporters/catch_reporter_multi.hpp> | #include <catch2/reporters/catch_reporter_multi.hpp> | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ | |||||||
| // SPDX-License-Identifier: BSL-1.0 | // SPDX-License-Identifier: BSL-1.0 | ||||||
| #include <catch2/catch_test_spec.hpp> | #include <catch2/catch_test_spec.hpp> | ||||||
| #include <catch2/interfaces/catch_interfaces_testcase.hpp> | #include <catch2/interfaces/catch_interfaces_testcase.hpp> | ||||||
|  | #include <catch2/internal/catch_test_case_registry_impl.hpp> | ||||||
| #include <catch2/internal/catch_reusable_string_stream.hpp> | #include <catch2/internal/catch_reusable_string_stream.hpp> | ||||||
| #include <catch2/internal/catch_string_manip.hpp> | #include <catch2/internal/catch_string_manip.hpp> | ||||||
| #include <catch2/catch_test_case_info.hpp> | #include <catch2/catch_test_case_info.hpp> | ||||||
|   | |||||||
| @@ -12,7 +12,6 @@ | |||||||
|  |  | ||||||
| namespace Catch { | namespace Catch { | ||||||
|  |  | ||||||
|     class TestSpec; |  | ||||||
|     struct TestCaseInfo; |     struct TestCaseInfo; | ||||||
|     class TestCaseHandle; |     class TestCaseHandle; | ||||||
|     class IConfig; |     class IConfig; | ||||||
| @@ -26,11 +25,6 @@ namespace Catch { | |||||||
|         virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0; |         virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config ); |  | ||||||
|     bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config ); |  | ||||||
|     std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ); |  | ||||||
|     std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config ); |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif // CATCH_INTERFACES_TESTCASE_HPP_INCLUDED | #endif // CATCH_INTERFACES_TESTCASE_HPP_INCLUDED | ||||||
|   | |||||||
| @@ -9,8 +9,8 @@ | |||||||
|  |  | ||||||
| #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> | #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> | ||||||
| #include <catch2/interfaces/catch_interfaces_reporter.hpp> | #include <catch2/interfaces/catch_interfaces_reporter.hpp> | ||||||
| #include <catch2/interfaces/catch_interfaces_testcase.hpp> |  | ||||||
| #include <catch2/interfaces/catch_interfaces_reporter_factory.hpp> | #include <catch2/interfaces/catch_interfaces_reporter_factory.hpp> | ||||||
|  | #include <catch2/internal/catch_test_case_registry_impl.hpp> | ||||||
| #include <catch2/internal/catch_reporter_registry.hpp> | #include <catch2/internal/catch_reporter_registry.hpp> | ||||||
| #include <catch2/internal/catch_move_and_forward.hpp> | #include <catch2/internal/catch_move_and_forward.hpp> | ||||||
| #include <catch2/internal/catch_case_insensitive_comparisons.hpp> | #include <catch2/internal/catch_case_insensitive_comparisons.hpp> | ||||||
|   | |||||||
| @@ -24,6 +24,38 @@ | |||||||
|  |  | ||||||
| namespace Catch { | namespace Catch { | ||||||
|  |  | ||||||
|  |     namespace { | ||||||
|  |         static void enforceNoDuplicateTestCases( | ||||||
|  |             std::vector<TestCaseHandle> const& tests ) { | ||||||
|  |             auto testInfoCmp = []( TestCaseInfo const* lhs, | ||||||
|  |                                    TestCaseInfo const* rhs ) { | ||||||
|  |                 return *lhs < *rhs; | ||||||
|  |             }; | ||||||
|  |             std::set<TestCaseInfo const*, decltype( testInfoCmp )&> seenTests( | ||||||
|  |                 testInfoCmp ); | ||||||
|  |             for ( auto const& test : tests ) { | ||||||
|  |                 const auto infoPtr = &test.getTestCaseInfo(); | ||||||
|  |                 const auto prev = seenTests.insert( infoPtr ); | ||||||
|  |                 CATCH_ENFORCE( prev.second, | ||||||
|  |                                "error: test case \"" | ||||||
|  |                                    << infoPtr->name << "\", with tags \"" | ||||||
|  |                                    << infoPtr->tagsAsString() | ||||||
|  |                                    << "\" already defined.\n" | ||||||
|  |                                    << "\tFirst seen at " | ||||||
|  |                                    << ( *prev.first )->lineInfo << "\n" | ||||||
|  |                                    << "\tRedefined at " << infoPtr->lineInfo ); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         static bool matchTest( TestCaseHandle const& testCase, | ||||||
|  |                                TestSpec const& testSpec, | ||||||
|  |                                IConfig const& config ) { | ||||||
|  |             return testSpec.matches( testCase.getTestCaseInfo() ) && | ||||||
|  |                    isThrowSafe( testCase, config ); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } // end unnamed namespace | ||||||
|  |  | ||||||
|     std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases ) { |     std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases ) { | ||||||
|         switch (config.runOrder()) { |         switch (config.runOrder()) { | ||||||
|         case TestRunOrder::Declared: |         case TestRunOrder::Declared: | ||||||
| @@ -80,29 +112,6 @@ namespace Catch { | |||||||
|         return !testCase.getTestCaseInfo().throws() || config.allowThrows(); |         return !testCase.getTestCaseInfo().throws() || config.allowThrows(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config ) { |  | ||||||
|         return testSpec.matches( testCase.getTestCaseInfo() ) && isThrowSafe( testCase, config ); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     void |  | ||||||
|     enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& tests ) { |  | ||||||
|         auto testInfoCmp = []( TestCaseInfo const* lhs, |  | ||||||
|                                TestCaseInfo const* rhs ) { |  | ||||||
|             return *lhs < *rhs; |  | ||||||
|         }; |  | ||||||
|         std::set<TestCaseInfo const*, decltype(testInfoCmp) &> seenTests(testInfoCmp); |  | ||||||
|         for ( auto const& test : tests ) { |  | ||||||
|             const auto infoPtr = &test.getTestCaseInfo(); |  | ||||||
|             const auto prev = seenTests.insert( infoPtr ); |  | ||||||
|             CATCH_ENFORCE( |  | ||||||
|                 prev.second, |  | ||||||
|                 "error: test case \"" << infoPtr->name << "\", with tags \"" |  | ||||||
|                     << infoPtr->tagsAsString() << "\" already defined.\n" |  | ||||||
|                     << "\tFirst seen at " << ( *prev.first )->lineInfo << "\n" |  | ||||||
|                     << "\tRedefined at " << infoPtr->lineInfo ); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ) { |     std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ) { | ||||||
|         std::vector<TestCaseHandle> filtered; |         std::vector<TestCaseHandle> filtered; | ||||||
|         filtered.reserve( testCases.size() ); |         filtered.reserve( testCases.size() ); | ||||||
|   | |||||||
| @@ -24,9 +24,6 @@ namespace Catch { | |||||||
|     std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases ); |     std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases ); | ||||||
|  |  | ||||||
|     bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config ); |     bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config ); | ||||||
|     bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config ); |  | ||||||
|  |  | ||||||
|     void enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& functions ); |  | ||||||
|  |  | ||||||
|     std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ); |     std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config ); | ||||||
|     std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config ); |     std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský