mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-25 23:06:10 +01:00
Moved runner helpers into Catch namespace
not sure they weren't there to start with
This commit is contained in:
parent
aa9d635014
commit
5e063616df
@ -22,97 +22,91 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const int MaxExitCode = 255;
|
const int MaxExitCode = 255;
|
||||||
using Catch::IStreamingReporterPtr;
|
|
||||||
using Catch::IConfigPtr;
|
|
||||||
using Catch::Config;
|
|
||||||
|
|
||||||
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
|
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
|
||||||
auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
|
auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
|
||||||
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
|
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
|
||||||
|
|
||||||
return reporter;
|
return reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CATCH_CONFIG_DEFAULT_REPORTER
|
#ifndef CATCH_CONFIG_DEFAULT_REPORTER
|
||||||
#define CATCH_CONFIG_DEFAULT_REPORTER "console"
|
#define CATCH_CONFIG_DEFAULT_REPORTER "console"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
|
IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
|
||||||
auto const& reporterNames = config->getReporterNames();
|
auto const& reporterNames = config->getReporterNames();
|
||||||
if (reporterNames.empty())
|
if (reporterNames.empty())
|
||||||
return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config);
|
return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config);
|
||||||
|
|
||||||
IStreamingReporterPtr reporter;
|
IStreamingReporterPtr reporter;
|
||||||
for (auto const& name : reporterNames)
|
for (auto const& name : reporterNames)
|
||||||
addReporter(reporter, createReporter(name, config));
|
addReporter(reporter, createReporter(name, config));
|
||||||
return reporter;
|
return reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef CATCH_CONFIG_DEFAULT_REPORTER
|
#undef CATCH_CONFIG_DEFAULT_REPORTER
|
||||||
|
|
||||||
void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) {
|
void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) {
|
||||||
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
|
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
|
||||||
for (auto const& listener : listeners)
|
for (auto const& listener : listeners)
|
||||||
addReporter(reporters, listener->create(Catch::ReporterConfig(config)));
|
addReporter(reporters, listener->create(Catch::ReporterConfig(config)));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Catch::Totals runTests(std::shared_ptr<Config> const& config) {
|
|
||||||
using namespace Catch;
|
|
||||||
IStreamingReporterPtr reporter = makeReporter(config);
|
|
||||||
addListeners(reporter, config);
|
|
||||||
|
|
||||||
RunContext context(config, std::move(reporter));
|
|
||||||
|
|
||||||
Totals totals;
|
|
||||||
|
|
||||||
context.testGroupStarting(config->name(), 1, 1);
|
|
||||||
|
|
||||||
TestSpec testSpec = config->testSpec();
|
|
||||||
if (!testSpec.hasFilters())
|
|
||||||
testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests
|
|
||||||
|
|
||||||
auto const& allTestCases = getAllTestCasesSorted(*config);
|
|
||||||
for (auto const& testCase : allTestCases) {
|
|
||||||
if (!context.aborting() && matchTest(testCase, testSpec, *config))
|
|
||||||
totals += context.runTest(testCase);
|
|
||||||
else
|
|
||||||
context.reporter().skipTest(testCase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.testGroupEnded(config->name(), totals, 1, 1);
|
|
||||||
return totals;
|
|
||||||
}
|
|
||||||
|
|
||||||
void applyFilenamesAsTags(Catch::IConfig const& config) {
|
Catch::Totals runTests(std::shared_ptr<Config> const& config) {
|
||||||
using namespace Catch;
|
IStreamingReporterPtr reporter = makeReporter(config);
|
||||||
auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
|
addListeners(reporter, config);
|
||||||
for (auto& testCase : tests) {
|
|
||||||
auto tags = testCase.tags;
|
|
||||||
|
|
||||||
std::string filename = testCase.lineInfo.file;
|
RunContext context(config, std::move(reporter));
|
||||||
auto lastSlash = filename.find_last_of("\\/");
|
|
||||||
if (lastSlash != std::string::npos) {
|
Totals totals;
|
||||||
filename.erase(0, lastSlash);
|
|
||||||
filename[0] = '#';
|
context.testGroupStarting(config->name(), 1, 1);
|
||||||
|
|
||||||
|
TestSpec testSpec = config->testSpec();
|
||||||
|
if (!testSpec.hasFilters())
|
||||||
|
testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests
|
||||||
|
|
||||||
|
auto const& allTestCases = getAllTestCasesSorted(*config);
|
||||||
|
for (auto const& testCase : allTestCases) {
|
||||||
|
if (!context.aborting() && matchTest(testCase, testSpec, *config))
|
||||||
|
totals += context.runTest(testCase);
|
||||||
|
else
|
||||||
|
context.reporter().skipTest(testCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lastDot = filename.find_last_of('.');
|
context.testGroupEnded(config->name(), totals, 1, 1);
|
||||||
if (lastDot != std::string::npos) {
|
return totals;
|
||||||
filename.erase(lastDot);
|
|
||||||
}
|
|
||||||
|
|
||||||
tags.push_back(std::move(filename));
|
|
||||||
setTags(testCase, tags);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
void applyFilenamesAsTags(Catch::IConfig const& config) {
|
||||||
|
auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
|
||||||
|
for (auto& testCase : tests) {
|
||||||
|
auto tags = testCase.tags;
|
||||||
|
|
||||||
namespace Catch {
|
std::string filename = testCase.lineInfo.file;
|
||||||
|
auto lastSlash = filename.find_last_of("\\/");
|
||||||
|
if (lastSlash != std::string::npos) {
|
||||||
|
filename.erase(0, lastSlash);
|
||||||
|
filename[0] = '#';
|
||||||
|
}
|
||||||
|
|
||||||
|
auto lastDot = filename.find_last_of('.');
|
||||||
|
if (lastDot != std::string::npos) {
|
||||||
|
filename.erase(lastDot);
|
||||||
|
}
|
||||||
|
|
||||||
|
tags.push_back(std::move(filename));
|
||||||
|
setTags(testCase, tags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anon namespace
|
||||||
|
|
||||||
Session::Session() {
|
Session::Session() {
|
||||||
static bool alreadyInstantiated = false;
|
static bool alreadyInstantiated = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user