From 33704524d868f88a25560a83acd219d6933a5c44 Mon Sep 17 00:00:00 2001 From: Marcel Gotsch Date: Sat, 27 Aug 2022 22:08:35 +0200 Subject: [PATCH] fixup! Report generator states for failed assertions --- examples/311-Gen-CustomCapture.cpp | 2 +- src/catch2/generators/catch_generators.hpp | 4 ++-- src/catch2/internal/catch_generator_info.cpp | 6 ++++-- src/catch2/internal/catch_generator_info.hpp | 8 +++++--- src/catch2/reporters/catch_reporter_console.cpp | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/311-Gen-CustomCapture.cpp b/examples/311-Gen-CustomCapture.cpp index 5266d294..efd99032 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( "custom capture generator", "custom definition", CATCH_INTERNAL_LINEINFO, + auto number = Catch::Generators::generate( "custom capture generator", "custom arguments description", 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 41d8e582..fb830d51 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -211,7 +211,7 @@ namespace Detail { // 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( StringRef generatorName, StringRef definition, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval().get()) { + auto generate( StringRef generatorName, StringRef argumentsDescription, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval().get()) { using UnderlyingType = typename decltype(generatorExpression())::type; IGeneratorTracker& tracker = acquireGeneratorTracker( generatorName, lineInfo ); @@ -220,7 +220,7 @@ namespace Detail { } auto const& generator = static_cast const&>( *tracker.getGenerator() ); - getResultCapture().trackGeneratorState(GeneratorInfo(definition, lineInfo, generator.currentElementAsString())); + getResultCapture().trackGeneratorState(GeneratorInfo(generatorName, argumentsDescription, lineInfo, generator.currentElementAsString())); return generator.get(); } diff --git a/src/catch2/internal/catch_generator_info.cpp b/src/catch2/internal/catch_generator_info.cpp index b1160a58..760c7fc1 100644 --- a/src/catch2/internal/catch_generator_info.cpp +++ b/src/catch2/internal/catch_generator_info.cpp @@ -10,10 +10,12 @@ namespace Catch { - GeneratorInfo::GeneratorInfo( StringRef _definition, + GeneratorInfo::GeneratorInfo( StringRef _name, + StringRef _arguments, SourceLineInfo const& _lineInfo, StringRef _currentElement ): - definition( _definition ), + name( _name ), + arguments( _arguments ), lineInfo( _lineInfo ), currentElement( _currentElement ) {} diff --git a/src/catch2/internal/catch_generator_info.hpp b/src/catch2/internal/catch_generator_info.hpp index dd4a4aa2..5cdc24f8 100644 --- a/src/catch2/internal/catch_generator_info.hpp +++ b/src/catch2/internal/catch_generator_info.hpp @@ -15,16 +15,18 @@ namespace Catch { struct GeneratorInfo { - GeneratorInfo( StringRef _definition, + GeneratorInfo( StringRef _name, + StringRef _arguments, SourceLineInfo const& _lineInfo, StringRef currentElement ); - StringRef definition; + StringRef name; + StringRef arguments; SourceLineInfo lineInfo; StringRef currentElement; bool operator==( GeneratorInfo const& other ) const { - return definition == other.definition && + return name == other.name && arguments == other.arguments && lineInfo == other.lineInfo && currentElement == other.currentElement; } diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index d2eb4a2e..c310d345 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -164,7 +164,7 @@ private: for ( auto const& info : stats.generatorInfos ) { stream << TextFlow::Column( "line:" ).indent( 2 ) << info.lineInfo.line << ": " - << "GENERATE(" << info.definition << ")\n" + << "GENERATE(" << info.arguments << ")\n" << TextFlow::Column( "value: " ).indent( 2 ) << colourImpl->guardColour( Colour::GeneratorValue ) << info.currentElement << '\n';