2020-08-30 15:43:45 +02:00
|
|
|
|
|
|
|
|
// 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
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_list.hpp>
|
2017-07-10 14:25:38 +02:00
|
|
|
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
|
|
|
|
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
2020-08-23 18:16:10 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
|
2020-08-23 21:19:26 +02:00
|
|
|
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
2017-07-10 14:25:38 +02:00
|
|
|
|
2020-03-30 10:34:21 +02:00
|
|
|
#include <catch2/internal/catch_context.hpp>
|
2020-07-29 16:29:41 +02:00
|
|
|
#include <catch2/catch_config.hpp>
|
2020-08-13 14:00:19 +02:00
|
|
|
#include <catch2/catch_test_spec.hpp>
|
2020-07-29 14:30:19 +02:00
|
|
|
#include <catch2/catch_test_case_info.hpp>
|
2013-03-28 22:13:31 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
namespace Catch {
|
2019-06-16 16:12:47 +02:00
|
|
|
namespace {
|
2013-03-28 22:13:31 +00:00
|
|
|
|
2020-08-11 09:34:25 +02:00
|
|
|
void listTests(IStreamingReporter& reporter, IConfig const& config) {
|
2020-01-25 20:39:17 +01:00
|
|
|
auto const& testSpec = config.testSpec();
|
2019-06-16 16:12:47 +02:00
|
|
|
auto matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
2019-06-21 23:15:08 +02:00
|
|
|
reporter.listTests(matchedTestCases, config);
|
2014-04-15 18:44:37 +01:00
|
|
|
}
|
2013-11-12 18:59:34 +00:00
|
|
|
|
2020-08-11 09:34:25 +02:00
|
|
|
void listTags(IStreamingReporter& reporter, IConfig const& config) {
|
2020-01-25 20:39:17 +01:00
|
|
|
auto const& testSpec = config.testSpec();
|
2019-11-04 21:35:57 +01:00
|
|
|
std::vector<TestCaseHandle> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
2019-06-16 16:12:47 +02:00
|
|
|
|
2019-11-07 12:39:07 +01:00
|
|
|
std::map<StringRef, TagInfo> tagCounts;
|
2019-06-16 16:12:47 +02:00
|
|
|
for (auto const& testCase : matchedTestCases) {
|
|
|
|
|
for (auto const& tagName : testCase.getTestCaseInfo().tags) {
|
2019-11-07 12:39:07 +01:00
|
|
|
auto it = tagCounts.find(tagName.lowerCased);
|
|
|
|
|
if (it == tagCounts.end())
|
|
|
|
|
it = tagCounts.insert(std::make_pair(tagName.lowerCased, TagInfo())).first;
|
|
|
|
|
it->second.add(tagName.original);
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 23:15:08 +02:00
|
|
|
std::vector<TagInfo> infos; infos.reserve(tagCounts.size());
|
2020-08-19 17:44:22 +02:00
|
|
|
for (auto& tagc : tagCounts) {
|
2019-06-21 23:15:08 +02:00
|
|
|
infos.push_back(std::move(tagc.second));
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
2019-06-21 23:15:08 +02:00
|
|
|
|
|
|
|
|
reporter.listTags(infos, config);
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 09:34:25 +02:00
|
|
|
void listReporters(IStreamingReporter& reporter, IConfig const& config) {
|
2019-06-21 23:15:08 +02:00
|
|
|
std::vector<ReporterDescription> descriptions;
|
2019-06-16 16:12:47 +02:00
|
|
|
|
2019-06-21 23:15:08 +02:00
|
|
|
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
|
|
|
|
descriptions.reserve(factories.size());
|
|
|
|
|
for (auto const& fac : factories) {
|
|
|
|
|
descriptions.push_back({ fac.first, fac.second->getDescription() });
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
2019-06-21 23:15:08 +02:00
|
|
|
|
|
|
|
|
reporter.listReporters(descriptions, config);
|
2014-04-15 18:44:37 +01:00
|
|
|
}
|
2019-06-16 16:12:47 +02:00
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
2013-11-26 20:57:34 +00:00
|
|
|
|
2019-11-07 12:39:07 +01:00
|
|
|
void TagInfo::add( StringRef spelling ) {
|
2017-07-10 14:25:38 +02:00
|
|
|
++count;
|
|
|
|
|
spellings.insert( spelling );
|
|
|
|
|
}
|
2014-05-20 19:02:10 +01:00
|
|
|
|
2017-07-10 14:25:38 +02:00
|
|
|
std::string TagInfo::all() const {
|
2019-11-07 12:39:07 +01:00
|
|
|
// 2 per tag for brackets '[' and ']'
|
|
|
|
|
size_t size = spellings.size() * 2;
|
2019-08-05 19:12:25 +02:00
|
|
|
for (auto const& spelling : spellings) {
|
2019-11-07 12:39:07 +01:00
|
|
|
size += spelling.size();
|
2019-08-05 19:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string out; out.reserve(size);
|
|
|
|
|
for (auto const& spelling : spellings) {
|
|
|
|
|
out += '[';
|
|
|
|
|
out += spelling;
|
|
|
|
|
out += ']';
|
|
|
|
|
}
|
2017-07-10 14:25:38 +02:00
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-19 17:29:24 +02:00
|
|
|
bool list( IStreamingReporter& reporter, Config const& config ) {
|
2019-06-16 16:12:47 +02:00
|
|
|
bool listed = false;
|
2020-05-19 17:29:24 +02:00
|
|
|
if (config.listTests()) {
|
2019-06-16 16:12:47 +02:00
|
|
|
listed = true;
|
2020-05-19 17:29:24 +02:00
|
|
|
listTests(reporter, config);
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
2020-05-19 17:29:24 +02:00
|
|
|
if (config.listTags()) {
|
2019-06-16 16:12:47 +02:00
|
|
|
listed = true;
|
2020-05-19 17:29:24 +02:00
|
|
|
listTags(reporter, config);
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
2020-05-19 17:29:24 +02:00
|
|
|
if (config.listReporters()) {
|
2019-06-16 16:12:47 +02:00
|
|
|
listed = true;
|
2020-05-19 17:29:24 +02:00
|
|
|
listReporters(reporter, config);
|
2019-06-16 16:12:47 +02:00
|
|
|
}
|
|
|
|
|
return listed;
|
2010-11-09 23:24:00 +00:00
|
|
|
}
|
2013-07-03 19:14:59 +01:00
|
|
|
|
2010-11-09 23:24:00 +00:00
|
|
|
} // end namespace Catch
|