From 78e33ce51f78f0837b36a0e8b6b92c4b2a860178 Mon Sep 17 00:00:00 2001 From: Daniel Feist Date: Thu, 31 Mar 2022 16:46:41 +0200 Subject: [PATCH] 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 --- src/CMakeLists.txt | 2 + src/catch2/catch_all.hpp | 1 + .../internal/catch_test_case_info_hasher.cpp | 31 ++++++++ .../internal/catch_test_case_info_hasher.hpp | 22 ++++++ .../catch_test_case_registry_impl.cpp | 31 +------- tests/CMakeLists.txt | 1 + .../Baselines/automake.sw.approved.txt | 2 + .../Baselines/automake.sw.multi.approved.txt | 2 + .../Baselines/compact.sw.approved.txt | 15 ++++ .../Baselines/compact.sw.multi.approved.txt | 15 ++++ .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 74 +++++++++++++++++- .../Baselines/console.sw.multi.approved.txt | 74 +++++++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 7 +- .../Baselines/junit.sw.multi.approved.txt | 7 +- .../Baselines/sonarqube.sw.approved.txt | 7 ++ .../Baselines/sonarqube.sw.multi.approved.txt | 7 ++ tests/SelfTest/Baselines/tap.sw.approved.txt | 12 ++- .../Baselines/tap.sw.multi.approved.txt | 12 ++- .../Baselines/teamcity.sw.approved.txt | 4 + .../Baselines/teamcity.sw.multi.approved.txt | 4 + tests/SelfTest/Baselines/xml.sw.approved.txt | 75 ++++++++++++++++++- .../Baselines/xml.sw.multi.approved.txt | 75 ++++++++++++++++++- .../TestCaseInfoHasher.tests.cpp | 51 +++++++++++++ 24 files changed, 493 insertions(+), 42 deletions(-) create mode 100644 src/catch2/internal/catch_test_case_info_hasher.cpp create mode 100644 src/catch2/internal/catch_test_case_info_hasher.hpp create mode 100644 tests/SelfTest/IntrospectiveTests/TestCaseInfoHasher.tests.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 78d95956..16efa3fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -157,6 +157,7 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_wildcard_pattern.hpp ${SOURCES_DIR}/internal/catch_windows_h_proxy.hpp ${SOURCES_DIR}/internal/catch_xmlwriter.hpp + ${SOURCES_DIR}/internal/catch_test_case_info_hasher.hpp ) set(IMPL_SOURCES ${SOURCES_DIR}/catch_approx.cpp @@ -213,6 +214,7 @@ set(IMPL_SOURCES ${SOURCES_DIR}/catch_version.cpp ${SOURCES_DIR}/internal/catch_wildcard_pattern.cpp ${SOURCES_DIR}/internal/catch_xmlwriter.cpp + ${SOURCES_DIR}/internal/catch_test_case_info_hasher.cpp ) set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS}) diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index 92cdc205..656417f4 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -95,6 +95,7 @@ #include #include #include +#include #include #include #include diff --git a/src/catch2/internal/catch_test_case_info_hasher.cpp b/src/catch2/internal/catch_test_case_info_hasher.cpp new file mode 100644 index 00000000..75acc978 --- /dev/null +++ b/src/catch2/internal/catch_test_case_info_hasher.cpp @@ -0,0 +1,31 @@ +#include +#include + +namespace Catch { + TestCaseInfoHasher::TestCaseInfoHasher( hash_t seed ): m_seed( seed ) {} + + uint32_t TestCaseInfoHasher::operator()( TestCaseInfo const& t ) const { + // FNV-1a hash algorithm that is designed for uniqueness: + const hash_t prime = 1099511628211u; + hash_t hash = 14695981039346656037u; + for ( const char c : t.name ) { + hash ^= c; + hash *= prime; + } + for ( const char c : t.className ) { + hash ^= c; + hash *= prime; + } + for ( const Tag& tag : t.tags ) { + for ( const char c : tag.original ) { + hash ^= c; + hash *= prime; + } + } + hash ^= m_seed; + hash *= prime; + const uint32_t low{ static_cast( hash ) }; + const uint32_t high{ static_cast( hash >> 32 ) }; + return low * high; + } +} // namespace Catch diff --git a/src/catch2/internal/catch_test_case_info_hasher.hpp b/src/catch2/internal/catch_test_case_info_hasher.hpp new file mode 100644 index 00000000..954bdcde --- /dev/null +++ b/src/catch2/internal/catch_test_case_info_hasher.hpp @@ -0,0 +1,22 @@ +#ifndef CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED +#define CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED + +#include + +namespace Catch { + + struct TestCaseInfo; + + class TestCaseInfoHasher { + public: + using hash_t = std::uint64_t; + TestCaseInfoHasher( hash_t seed ); + uint32_t operator()( TestCaseInfo const& t ) const; + + private: + hash_t m_seed; + }; + +} // namespace Catch + +#endif /* CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED */ diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp index 3c1ab54b..6c491a95 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.cpp +++ b/src/catch2/internal/catch_test_case_registry_impl.cpp @@ -16,38 +16,13 @@ #include #include #include +#include #include #include namespace Catch { -namespace { - struct TestHasher { - using hash_t = uint64_t; - - explicit TestHasher( hash_t hashSuffix ): - m_hashSuffix( hashSuffix ) {} - - uint64_t m_hashSuffix; - - uint32_t operator()( TestCaseInfo const& t ) const { - // FNV-1a hash with multiplication fold. - const hash_t prime = 1099511628211u; - hash_t hash = 14695981039346656037u; - for (const char c : t.name) { - hash ^= c; - hash *= prime; - } - hash ^= m_hashSuffix; - hash *= prime; - const uint32_t low{ static_cast(hash) }; - const uint32_t high{ static_cast(hash >> 32) }; - return low * high; - } - }; -} // end anonymous namespace - std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ) { switch (config.runOrder()) { case TestRunOrder::Declared: @@ -66,9 +41,9 @@ namespace { } case TestRunOrder::Randomized: { seedRng(config); - using TestWithHash = std::pair; + using TestWithHash = std::pair; - TestHasher h{ config.rngSeed() }; + TestCaseInfoHasher h{ config.rngSeed() }; std::vector indexed_tests; indexed_tests.reserve(unsortedTestCases.size()); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ef1b13ea..1c520120 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -88,6 +88,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Reporters.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TestCaseInfoHasher.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/TestSpecParser.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/TextFlow.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Sharding.tests.cpp diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index fadb2747..9df8be0d 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -255,6 +255,8 @@ Message from section two :test-result: PASS Test case with one argument :test-result: PASS Test enum bit values :test-result: PASS Test with special, characters "in name +:test-result: PASS TestCaseInfoHasher produces different hashes. +:test-result: PASS TestCaseInfoHasher produces equal hashes. :test-result: PASS Testing checked-if :test-result: XFAIL Testing checked-if 2 :test-result: XFAIL Testing checked-if 3 diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index f05de0ab..10db54cd 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -248,6 +248,8 @@ :test-result: PASS Test case with one argument :test-result: PASS Test enum bit values :test-result: PASS Test with special, characters "in name +:test-result: PASS TestCaseInfoHasher produces different hashes. +:test-result: PASS TestCaseInfoHasher produces equal hashes. :test-result: PASS Testing checked-if :test-result: XFAIL Testing checked-if 2 :test-result: XFAIL Testing checked-if 3 diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 4688a228..8b404c58 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1868,6 +1868,21 @@ Tag.tests.cpp:: passed: testCase.tags[0] == Tag( "tag1" ) for: {?} VariadicMacros.tests.cpp:: passed: with 1 message: 'no assertions' Tricky.tests.cpp:: passed: 0x == bit30and31 for: 3221225472 (0x) == 3221225472 CmdLine.tests.cpp:: passed: +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 764519552 (0x) +!= +3472848544 (0x) +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 869111496 (0x) +!= +2870097333 (0x) +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 1172537240 (0x) +!= +1403724645 (0x) +TestCaseInfoHasher.tests.cpp:: passed: h1(testCase1) != h2(testCase2) for: 1836497244 (0x) +!= +430288597 (0x) +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) for: 764519552 (0x) +== +764519552 (0x) Misc.tests.cpp:: passed: true Misc.tests.cpp:: passed: Misc.tests.cpp:: failed - but was ok: false diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index c571b0c9..3b3e1eef 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -1861,6 +1861,21 @@ Tag.tests.cpp:: passed: testCase.tags[0] == Tag( "tag1" ) for: {?} VariadicMacros.tests.cpp:: passed: with 1 message: 'no assertions' Tricky.tests.cpp:: passed: 0x == bit30and31 for: 3221225472 (0x) == 3221225472 CmdLine.tests.cpp:: passed: +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 764519552 (0x) +!= +3472848544 (0x) +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 869111496 (0x) +!= +2870097333 (0x) +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 1172537240 (0x) +!= +1403724645 (0x) +TestCaseInfoHasher.tests.cpp:: passed: h1(testCase1) != h2(testCase2) for: 1836497244 (0x) +!= +430288597 (0x) +TestCaseInfoHasher.tests.cpp:: passed: hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) for: 764519552 (0x) +== +764519552 (0x) Misc.tests.cpp:: passed: true Misc.tests.cpp:: passed: Misc.tests.cpp:: failed - but was ok: false diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index ca0a77e5..61b1a112 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1395,6 +1395,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 386 | 310 passed | 69 failed | 7 failed as expected -assertions: 2219 | 2064 passed | 128 failed | 27 failed as expected +test cases: 388 | 312 passed | 69 failed | 7 failed as expected +assertions: 2224 | 2069 passed | 128 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 5655f50a..148a3b53 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -13286,6 +13286,76 @@ CmdLine.tests.cpp: CmdLine.tests.cpp:: PASSED: +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + class names are equal, names are equal but tags are different. +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) ) +with expansion: + 764519552 (0x) + != + 3472848544 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + class names are equal, tags are equal but names are different +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) ) +with expansion: + 869111496 (0x) + != + 2870097333 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + names are equal, tags are equal but class names are different +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) ) +with expansion: + 1172537240 (0x) + != + 1403724645 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + class names and names and tags are equal but hashers are seeded differently. +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( h1(testCase1) != h2(testCase2) ) +with expansion: + 1836497244 (0x) + != + 430288597 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces equal hashes. + class names and names and tags are equal. +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) ) +with expansion: + 764519552 (0x) + == + 764519552 (0x) + ------------------------------------------------------------------------------- Testing checked-if ------------------------------------------------------------------------------- @@ -17871,6 +17941,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 386 | 296 passed | 83 failed | 7 failed as expected -assertions: 2234 | 2064 passed | 143 failed | 27 failed as expected +test cases: 388 | 298 passed | 83 failed | 7 failed as expected +assertions: 2239 | 2069 passed | 143 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 32fa0689..412303da 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -13279,6 +13279,76 @@ CmdLine.tests.cpp: CmdLine.tests.cpp:: PASSED: +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + class names are equal, names are equal but tags are different. +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) ) +with expansion: + 764519552 (0x) + != + 3472848544 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + class names are equal, tags are equal but names are different +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) ) +with expansion: + 869111496 (0x) + != + 2870097333 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + names are equal, tags are equal but class names are different +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) ) +with expansion: + 1172537240 (0x) + != + 1403724645 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces different hashes. + class names and names and tags are equal but hashers are seeded differently. +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( h1(testCase1) != h2(testCase2) ) +with expansion: + 1836497244 (0x) + != + 430288597 (0x) + +------------------------------------------------------------------------------- +TestCaseInfoHasher produces equal hashes. + class names and names and tags are equal. +------------------------------------------------------------------------------- +TestCaseInfoHasher.tests.cpp: +............................................................................... + +TestCaseInfoHasher.tests.cpp:: PASSED: + CHECK( hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) ) +with expansion: + 764519552 (0x) + == + 764519552 (0x) + ------------------------------------------------------------------------------- Testing checked-if ------------------------------------------------------------------------------- @@ -17863,6 +17933,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 386 | 296 passed | 83 failed | 7 failed as expected -assertions: 2234 | 2064 passed | 143 failed | 27 failed as expected +test cases: 388 | 298 passed | 83 failed | 7 failed as expected +assertions: 2239 | 2069 passed | 143 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 3a099b4f..7c82e5b3 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1355,6 +1355,11 @@ Misc.tests.cpp: + + + + + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 527f7ba0..d850f16a 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -1354,6 +1354,11 @@ Misc.tests.cpp: + + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 92db65df..1a9d215d 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -273,6 +273,13 @@ + + + + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index c9074bf0..cbefb063 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -272,6 +272,13 @@ + + + + + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 456e80ee..67ceddfc 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -3297,6 +3297,16 @@ ok {test-number} - with 1 message: 'no assertions' ok {test-number} - 0x == bit30and31 for: 3221225472 (0x) == 3221225472 # Test with special, characters "in name ok {test-number} - +# TestCaseInfoHasher produces different hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 764519552 (0x) != 3472848544 (0x) +# TestCaseInfoHasher produces different hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 869111496 (0x) != 2870097333 (0x) +# TestCaseInfoHasher produces different hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 1172537240 (0x) != 1403724645 (0x) +# TestCaseInfoHasher produces different hashes. +ok {test-number} - h1(testCase1) != h2(testCase2) for: 1836497244 (0x) != 430288597 (0x) +# TestCaseInfoHasher produces equal hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) for: 764519552 (0x) == 764519552 (0x) # Testing checked-if ok {test-number} - true # Testing checked-if @@ -4470,5 +4480,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2234 +1..2239 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 534005df..d369326e 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -3290,6 +3290,16 @@ ok {test-number} - with 1 message: 'no assertions' ok {test-number} - 0x == bit30and31 for: 3221225472 (0x) == 3221225472 # Test with special, characters "in name ok {test-number} - +# TestCaseInfoHasher produces different hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 764519552 (0x) != 3472848544 (0x) +# TestCaseInfoHasher produces different hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 869111496 (0x) != 2870097333 (0x) +# TestCaseInfoHasher produces different hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) for: 1172537240 (0x) != 1403724645 (0x) +# TestCaseInfoHasher produces different hashes. +ok {test-number} - h1(testCase1) != h2(testCase2) for: 1836497244 (0x) != 430288597 (0x) +# TestCaseInfoHasher produces equal hashes. +ok {test-number} - hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) for: 764519552 (0x) == 764519552 (0x) # Testing checked-if ok {test-number} - true # Testing checked-if @@ -4462,5 +4472,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2234 +1..2239 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 43324e06..d9b98f70 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -615,6 +615,10 @@ Misc.tests.cpp:|nexpression failed|n CHECK( s1 == s2 )|nwith expan ##teamcity[testFinished name='Test enum bit values' duration="{duration}"] ##teamcity[testStarted name='Test with special, characters "in name'] ##teamcity[testFinished name='Test with special, characters "in name' duration="{duration}"] +##teamcity[testStarted name='TestCaseInfoHasher produces different hashes.'] +##teamcity[testFinished name='TestCaseInfoHasher produces different hashes.' duration="{duration}"] +##teamcity[testStarted name='TestCaseInfoHasher produces equal hashes.'] +##teamcity[testFinished name='TestCaseInfoHasher produces equal hashes.' duration="{duration}"] ##teamcity[testStarted name='Testing checked-if'] ##teamcity[testFinished name='Testing checked-if' duration="{duration}"] ##teamcity[testStarted name='Testing checked-if 2'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 3bc028a4..ffdae89c 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -615,6 +615,10 @@ Misc.tests.cpp:|nexpression failed|n CHECK( s1 == s2 )|nwith expan ##teamcity[testFinished name='Test enum bit values' duration="{duration}"] ##teamcity[testStarted name='Test with special, characters "in name'] ##teamcity[testFinished name='Test with special, characters "in name' duration="{duration}"] +##teamcity[testStarted name='TestCaseInfoHasher produces different hashes.'] +##teamcity[testFinished name='TestCaseInfoHasher produces different hashes.' duration="{duration}"] +##teamcity[testStarted name='TestCaseInfoHasher produces equal hashes.'] +##teamcity[testFinished name='TestCaseInfoHasher produces equal hashes.' duration="{duration}"] ##teamcity[testStarted name='Testing checked-if'] ##teamcity[testFinished name='Testing checked-if' duration="{duration}"] ##teamcity[testStarted name='Testing checked-if 2'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index f9518c3d..4facaec2 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -15579,6 +15579,77 @@ Message from section two + +
+ + + hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) + + + 764519552 (0x) +!= +3472848544 (0x) + + + +
+
+ + + hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) + + + 869111496 (0x) +!= +2870097333 (0x) + + + +
+
+ + + hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) + + + 1172537240 (0x) +!= +1403724645 (0x) + + + +
+
+ + + h1(testCase1) != h2(testCase2) + + + 1836497244 (0x) +!= +430288597 (0x) + + + +
+ +
+ +
+ + + hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) + + + 764519552 (0x) +== +764519552 (0x) + + + +
+ +
@@ -20991,6 +21062,6 @@ loose text artifact - - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 6617afe3..f6b172f5 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -15579,6 +15579,77 @@ Message from section two + +
+ + + hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) + + + 764519552 (0x) +!= +3472848544 (0x) + + + +
+
+ + + hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) + + + 869111496 (0x) +!= +2870097333 (0x) + + + +
+
+ + + hasherWithCustomSeed(testCase1) != hasherWithCustomSeed(testCase2) + + + 1172537240 (0x) +!= +1403724645 (0x) + + + +
+
+ + + h1(testCase1) != h2(testCase2) + + + 1836497244 (0x) +!= +430288597 (0x) + + + +
+ +
+ +
+ + + hasherWithCustomSeed(testCase1) == hasherWithCustomSeed(testCase2) + + + 764519552 (0x) +== +764519552 (0x) + + + +
+ +
@@ -20990,6 +21061,6 @@ There is no extra whitespace here - - + + 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 +#include +#include + +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)); + } +}