diff options
| author | Daniel Feist | 2022-03-31 16:46:41 +0200 |
|---|---|---|
| committer | GitHub | 2022-03-31 16:46:41 +0200 |
| commit | 78e33ce51f78f0837b36a0e8b6b92c4b2a860178 (patch) | |
| tree | 35f4c8fc248ae1e99e411a1c58ca080c3495dcb5 /tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp | |
| parent | 1a8a793178d50b74b0f9a0adb3eec937b61039a9 (diff) | |
| download | catch3-78e33ce51f78f0837b36a0e8b6b92c4b2a860178.tar.gz | |
Added TestCaseInfoHasher and tests. (#2394)
Test case hashing includes tags and class name
As the hasher involves more code now, it was split out into its own file
and it got its own set of tests.
Closes #2304
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp b/tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp new file mode 100644 index 00000000..45007360 --- /dev/null +++ b/tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp @@ -0,0 +1,51 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/catch_test_case_info.hpp> +#include <catch2/internal/catch_test_case_info_hasher.hpp> + +static constexpr Catch::SourceLineInfo dummySourceLineInfo = CATCH_INTERNAL_LINEINFO; + +TEST_CASE( "TestCaseInfoHasher produces equal hashes." ) { + SECTION( "class names and names and tags are equal." ) { + Catch::TestCaseInfo testCase1("", {"name", "[.magic-tag1]"}, dummySourceLineInfo); + Catch::TestCaseInfo testCase2("", {"name", "[.magic-tag1]"}, dummySourceLineInfo); + + Catch::TestCaseInfoHasher hasherWithCustomSeed(123456789u); + CHECK(hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2)); + } +} + +TEST_CASE( "TestCaseInfoHasher produces different hashes." ) { + SECTION( "class names are equal, names are equal but tags are different." ) { + Catch::TestCaseInfo testCase1("", {"name", "[.magic-tag1]"}, dummySourceLineInfo); + Catch::TestCaseInfo testCase2("", {"name", "[.magic-tag2]"}, dummySourceLineInfo); + + Catch::TestCaseInfoHasher hasherWithCustomSeed(123456789u); + CHECK(hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2)); + } + + SECTION( "class names are equal, tags are equal but names are different" ) { + Catch::TestCaseInfo testCase1("", {"name1", "[.magic-tag]"}, dummySourceLineInfo); + Catch::TestCaseInfo testCase2("", {"name2", "[.magic-tag]"}, dummySourceLineInfo); + + Catch::TestCaseInfoHasher hasherWithCustomSeed(123456789u); + CHECK(hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2)); + } + + SECTION( "names are equal, tags are equal but class names are different" ) { + Catch::TestCaseInfo testCase1("class1", {"name", "[.magic-tag]"}, dummySourceLineInfo); + Catch::TestCaseInfo testCase2("class2", {"name", "[.magic-tag]"}, dummySourceLineInfo); + + Catch::TestCaseInfoHasher hasherWithCustomSeed(123456789u); + CHECK(hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2)); + } + + SECTION( "class names and names and tags are equal but hashers are seeded differently." ) { + Catch::TestCaseInfo testCase1("", {"name", "[.magic-tag1]"}, dummySourceLineInfo); + Catch::TestCaseInfo testCase2("", {"name", "[.magic-tag1]"}, dummySourceLineInfo); + + Catch::TestCaseInfoHasher h1(14695981039346656037u); + Catch::TestCaseInfoHasher h2(14695981039346656038u); + + CHECK(h1(testCase1) != h2(testCase2)); + } +} |