diff options
| author | Martin Hořeňovský | 2022-04-12 21:22:43 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-04-13 15:00:50 +0200 |
| commit | 79d1e8238135427a6780a6db2cdb8b9be0b7f086 (patch) | |
| tree | 13b7a82bbad094af77171b2807b5d9241acc1721 /tests | |
| parent | 4f09f1120ba0a28f218a00821a8347a443042ecb (diff) | |
| download | catch3-79d1e8238135427a6780a6db2cdb8b9be0b7f086.tar.gz | |
Store IStream instance owning ptrs in reporter instances
This ended up being a surprisingly large refactoring, motivated
by removing a `const_cast` from `Config`'s handling of reporter
streams, forced by previous commit.
Diffstat (limited to 'tests')
16 files changed, 60 insertions, 51 deletions
diff --git a/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp b/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp index 2ef629bf..c75d891e 100644 --- a/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp +++ b/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp @@ -20,12 +20,13 @@ #include <catch2/reporters/catch_reporter_registrars.hpp> #include <iostream> +#include <utility> class CumulativeBenchmarkReporter final : public Catch::CumulativeReporterBase { public: - CumulativeBenchmarkReporter(Catch::ReporterConfig const& _config) : - CumulativeReporterBase(_config) { + CumulativeBenchmarkReporter(Catch::ReporterConfig&& _config) : + CumulativeReporterBase(std::move(_config)) { m_preferences.shouldReportAllAssertions = true; } diff --git a/tests/ExtraTests/X23-CasingInReporterNames.cpp b/tests/ExtraTests/X23-CasingInReporterNames.cpp index b5dcb403..0e13f205 100644 --- a/tests/ExtraTests/X23-CasingInReporterNames.cpp +++ b/tests/ExtraTests/X23-CasingInReporterNames.cpp @@ -19,11 +19,12 @@ #include <catch2/reporters/catch_reporter_registrars.hpp> #include <iostream> +#include <utility> class TestReporter : public Catch::StreamingReporterBase { public: - TestReporter(Catch::ReporterConfig const& _config): - StreamingReporterBase(_config) { + TestReporter(Catch::ReporterConfig&& _config): + StreamingReporterBase(std::move(_config)) { std::cout << "TestReporter constructed\n"; } diff --git a/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp b/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp index af3a3202..01aca7c0 100644 --- a/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp +++ b/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp @@ -16,13 +16,14 @@ #include <catch2/reporters/catch_reporter_registrars.hpp> #include <iostream> +#include <utility> namespace { class TestReporter : public Catch::StreamingReporterBase { public: - TestReporter(Catch::ReporterConfig const& _config): - StreamingReporterBase(_config) { + TestReporter(Catch::ReporterConfig&& _config): + StreamingReporterBase(std::move(_config)) { m_preferences.shouldReportAllAssertions = false; std::cout << "X26 - TestReporter constructed\n"; } diff --git a/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp b/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp index 871ed53c..cb29be0c 100644 --- a/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp +++ b/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp @@ -26,6 +26,7 @@ #include <iostream> #include <string> +#include <utility> class TestReporter : public Catch::StreamingReporterBase { std::string stdOutString( uint64_t iter ){ @@ -36,8 +37,8 @@ class TestReporter : public Catch::StreamingReporterBase { } public: - TestReporter( Catch::ReporterConfig const& _config ): - StreamingReporterBase( _config ) { + TestReporter( Catch::ReporterConfig&& _config ): + StreamingReporterBase( std::move(_config) ) { m_preferences.shouldRedirectStdOut = true; std::cout << "X27 - TestReporter constructed\n"; } diff --git a/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp b/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp index ce2d31eb..c8102edb 100644 --- a/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp +++ b/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp @@ -19,7 +19,9 @@ #include <catch2/reporters/catch_reporter_event_listener.hpp> #include <catch2/reporters/catch_reporter_registrars.hpp> #include <catch2/reporters/catch_reporter_streaming_base.hpp> + #include <iostream> +#include <utility> namespace { @@ -54,8 +56,8 @@ namespace { class TestReporter : public Catch::StreamingReporterBase { public: - TestReporter( Catch::ReporterConfig const& _config ): - StreamingReporterBase( _config ) { + TestReporter( Catch::ReporterConfig&& _config ): + StreamingReporterBase( std::move(_config) ) { std::cout << "X28 - TestReporter constructed\n"; } diff --git a/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp b/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp index 9721775d..d3af7dc7 100644 --- a/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp +++ b/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp @@ -25,8 +25,8 @@ class TestReporter : public Catch::StreamingReporterBase { public: - TestReporter( Catch::ReporterConfig const& _config ): - StreamingReporterBase( _config ) { + TestReporter( Catch::ReporterConfig&& _config ): + StreamingReporterBase( std::move(_config) ) { std::cout << "X29 - TestReporter constructed\n"; } diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 96fb47ce..bac5115f 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1317,7 +1317,7 @@ CmdLine.tests.cpp:<line number>: passed: config.noThrow == false for: false == f CmdLine.tests.cpp:<line number>: passed: config.reporterSpecifications.empty() for: true CmdLine.tests.cpp:<line number>: passed: !(cfg.hasTestFilters()) for: !false CmdLine.tests.cpp:<line number>: passed: cfg.getReporterSpecs().size() == 1 for: 1 == 1 -CmdLine.tests.cpp:<line number>: passed: cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } for: {?} == {?} +CmdLine.tests.cpp:<line number>: passed: cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } for: {?} == {?} CmdLine.tests.cpp:<line number>: passed: result for: {?} CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(*fakeTestCase("notIncluded")) == false for: false == false diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index c1ac5044..88c3dc5a 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -1315,7 +1315,7 @@ CmdLine.tests.cpp:<line number>: passed: config.noThrow == false for: false == f CmdLine.tests.cpp:<line number>: passed: config.reporterSpecifications.empty() for: true CmdLine.tests.cpp:<line number>: passed: !(cfg.hasTestFilters()) for: !false CmdLine.tests.cpp:<line number>: passed: cfg.getReporterSpecs().size() == 1 for: 1 == 1 -CmdLine.tests.cpp:<line number>: passed: cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } for: {?} == {?} +CmdLine.tests.cpp:<line number>: passed: cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } for: {?} == {?} CmdLine.tests.cpp:<line number>: passed: result for: {?} CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(*fakeTestCase("notIncluded")) == false for: false == false diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 938e96b0..d0e3e990 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -9438,7 +9438,7 @@ with expansion: 1 == 1 CmdLine.tests.cpp:<line number>: PASSED: - CHECK( cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } ) + CHECK( cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } ) with expansion: {?} == {?} diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index dea69f25..512d4966 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -9436,7 +9436,7 @@ with expansion: 1 == 1 CmdLine.tests.cpp:<line number>: PASSED: - CHECK( cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } ) + CHECK( cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } ) with expansion: {?} == {?} diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 6c38f276..c4e166db 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -2481,7 +2481,7 @@ ok {test-number} - !(cfg.hasTestFilters()) for: !false # Process can be configured on command line ok {test-number} - cfg.getReporterSpecs().size() == 1 for: 1 == 1 # Process can be configured on command line -ok {test-number} - cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } for: {?} == {?} +ok {test-number} - cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } for: {?} == {?} # Process can be configured on command line ok {test-number} - result for: {?} # Process can be configured on command line diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 35777386..54cb7d84 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -2479,7 +2479,7 @@ ok {test-number} - !(cfg.hasTestFilters()) for: !false # Process can be configured on command line ok {test-number} - cfg.getReporterSpecs().size() == 1 for: 1 == 1 # Process can be configured on command line -ok {test-number} - cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } for: {?} == {?} +ok {test-number} - cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } for: {?} == {?} # Process can be configured on command line ok {test-number} - result for: {?} # Process can be configured on command line diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index d2710bd3..f250f926 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -11476,7 +11476,7 @@ C </Expression> <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } + cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } </Original> <Expanded> {?} == {?} diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 085a5cad..e19bbb1f 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -11476,7 +11476,7 @@ C </Expression> <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" > <Original> - cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, {}, {}, {} } + cfg.getReporterSpecs()[0] == Catch::ReporterSpec{ expectedReporter, std::string{}, Catch::ColourMode::PlatformDefault, {} } </Original> <Expanded> {?} == {?} diff --git a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 30cc3a0d..0f02af69 100644 --- a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -363,7 +363,10 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" CHECK( cfg.getReporterSpecs().size() == 1 ); CHECK( cfg.getReporterSpecs()[0] == - Catch::ReporterSpec{ expectedReporter, {}, {}, {} } ); + Catch::ReporterSpec{ expectedReporter, + std::string{}, + Catch::ColourMode::PlatformDefault, + {} } ); } SECTION("test lists") { diff --git a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp index 84f2b689..e4554fca 100644 --- a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp @@ -23,6 +23,7 @@ #include <catch2/reporters/catch_reporter_event_listener.hpp> #include <catch2/reporters/catch_reporter_streaming_base.hpp> #include <catch2/reporters/catch_reporter_multi.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <sstream> @@ -34,6 +35,15 @@ namespace { private: std::stringstream sstr; }; + + //! config must outlive the function + Catch::ReporterConfig makeDummyRepConfig( Catch::Config const& config ) { + return Catch::ReporterConfig{ + &config, + Catch::Detail::make_unique<StringIStream>(), + Catch::ColourMode::None, + {} }; + } } TEST_CASE( "The default listing implementation write to provided stream", @@ -85,20 +95,19 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) { for (auto const& factory : factories) { INFO("Tested reporter: " << factory.first); - StringIStream sstream; + auto sstream = Catch::Detail::make_unique<StringIStream>(); + auto& sstreamRef = *sstream.get(); - Catch::ConfigData config_data; - Catch::Config config( config_data ); - Catch::ReporterConfig rep_config( - &config, &sstream, Catch::ColourMode::None, {} ); - auto reporter = factory.second->create( rep_config ); + Catch::Config config( Catch::ConfigData{} ); + auto reporter = factory.second->create( Catch::ReporterConfig{ + &config, CATCH_MOVE( sstream ), Catch::ColourMode::None, {} } ); DYNAMIC_SECTION( factory.first << " reporter lists tags" ) { std::vector<Catch::TagInfo> tags(1); tags[0].add("fakeTag"_catch_sr); reporter->listTags(tags); - auto listingString = sstream.str(); + auto listingString = sstreamRef.str(); REQUIRE_THAT(listingString, ContainsSubstring("fakeTag"s)); } @@ -107,7 +116,7 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) { { { "fake reporter", "fake description" } } ); reporter->listReporters(reporters); - auto listingString = sstream.str(); + auto listingString = sstreamRef.str(); REQUIRE_THAT(listingString, ContainsSubstring("fake reporter"s)); } @@ -119,7 +128,7 @@ TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) { std::vector<Catch::TestCaseHandle> tests({ {&fakeInfo, nullptr} }); reporter->listTests(tests); - auto listingString = sstream.str(); + auto listingString = sstreamRef.str(); REQUIRE_THAT( listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) ); @@ -159,8 +168,8 @@ namespace { public: MockReporter( std::string witness, std::vector<std::string>& recorder, - Catch::ReporterConfig const& config ): - StreamingReporterBase( config ), + Catch::ReporterConfig&& config ): + StreamingReporterBase( CATCH_MOVE(config) ), m_witness( witness ), m_recorder( recorder ) {} @@ -173,25 +182,20 @@ namespace { TEST_CASE("Multireporter calls reporters and listeners in correct order", "[reporters][multi-reporter]") { - - Catch::ConfigData config_data; - Catch::Config config( config_data ); - StringIStream sstream; - Catch::ReporterConfig rep_config( - &config, &sstream, Catch::ColourMode::None, {} ); + Catch::Config config( Catch::ConfigData{} ); // We add reporters before listeners, to check that internally they // get sorted properly, and listeners are called first anyway. Catch::MultiReporter multiReporter( &config ); std::vector<std::string> records; multiReporter.addReporter( Catch::Detail::make_unique<MockReporter>( - "Goodbye", records, rep_config ) ); + "Goodbye", records, makeDummyRepConfig(config) ) ); multiReporter.addListener( Catch::Detail::make_unique<MockListener>( "Hello", records, &config ) ); multiReporter.addListener( Catch::Detail::make_unique<MockListener>( "world", records, &config ) ); multiReporter.addReporter( Catch::Detail::make_unique<MockReporter>( - "world", records, rep_config ) ); + "world", records, makeDummyRepConfig(config) ) ); multiReporter.testRunStarting( { "" } ); std::vector<std::string> expected( { "Hello", "world", "Goodbye", "world" } ); @@ -217,8 +221,8 @@ namespace { public: PreferenceReporter( bool redirectStdout, bool reportAllAssertions, - Catch::ReporterConfig const& config ): - StreamingReporterBase( config ) { + Catch::ReporterConfig&& config ): + StreamingReporterBase( CATCH_MOVE(config) ) { m_preferences.shouldRedirectStdOut = redirectStdout; m_preferences.shouldReportAllAssertions = reportAllAssertions; } @@ -228,11 +232,7 @@ namespace { TEST_CASE("Multireporter updates ReporterPreferences properly", "[reporters][multi-reporter]") { - Catch::ConfigData config_data; - Catch::Config config( config_data ); - StringIStream sstream; - Catch::ReporterConfig rep_config( - &config, &sstream, Catch::ColourMode::None, {} ); + Catch::Config config( Catch::ConfigData{} ); Catch::MultiReporter multiReporter( &config ); // Post init defaults @@ -261,19 +261,19 @@ TEST_CASE("Multireporter updates ReporterPreferences properly", SECTION( "Adding reporters" ) { multiReporter.addReporter( Catch::Detail::make_unique<PreferenceReporter>( - true, false, rep_config ) ); + true, false, makeDummyRepConfig(config) ) ); REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true ); REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false ); multiReporter.addReporter( Catch::Detail::make_unique<PreferenceReporter>( - false, true, rep_config ) ); + false, true, makeDummyRepConfig( config ) ) ); REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true ); REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true ); multiReporter.addReporter( Catch::Detail::make_unique<PreferenceReporter>( - false, false, rep_config ) ); + false, false, makeDummyRepConfig( config ) ) ); REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true ); REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true ); } @@ -281,7 +281,7 @@ TEST_CASE("Multireporter updates ReporterPreferences properly", namespace { class TestReporterFactory : public Catch::IReporterFactory { - Catch::IEventListenerPtr create( Catch::ReporterConfig const& ) const override { + Catch::IEventListenerPtr create( Catch::ReporterConfig&& ) const override { CATCH_INTERNAL_ERROR( "This factory should never create a reporter" ); } |