diff options
| author | Martin Hořeňovský | 2026-04-08 10:26:57 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-04-08 12:57:09 +0200 |
| commit | 47200ddbee03eaf4a9d3d99d18cb692381d8f5bc (patch) | |
| tree | ec947545e5f35b38ea5592c6fafcd7861081648c /tests/SelfTest/IntrospectiveTests/ToString.tests.cpp | |
| parent | e51dcdcc595371828de2b1d28985e8d8c1895345 (diff) | |
| download | catch3-47200ddbee03eaf4a9d3d99d18cb692381d8f5bc.tar.gz | |
Rework internals of CATCH_REGISTER_ENUM
The old internals reached into the global hub to stash the allocation(s)
for enum value -> string value there, then kept around a potentially
invalid (in case the hub was cleaned up) reference into it, going through
whole bunch of virtual dispatch in the process.
The new internals just store the data in a static variable inside the
`StringMaker` specialization. This avoids potential lifetime issues,
avoids all virtual dispatch and (almost) reduces the include bloat in
the main header path.
The reason for (almost) there is that for full include correctness,
`EnumInfo` needs `<utility>` include for `std::pair`. However, this brings
in things like `std::relops`, because the std headers in C++ are dumb.
As this was not included before, and instead we relied on `std::pair`
existing in an internal stdlib header that we transitively included, the
full include size ends up bigger than before.
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/ToString.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/ToString.tests.cpp | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp index 01d989a7..780c951c 100644 --- a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp @@ -10,14 +10,10 @@ #include <catch2/catch_template_test_macros.hpp> #include <catch2/catch_test_macros.hpp> #include <catch2/generators/catch_generators.hpp> -#include <catch2/internal/catch_enum_values_registry.hpp> #include <catch2/matchers/catch_matchers_string.hpp> -#include <catch2/matchers/catch_matchers_vector.hpp> #include <chrono> -enum class EnumClass3 { Value1, Value2, Value3, Value4 }; - struct UsesSentinel { using const_iterator = int const*; using const_sentinel = std::nullptr_t; @@ -26,42 +22,6 @@ struct UsesSentinel { const_iterator end() const { return nullptr; } }; -TEST_CASE( "parseEnums", "[Strings][enums]" ) { - using namespace Catch::Matchers; - using Catch::Detail::parseEnums; - - SECTION( "No enums" ) - CHECK_THAT( parseEnums( "" ), Equals( std::vector<Catch::StringRef>{} ) ); - - SECTION( "One enum value" ) { - CHECK_THAT( parseEnums( "ClassName::EnumName::Value1" ), - Equals(std::vector<Catch::StringRef>{"Value1"} ) ); - CHECK_THAT( parseEnums( "Value1" ), - Equals( std::vector<Catch::StringRef>{"Value1"} ) ); - CHECK_THAT( parseEnums( "EnumName::Value1" ), - Equals(std::vector<Catch::StringRef>{"Value1"} ) ); - } - - SECTION( "Multiple enum values" ) { - CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2" ), - Equals( std::vector<Catch::StringRef>{"Value1", "Value2"} ) ); - CHECK_THAT( parseEnums( "ClassName::EnumName::Value1, ClassName::EnumName::Value2, ClassName::EnumName::Value3" ), - Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) ); - CHECK_THAT( parseEnums( "ClassName::EnumName::Value1,ClassName::EnumName::Value2 , ClassName::EnumName::Value3" ), - Equals( std::vector<Catch::StringRef>{"Value1", "Value2", "Value3"} ) ); - } -} - -TEST_CASE( "Directly creating an EnumInfo" ) { - - using namespace Catch::Detail; - auto enumInfo = makeEnumInfo( "EnumName", "EnumName::Value1, EnumName::Value2", {0, 1} ); - - CHECK( enumInfo->lookup(0) == "Value1" ); - CHECK( enumInfo->lookup(1) == "Value2" ); - CHECK( enumInfo->lookup(3) == "{** unexpected enum value **}" ); -} - TEST_CASE("Range type with sentinel") { CHECK( Catch::Detail::stringify(UsesSentinel{}) == "{ }" ); } |