Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-01-27 09:07:15 +0100
committerGitHub2021-01-27 09:07:15 +0100
commitb435e391c45c7cdb23c35cd2afb3435b0b7e53c7 (patch)
treea4bb48202c96d1dd4b7efe83f98c2919d890d1c9 /tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp
parentba8150516800dd5e18f818346a2a12c45b6ec542 (diff)
parent971b1fc32a857caa10eb166f39442cee5237267b (diff)
downloadcatch3-b435e391c45c7cdb23c35cd2afb3435b0b7e53c7.tar.gz
Merge pull request #2163 from catchorg/devel-list-outputs-to-out-flag
The output of --list-* flags obeys -o flag
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp')
-rw-r--r--tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp
new file mode 100644
index 00000000..c5c97998
--- /dev/null
+++ b/tests/SelfTest/IntrospectiveTests/Reporters.tests.cpp
@@ -0,0 +1,109 @@
+
+// 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 <catch2/catch_test_macros.hpp>
+
+#include <catch2/catch_test_case_info.hpp>
+#include <catch2/catch_config.hpp>
+#include <catch2/interfaces/catch_interfaces_reporter.hpp>
+#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
+#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
+#include <catch2/internal/catch_list.hpp>
+#include <catch2/matchers/catch_matchers_string.hpp>
+#include <catch2/reporters/catch_reporter_helpers.hpp>
+
+#include <sstream>
+
+TEST_CASE( "The default listing implementation write to provided stream",
+ "[reporters][reporter-helpers]" ) {
+ using Catch::Matchers::Contains;
+ using namespace std::string_literals;
+
+ std::stringstream sstream;
+ SECTION( "Listing tags" ) {
+ std::vector<Catch::TagInfo> tags(1);
+ tags[0].add("fakeTag"_catch_sr);
+ Catch::defaultListTags(sstream, tags, false);
+
+ auto listingString = sstream.str();
+ REQUIRE_THAT(listingString, Contains("[fakeTag]"s));
+ }
+ SECTION( "Listing reporters" ) {
+ std::vector<Catch::ReporterDescription> reporters(
+ { { "fake reporter", "fake description" } } );
+ Catch::defaultListReporters(sstream, reporters, Catch::Verbosity::Normal);
+
+ auto listingString = sstream.str();
+ REQUIRE_THAT(listingString, Contains("fake reporter"s));
+ }
+ SECTION( "Listing tests" ) {
+ Catch::TestCaseInfo fakeInfo{
+ ""s,
+ { "fake test name"_catch_sr, "[fakeTestTag]"_catch_sr },
+ { "fake-file.cpp", 123456789 } };
+ std::vector<Catch::TestCaseHandle> tests({ {&fakeInfo, nullptr} });
+ Catch::defaultListTests(sstream, tests, false, Catch::Verbosity::Normal);
+
+ auto listingString = sstream.str();
+ REQUIRE_THAT( listingString,
+ Contains( "fake test name"s ) &&
+ Contains( "fakeTestTag"s ) );
+ }
+}
+
+TEST_CASE( "Reporter's write listings to provided stream", "[reporters]" ) {
+ using Catch::Matchers::Contains;
+ 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<Catch::TagInfo> tags(1);
+ tags[0].add("fakeTag"_catch_sr);
+ reporter->listTags(tags);
+
+ auto listingString = sstream.str();
+ REQUIRE_THAT(listingString, Contains("fakeTag"s));
+ }
+
+ DYNAMIC_SECTION( factory.first << " reporter lists reporters" ) {
+ std::vector<Catch::ReporterDescription> reporters(
+ { { "fake reporter", "fake description" } } );
+ reporter->listReporters(reporters);
+
+ auto listingString = sstream.str();
+ REQUIRE_THAT(listingString, Contains("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<Catch::TestCaseHandle> tests({ {&fakeInfo, nullptr} });
+ reporter->listTests(tests);
+
+ auto listingString = sstream.str();
+ REQUIRE_THAT( listingString,
+ Contains( "fake test name"s ) &&
+ Contains( "fakeTestTag"s ) );
+ }
+ }
+}