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
This commit is contained in:
Daniel Feist
2022-03-31 16:46:41 +02:00
committed by GitHub
parent 1a8a793178
commit 78e33ce51f
24 changed files with 493 additions and 42 deletions

View File

@@ -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));
}
}