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

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_interfaces_reporter.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-06-21 23:15:08 +0200
committerMartin Hořeňovský2019-10-29 14:07:18 +0100
commit85b129c741d7493df178c4e0644cd221ad434141 (patch)
treeca0427cc57cccd85734d0bb3b17175a77d6cfa09 /include/internal/catch_interfaces_reporter.cpp
parent0f39438aaefe70a89aaee65e8ce78c490a6b03b5 (diff)
downloadcatch3-85b129c741d7493df178c4e0644cd221ad434141.tar.gz
Pipe --list* through reporters
This allows us to provide machine-readable listings through the XMLReporter and it will also allow users to define their own listing format that does whatever their own tools need.
Diffstat (limited to 'include/internal/catch_interfaces_reporter.cpp')
-rw-r--r--include/internal/catch_interfaces_reporter.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/include/internal/catch_interfaces_reporter.cpp b/include/internal/catch_interfaces_reporter.cpp
index 0c367c5b..664dd3eb 100644
--- a/include/internal/catch_interfaces_reporter.cpp
+++ b/include/internal/catch_interfaces_reporter.cpp
@@ -6,7 +6,13 @@
*/
#include "catch_interfaces_reporter.h"
+#include "catch_console_colour.h"
#include "../reporters/catch_reporter_listening.h"
+#include "catch_list.h"
+#include "catch_text.h"
+
+#include <algorithm>
+#include <iomanip>
namespace Catch {
@@ -108,6 +114,86 @@ namespace Catch {
void IStreamingReporter::fatalErrorEncountered( StringRef ) {}
bool IStreamingReporter::isMulti() const { return false; }
+ void IStreamingReporter::listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) {
+ Catch::cout() << "Available reporters:\n";
+ const auto maxNameLen = std::max_element(descriptions.begin(), descriptions.end(),
+ [](ReporterDescription const& lhs, ReporterDescription const& rhs) { return lhs.name.size() < rhs.name.size(); })
+ ->name.size();
+
+ for (auto const& desc : descriptions) {
+ if (config.verbosity() == Verbosity::Quiet) {
+ Catch::cout()
+ << Column(desc.name)
+ .indent(2)
+ .width(5 + maxNameLen) << '\n';
+ } else {
+ Catch::cout()
+ << Column(desc.name + ":")
+ .indent(2)
+ .width(5 + maxNameLen)
+ + Column(desc.description)
+ .initialIndent(0)
+ .indent(2)
+ .width(CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen - 8)
+ << '\n';
+ }
+ }
+ Catch::cout() << std::endl;
+ }
+
+ void IStreamingReporter::listTests(std::vector<TestCase> const& tests, Config const& config) {
+ if (config.hasTestFilters())
+ Catch::cout() << "Matching test cases:\n";
+ else {
+ Catch::cout() << "All available test cases:\n";
+ }
+
+ for (auto const& testCaseInfo : tests) {
+ Colour::Code colour = testCaseInfo.isHidden()
+ ? Colour::SecondaryText
+ : Colour::None;
+ Colour colourGuard(colour);
+
+ Catch::cout() << Column(testCaseInfo.name).initialIndent(2).indent(4) << '\n';
+ if (config.verbosity() >= Verbosity::High) {
+ Catch::cout() << Column(Catch::Detail::stringify(testCaseInfo.lineInfo)).indent(4) << std::endl;
+ std::string description = testCaseInfo.description;
+ if (description.empty())
+ description = "(NO DESCRIPTION)";
+ Catch::cout() << Column(description).indent(4) << std::endl;
+ }
+ if (!testCaseInfo.tags.empty() && config.verbosity() > Verbosity::Quiet) {
+ Catch::cout() << Column(testCaseInfo.tagsAsString()).indent(6) << '\n';
+ }
+ }
+
+ if (!config.hasTestFilters()) {
+ Catch::cout() << pluralise(tests.size(), "test case") << '\n' << std::endl;
+ } else {
+ Catch::cout() << pluralise(tests.size(), "matching test case") << '\n' << std::endl;
+ }
+ }
+
+ void IStreamingReporter::listTags(std::vector<TagInfo> const& tags, Config const& config) {
+ if (config.hasTestFilters()) {
+ Catch::cout() << "Tags for matching test cases:\n";
+ } else {
+ Catch::cout() << "All available tags:\n";
+ }
+
+ for (auto const& tagCount : tags) {
+ ReusableStringStream rss;
+ rss << " " << std::setw(2) << tagCount.count << " ";
+ auto str = rss.str();
+ auto wrapper = Column(tagCount.all())
+ .initialIndent(0)
+ .indent(str.size())
+ .width(CATCH_CONFIG_CONSOLE_WIDTH - 10);
+ Catch::cout() << str << wrapper << '\n';
+ }
+ Catch::cout() << pluralise(tags.size(), "tag") << '\n' << std::endl;
+ }
+
IReporterFactory::~IReporterFactory() = default;
IReporterRegistry::~IReporterRegistry() = default;