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-06-21 23:15:08 +02:00
|
|
|
std::vector<TestCase> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2019-06-16 16:12:47 +02:00
|
|
|
std::map<std::string, TagInfo> tagCounts;
|
|
|
|
for (auto const& testCase : matchedTestCases) {
|
|
|
|
for (auto const& tagName : testCase.getTestCaseInfo().tags) {
|
|
|
|
std::string lcaseTagName = toLower(tagName);
|
|
|
|
auto countIt = tagCounts.find(lcaseTagName);
|
|
|
|
if (countIt == tagCounts.end())
|
|
|
|
countIt = tagCounts.insert(std::make_pair(lcaseTagName, TagInfo())).first;
|
|
|
|
countIt->second.add(tagName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-07-10 14:25:38 +02:00
|
|
|
void TagInfo::add( std::string const& spelling ) {
|
|
|
|
++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-08-05 19:12:25 +02:00
|
|
|
size_t size = 0;
|
|
|
|
for (auto const& spelling : spellings) {
|
|
|
|
// Add 2 for the brackes
|
|
|
|
size += spelling.size() + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|