Files
Catch2/src/catch2/internal/catch_list.cpp
T

104 lines
3.5 KiB
C++
Raw Normal View History

2010-11-09 23:24:00 +00:00
/*
* Created by Phil on 5/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
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>
#include <catch2/interfaces/catch_interfaces_testcase.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>
#include <catch2/catch_test_case_info.hpp>
2012-05-15 23:58:23 +01:00
namespace Catch {
2019-06-16 16:12:47 +02:00
namespace {
void listTests(IStreamingReporter& reporter, IConfig const& config) {
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);
}
void listTags(IStreamingReporter& reporter, IConfig const& config) {
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
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) {
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());
for (auto const& tagc : tagCounts) {
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
}
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);
}
2019-06-16 16:12:47 +02:00
} // end anonymous namespace
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 {
// 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) {
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;
}
bool list( IStreamingReporter& reporter, Config const& config ) {
2019-06-16 16:12:47 +02:00
bool listed = false;
if (config.listTests()) {
2019-06-16 16:12:47 +02:00
listed = true;
listTests(reporter, config);
2019-06-16 16:12:47 +02:00
}
if (config.listTags()) {
2019-06-16 16:12:47 +02:00
listed = true;
listTags(reporter, config);
2019-06-16 16:12:47 +02:00
}
if (config.listReporters()) {
2019-06-16 16:12:47 +02:00
listed = true;
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