From 480f3f418b07cba56421041564211f24d8376e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 1 Jun 2020 19:04:23 +0200 Subject: [PATCH] Improved generator tracking * Successive executions of the same `GENERATE` macro (e.g. because of a for loop) no longer lead to multiple nested generators. * The same line can now contain multiple `GENERATE` macros without issues. Fixes #1913 --- examples/311-Gen-CustomCapture.cpp | 2 +- src/catch2/generators/catch_generators.hpp | 19 +++-- .../internal/catch_generators_combined_tu.cpp | 4 +- .../interfaces/catch_interfaces_capture.hpp | 2 +- src/catch2/internal/catch_run_context.cpp | 26 +++++-- src/catch2/internal/catch_run_context.hpp | 2 +- .../internal/catch_test_case_tracker.hpp | 4 ++ .../Baselines/automake.sw.approved.txt | 2 + .../Baselines/compact.sw.approved.txt | 6 ++ .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 70 ++++++++++++++++++- .../Baselines/console.swa4.approved.txt | 70 ++++++++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 4 +- .../Baselines/sonarqube.sw.approved.txt | 2 + tests/SelfTest/Baselines/tap.sw.approved.txt | 14 +++- .../Baselines/teamcity.sw.approved.txt | 4 ++ tests/SelfTest/Baselines/xml.sw.approved.txt | 58 ++++++++++++++- .../SelfTest/UsageTests/Generators.tests.cpp | 16 +++++ 18 files changed, 283 insertions(+), 26 deletions(-) diff --git a/examples/311-Gen-CustomCapture.cpp b/examples/311-Gen-CustomCapture.cpp index 13a7eab3..d12ee709 100644 --- a/examples/311-Gen-CustomCapture.cpp +++ b/examples/311-Gen-CustomCapture.cpp @@ -29,7 +29,7 @@ TEST_CASE("Generate random doubles across different ranges", // This will take r1 by reference and r2 by value. // Note that there are no advantages for doing so in this example, // it is done only for expository purposes. - auto number = Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, + auto number = Catch::Generators::generate( "custom capture generator", CATCH_INTERNAL_LINEINFO, [&r1, r2]{ using namespace Catch::Generators; return makeGenerators(take(50, random(std::get<0>(r1), std::get<1>(r2)))); diff --git a/src/catch2/generators/catch_generators.hpp b/src/catch2/generators/catch_generators.hpp index 2e8fad14..c08c811b 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -179,16 +180,16 @@ namespace Detail { return makeGenerators( value( T( std::forward( val ) ) ), std::forward( moreGenerators )... ); } - auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker&; + auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker&; template // Note: The type after -> is weird, because VS2015 cannot parse // the expression used in the typedef inside, when it is in // return type. Yeah. - auto generate( SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval().get()) { + auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval().get()) { using UnderlyingType = typename decltype(generatorExpression())::type; - IGeneratorTracker& tracker = acquireGeneratorTracker( lineInfo ); + IGeneratorTracker& tracker = acquireGeneratorTracker( generatorName, lineInfo ); if (!tracker.hasGenerator()) { tracker.setGenerator(Catch::Detail::make_unique>(generatorExpression())); } @@ -201,10 +202,16 @@ namespace Detail { } // namespace Catch #define GENERATE( ... ) \ - Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) + Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ + CATCH_INTERNAL_LINEINFO, \ + [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) #define GENERATE_COPY( ... ) \ - Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) + Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ + CATCH_INTERNAL_LINEINFO, \ + [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) #define GENERATE_REF( ... ) \ - Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) + Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \ + CATCH_INTERNAL_LINEINFO, \ + [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace) #endif // TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED diff --git a/src/catch2/generators/internal/catch_generators_combined_tu.cpp b/src/catch2/generators/internal/catch_generators_combined_tu.cpp index f8b6ca4c..5fed3127 100644 --- a/src/catch2/generators/internal/catch_generators_combined_tu.cpp +++ b/src/catch2/generators/internal/catch_generators_combined_tu.cpp @@ -50,8 +50,8 @@ namespace Detail { GeneratorUntypedBase::~GeneratorUntypedBase() = default; - auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { - return getResultCapture().acquireGeneratorTracker( lineInfo ); + auto acquireGeneratorTracker(StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { + return getResultCapture().acquireGeneratorTracker( generatorName, lineInfo ); } } // namespace Generators diff --git a/src/catch2/interfaces/catch_interfaces_capture.hpp b/src/catch2/interfaces/catch_interfaces_capture.hpp index d26d4f27..9a3e84f5 100644 --- a/src/catch2/interfaces/catch_interfaces_capture.hpp +++ b/src/catch2/interfaces/catch_interfaces_capture.hpp @@ -42,7 +42,7 @@ namespace Catch { virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; - virtual auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0; + virtual auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0; virtual void benchmarkPreparing( std::string const& name ) = 0; virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0; diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index f59a604c..d4caedd2 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -27,12 +27,27 @@ namespace Catch { std::shared_ptr tracker; ITracker& currentTracker = ctx.currentTracker(); - if( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { + // Under specific circumstances, the generator we want + // to acquire is also the current tracker. If this is + // the case, we have to avoid looking through current + // tracker's children, and instead return the current + // tracker. + // A case where this check is important is e.g. + // for (int i = 0; i < 5; ++i) { + // int n = GENERATE(1, 2); + // } + // + // without it, the code above creates 5 nested generators. + if (currentTracker.nameAndLocation() == nameAndLocation) { + auto thisTracker = currentTracker.parent().findChild(nameAndLocation); + assert(thisTracker); + assert(thisTracker->isGeneratorTracker()); + tracker = std::static_pointer_cast(thisTracker); + } else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) { assert( childTracker ); assert( childTracker->isGeneratorTracker() ); tracker = std::static_pointer_cast( childTracker ); - } - else { + } else { tracker = std::make_shared( nameAndLocation, ctx, ¤tTracker ); currentTracker.addChild( tracker ); } @@ -181,9 +196,10 @@ namespace Catch { return true; } - auto RunContext::acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { + auto RunContext::acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { using namespace Generators; - GeneratorTracker& tracker = GeneratorTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( "generator", lineInfo ) ); + GeneratorTracker& tracker = GeneratorTracker::acquire(m_trackerContext, + TestCaseTracking::NameAndLocation( static_cast(generatorName), lineInfo ) ); assert( tracker.isOpen() ); m_lastAssertionInfo.lineInfo = lineInfo; return tracker; diff --git a/src/catch2/internal/catch_run_context.hpp b/src/catch2/internal/catch_run_context.hpp index e9625717..af9fb386 100644 --- a/src/catch2/internal/catch_run_context.hpp +++ b/src/catch2/internal/catch_run_context.hpp @@ -76,7 +76,7 @@ namespace Catch { void sectionEnded( SectionEndInfo const& endInfo ) override; void sectionEndedEarly( SectionEndInfo const& endInfo ) override; - auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override; + auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override; void benchmarkPreparing( std::string const& name ) override; void benchmarkStarting( BenchmarkInfo const& info ) override; diff --git a/src/catch2/internal/catch_test_case_tracker.hpp b/src/catch2/internal/catch_test_case_tracker.hpp index 3d9cace9..04a6a048 100644 --- a/src/catch2/internal/catch_test_case_tracker.hpp +++ b/src/catch2/internal/catch_test_case_tracker.hpp @@ -23,6 +23,10 @@ namespace TestCaseTracking { SourceLineInfo location; NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); + friend bool operator==(NameAndLocation const& lhs, NameAndLocation const& rhs) { + return lhs.name == rhs.name + && lhs.location == rhs.location; + } }; struct ITracker; diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index ffde555a..c9fe3ede 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -14,6 +14,8 @@ Nor would this :test-result: PASS #1548 :test-result: PASS #1905 -- test spec parser properly clears internal state between compound tests :test-result: PASS #1912 -- test spec parser handles escaping +:test-result: PASS #1913 - GENERATE inside a for loop should not keep recreating the generator +:test-result: PASS #1913 - GENERATEs can share a line :test-result: XFAIL #748 - captures with unexpected exceptions :test-result: PASS #809 :test-result: PASS #833 diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 977837ea..eb7bcc07 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -29,6 +29,12 @@ CmdLine.tests.cpp:: passed: spec.matches(*fakeTestCase(R"(spec {a} CmdLine.tests.cpp:: passed: spec.matches(*fakeTestCase(R"(spec [a] char)")) for: true CmdLine.tests.cpp:: passed: !(spec.matches(*fakeTestCase("differs but has similar tag", "[a]"))) for: !false CmdLine.tests.cpp:: passed: spec.matches(*fakeTestCase(R"(spec \ char)")) for: true +Generators.tests.cpp:: passed: counter < 7 for: 3 < 7 +Generators.tests.cpp:: passed: counter < 7 for: 6 < 7 +Generators.tests.cpp:: passed: i != j for: 1 != 3 +Generators.tests.cpp:: passed: i != j for: 1 != 4 +Generators.tests.cpp:: passed: i != j for: 2 != 3 +Generators.tests.cpp:: passed: i != j for: 2 != 4 Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' Exception.tests.cpp:: passed: thisThrows() with 1 message: 'answer := 42' diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index b20e5353..89e4a9d9 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 337 | 263 passed | 70 failed | 4 failed as expected -assertions: 1926 | 1774 passed | 131 failed | 21 failed as expected +test cases: 339 | 265 passed | 70 failed | 4 failed as expected +assertions: 1932 | 1780 passed | 131 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index bc46d209..a9c4d46d 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -236,6 +236,72 @@ CmdLine.tests.cpp:: PASSED: with expansion: true +------------------------------------------------------------------------------- +#1913 - GENERATE inside a for loop should not keep recreating the generator +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( counter < 7 ) +with expansion: + 3 < 7 + +------------------------------------------------------------------------------- +#1913 - GENERATE inside a for loop should not keep recreating the generator +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( counter < 7 ) +with expansion: + 6 < 7 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 1 != 3 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 1 != 4 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 2 != 3 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 2 != 4 + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -15058,6 +15124,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 337 | 247 passed | 86 failed | 4 failed as expected -assertions: 1943 | 1774 passed | 148 failed | 21 failed as expected +test cases: 339 | 249 passed | 86 failed | 4 failed as expected +assertions: 1949 | 1780 passed | 148 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/console.swa4.approved.txt b/tests/SelfTest/Baselines/console.swa4.approved.txt index bb7ee973..26a53c23 100644 --- a/tests/SelfTest/Baselines/console.swa4.approved.txt +++ b/tests/SelfTest/Baselines/console.swa4.approved.txt @@ -236,6 +236,72 @@ CmdLine.tests.cpp:: PASSED: with expansion: true +------------------------------------------------------------------------------- +#1913 - GENERATE inside a for loop should not keep recreating the generator +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( counter < 7 ) +with expansion: + 3 < 7 + +------------------------------------------------------------------------------- +#1913 - GENERATE inside a for loop should not keep recreating the generator +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( counter < 7 ) +with expansion: + 6 < 7 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 1 != 3 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 1 != 4 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 2 != 3 + +------------------------------------------------------------------------------- +#1913 - GENERATEs can share a line +------------------------------------------------------------------------------- +Generators.tests.cpp: +............................................................................... + +Generators.tests.cpp:: PASSED: + REQUIRE( i != j ) +with expansion: + 2 != 4 + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -416,6 +482,6 @@ Condition.tests.cpp:: FAILED: CHECK( true != true ) =============================================================================== -test cases: 21 | 16 passed | 3 failed | 2 failed as expected -assertions: 48 | 41 passed | 4 failed | 3 failed as expected +test cases: 23 | 18 passed | 3 failed | 2 failed as expected +assertions: 54 | 47 passed | 4 failed | 3 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index a29e54aa..5e4669ec 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -33,6 +33,8 @@ Nor would this + + FAILED: diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 03be4906..43c8dfec 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -915,6 +915,8 @@ Exception.tests.cpp: + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index e2f5e004..7123e139 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -56,6 +56,18 @@ ok {test-number} - spec.matches(*fakeTestCase(R"(spec [a] char)")) for: true ok {test-number} - !(spec.matches(*fakeTestCase("differs but has similar tag", "[a]"))) for: !false # #1912 -- test spec parser handles escaping ok {test-number} - spec.matches(*fakeTestCase(R"(spec \ char)")) for: true +# #1913 - GENERATE inside a for loop should not keep recreating the generator +ok {test-number} - counter < 7 for: 3 < 7 +# #1913 - GENERATE inside a for loop should not keep recreating the generator +ok {test-number} - counter < 7 for: 6 < 7 +# #1913 - GENERATEs can share a line +ok {test-number} - i != j for: 1 != 3 +# #1913 - GENERATEs can share a line +ok {test-number} - i != j for: 1 != 4 +# #1913 - GENERATEs can share a line +ok {test-number} - i != j for: 2 != 3 +# #1913 - GENERATEs can share a line +ok {test-number} - i != j for: 2 != 4 # #748 - captures with unexpected exceptions not ok {test-number} - unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' # #748 - captures with unexpected exceptions @@ -3878,5 +3890,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..1935 +1..1941 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 3f64f272..6d3023e5 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -30,6 +30,10 @@ Tricky.tests.cpp:|nexplicit failure with message:|n "1514"'] ##teamcity[testFinished name='#1905 -- test spec parser properly clears internal state between compound tests' duration="{duration}"] ##teamcity[testStarted name='#1912 -- test spec parser handles escaping'] ##teamcity[testFinished name='#1912 -- test spec parser handles escaping' duration="{duration}"] +##teamcity[testStarted name='#1913 - GENERATE inside a for loop should not keep recreating the generator'] +##teamcity[testFinished name='#1913 - GENERATE inside a for loop should not keep recreating the generator' duration="{duration}"] +##teamcity[testStarted name='#1913 - GENERATEs can share a line'] +##teamcity[testFinished name='#1913 - GENERATEs can share a line' duration="{duration}"] ##teamcity[testStarted name='#748 - captures with unexpected exceptions'] Exception.tests.cpp:|nunexpected exception with messages:|n "answer := 42"|n "expected exception"- failure ignore as test marked as |'ok to fail|'|n'] Exception.tests.cpp:|nunexpected exception with messages:|n "answer := 42"|n "expected exception"|n REQUIRE_NOTHROW( thisThrows() )|nwith expansion:|n thisThrows()|n- failure ignore as test marked as |'ok to fail|'|n'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 4d39e14d..2f6f01fc 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -251,6 +251,60 @@ Nor would this + + + + counter < 7 + + + 3 < 7 + + + + + counter < 7 + + + 6 < 7 + + + + + + + + i != j + + + 1 != 3 + + + + + i != j + + + 1 != 4 + + + + + i != j + + + 2 != 3 + + + + + i != j + + + 2 != 4 + + + +
@@ -18055,7 +18109,7 @@ loose text artifact
- + - + diff --git a/tests/SelfTest/UsageTests/Generators.tests.cpp b/tests/SelfTest/UsageTests/Generators.tests.cpp index 45088111..acfef8a9 100644 --- a/tests/SelfTest/UsageTests/Generators.tests.cpp +++ b/tests/SelfTest/UsageTests/Generators.tests.cpp @@ -255,6 +255,22 @@ TEST_CASE("Copy and then generate a range", "[generators]") { } } +TEST_CASE("#1913 - GENERATE inside a for loop should not keep recreating the generator", "[regression][generators]") { + static int counter = 0; + for (int i = 0; i < 3; ++i) { + int _ = GENERATE(1, 2); + (void)_; + ++counter; + } + // There should be at most 6 (3 * 2) counter increments + REQUIRE(counter < 7); +} + +TEST_CASE("#1913 - GENERATEs can share a line", "[regression][generators]") { + int i = GENERATE(1, 2); int j = GENERATE(3, 4); + REQUIRE(i != j); +} + #if defined(__clang__) #pragma clang diagnostic pop #endif