// Copyright Catch2 Authors // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 #include #include #include #include #include #include #include #include #include #include TEST_CASE( "The default listing implementation write to provided stream", "[reporters][reporter-helpers]" ) { using Catch::Matchers::ContainsSubstring; using namespace std::string_literals; std::stringstream sstream; SECTION( "Listing tags" ) { std::vector tags(1); tags[0].add("fakeTag"_catch_sr); Catch::defaultListTags(sstream, tags, false); auto listingString = sstream.str(); REQUIRE_THAT(listingString, ContainsSubstring("[fakeTag]"s)); } SECTION( "Listing reporters" ) { std::vector reporters( { { "fake reporter", "fake description" } } ); Catch::defaultListReporters(sstream, reporters, Catch::Verbosity::Normal); auto listingString = sstream.str(); REQUIRE_THAT(listingString, ContainsSubstring("fake reporter"s)); } SECTION( "Listing tests" ) { Catch::TestCaseInfo fakeInfo{ ""s, { "fake test name"_catch_sr, "[fakeTestTag]"_catch_sr }, { "fake-file.cpp", 123456789 } }; std::vector tests({ {&fakeInfo, nullptr} }); Catch::defaultListTests(sstream, tests, false, Catch::Verbosity::Normal); auto listingString = sstream.str(); REQUIRE_THAT( listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) ); } } TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) { using Catch::Matchers::ContainsSubstring; using namespace std::string_literals; auto const& factories = Catch::getRegistryHub().getReporterRegistry().getFactories(); // If there are no reporters, the test would pass falsely // while there is something obviously broken REQUIRE_FALSE(factories.empty()); for (auto const& factory : factories) { INFO("Tested reporter: " << factory.first); std::stringstream sstream; Catch::ConfigData config_data; Catch::Config config( config_data ); Catch::ReporterConfig rep_config( &config, sstream ); auto reporter = factory.second->create( rep_config ); DYNAMIC_SECTION( factory.first << " reporter lists tags" ) { std::vector tags(1); tags[0].add("fakeTag"_catch_sr); reporter->listTags(tags); auto listingString = sstream.str(); REQUIRE_THAT(listingString, ContainsSubstring("fakeTag"s)); } DYNAMIC_SECTION( factory.first << " reporter lists reporters" ) { std::vector reporters( { { "fake reporter", "fake description" } } ); reporter->listReporters(reporters); auto listingString = sstream.str(); REQUIRE_THAT(listingString, ContainsSubstring("fake reporter"s)); } DYNAMIC_SECTION( factory.first << " reporter lists tests" ) { Catch::TestCaseInfo fakeInfo{ ""s, { "fake test name"_catch_sr, "[fakeTestTag]"_catch_sr }, { "fake-file.cpp", 123456789 } }; std::vector tests({ {&fakeInfo, nullptr} }); reporter->listTests(tests); auto listingString = sstream.str(); REQUIRE_THAT( listingString, ContainsSubstring( "fake test name"s ) && ContainsSubstring( "fakeTestTag"s ) ); } } } TEST_CASE("Reproducer for #2309 - a very long description past 80 chars (default console width) with a late colon : blablabla", "[console-reporter]") { SUCCEED(); }