2010-11-10 00:24:00 +01: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)
|
|
|
|
*/
|
|
|
|
|
2017-07-10 14:25:38 +02:00
|
|
|
#include "catch_list.h"
|
|
|
|
|
|
|
|
#include "catch_interfaces_registry_hub.h"
|
|
|
|
#include "catch_interfaces_reporter.h"
|
|
|
|
#include "catch_interfaces_testcase.h"
|
|
|
|
|
2019-02-08 10:41:23 +01:00
|
|
|
#include "catch_context.h"
|
2017-08-29 16:44:02 +02:00
|
|
|
#include "catch_stream.h"
|
2017-07-25 21:57:35 +02:00
|
|
|
#include "catch_text.h"
|
2017-07-18 21:27:42 +02:00
|
|
|
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_console_colour.h"
|
|
|
|
#include "catch_test_spec_parser.h"
|
2017-07-20 20:50:47 +02:00
|
|
|
#include "catch_tostring.h"
|
2017-07-25 21:57:35 +02:00
|
|
|
#include "catch_string_manip.h"
|
2013-03-28 23:13:31 +01:00
|
|
|
|
2010-11-11 21:42:16 +01:00
|
|
|
#include <limits>
|
2013-03-28 23:13:31 +01:00
|
|
|
#include <algorithm>
|
2019-06-16 16:12:47 +02:00
|
|
|
#include <set>
|
2010-11-11 21:56:38 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
2019-06-16 16:12:47 +02:00
|
|
|
namespace {
|
2013-03-28 23:13:31 +01:00
|
|
|
|
2019-06-21 23:15:08 +02:00
|
|
|
void listTests(IStreamingReporter& reporter, Config const& config) {
|
2019-06-16 16:12:47 +02:00
|
|
|
TestSpec testSpec = config.testSpec();
|
|
|
|
auto matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
2019-06-21 23:15:08 +02:00
|
|
|
reporter.listTests(matchedTestCases, config);
|
2014-05-16 19:24:07 +02:00
|
|
|
}
|
2013-03-28 23:13:31 +01:00
|
|
|
|
2019-06-21 23:15:08 +02:00
|
|
|
void listTags(IStreamingReporter& reporter, Config const& config) {
|
2019-06-16 16:12:47 +02:00
|
|
|
TestSpec testSpec = config.testSpec();
|
2019-11-04 21:35:57 +01:00
|
|
|
std::vector<TestCaseHandle> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
2013-07-03 20:14:59 +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());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-06-21 23:15:08 +02:00
|
|
|
void listReporters(IStreamingReporter& reporter, Config const& config) {
|
|
|
|
std::vector<ReporterDescription> descriptions;
|
|
|
|
|
2019-06-16 16:12:47 +02:00
|
|
|
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
2019-06-21 23:15:08 +02:00
|
|
|
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 19:44:37 +02:00
|
|
|
}
|
2019-06-16 16:12:47 +02:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2013-11-26 21:57:34 +01: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 20:02:10 +02: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;
|
|
|
|
}
|
|
|
|
|
2019-06-21 23:15:08 +02:00
|
|
|
bool list( IStreamingReporter& reporter, std::shared_ptr<Config> const& config ) {
|
2019-06-16 16:12:47 +02:00
|
|
|
bool listed = false;
|
|
|
|
getCurrentMutableContext().setConfig( config );
|
|
|
|
if (config->listTests()) {
|
|
|
|
listed = true;
|
2019-06-21 23:15:08 +02:00
|
|
|
listTests(reporter, *config);
|
2014-05-16 19:24:07 +02:00
|
|
|
}
|
2019-06-16 16:12:47 +02:00
|
|
|
if (config->listTags()) {
|
|
|
|
listed = true;
|
2019-06-21 23:15:08 +02:00
|
|
|
listTags(reporter, *config);
|
2013-03-29 12:42:10 +01:00
|
|
|
}
|
2019-06-16 16:12:47 +02:00
|
|
|
if (config->listReporters()) {
|
|
|
|
listed = true;
|
2019-06-21 23:15:08 +02:00
|
|
|
listReporters(reporter, *config);
|
2013-06-07 19:56:43 +02:00
|
|
|
}
|
2019-06-16 16:12:47 +02:00
|
|
|
return listed;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
} // end namespace Catch
|