Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2017-12-05 23:26:21 +0000
committerPhil Nash2017-12-05 23:26:21 +0000
commit5e063616dfc2e6f12edac666129f0cf58f5d7ae4 (patch)
treeffcb0859e68df05e64575399de0b1b634d9b46f6 /include
parentaa9d635014c3ab321fe65bd59c50fa71d6a86583 (diff)
downloadcatch3-5e063616dfc2e6f12edac666129f0cf58f5d7ae4.tar.gz
Moved runner helpers into Catch namespace
not sure they weren't there to start with
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_session.cpp124
1 files changed, 59 insertions, 65 deletions
diff --git a/include/internal/catch_session.cpp b/include/internal/catch_session.cpp
index 5a6a8434..b1c00d05 100644
--- a/include/internal/catch_session.cpp
+++ b/include/internal/catch_session.cpp
@@ -22,97 +22,91 @@
#include <cstdlib>
#include <iomanip>
+namespace Catch {
-namespace {
- const int MaxExitCode = 255;
- using Catch::IStreamingReporterPtr;
- using Catch::IConfigPtr;
- using Catch::Config;
+ namespace {
+ const int MaxExitCode = 255;
- IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
- auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
- CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
+ IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) {
+ auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
+ CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
- return reporter;
- }
+ return reporter;
+ }
#ifndef CATCH_CONFIG_DEFAULT_REPORTER
#define CATCH_CONFIG_DEFAULT_REPORTER "console"
#endif
- IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
- auto const& reporterNames = config->getReporterNames();
- if (reporterNames.empty())
- return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config);
+ IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) {
+ auto const& reporterNames = config->getReporterNames();
+ if (reporterNames.empty())
+ return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config);
- IStreamingReporterPtr reporter;
- for (auto const& name : reporterNames)
- addReporter(reporter, createReporter(name, config));
- return reporter;
- }
+ IStreamingReporterPtr reporter;
+ for (auto const& name : reporterNames)
+ addReporter(reporter, createReporter(name, config));
+ return reporter;
+ }
#undef CATCH_CONFIG_DEFAULT_REPORTER
- void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) {
- auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
- for (auto const& listener : listeners)
- addReporter(reporters, listener->create(Catch::ReporterConfig(config)));
- }
+ void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) {
+ auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
+ for (auto const& listener : listeners)
+ 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);
+ Catch::Totals runTests(std::shared_ptr<Config> const& config) {
+ IStreamingReporterPtr reporter = makeReporter(config);
+ addListeners(reporter, config);
- RunContext context(config, std::move(reporter));
+ RunContext context(config, std::move(reporter));
- Totals totals;
+ Totals totals;
- context.testGroupStarting(config->name(), 1, 1);
+ context.testGroupStarting(config->name(), 1, 1);
- TestSpec testSpec = config->testSpec();
- if (!testSpec.hasFilters())
- testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests
+ 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 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;
}
- context.testGroupEnded(config->name(), totals, 1, 1);
- return totals;
- }
+ void applyFilenamesAsTags(Catch::IConfig const& config) {
+ auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
+ for (auto& testCase : tests) {
+ auto tags = testCase.tags;
- void applyFilenamesAsTags(Catch::IConfig const& config) {
- using namespace Catch;
- auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
- for (auto& testCase : tests) {
- auto tags = testCase.tags;
-
- std::string filename = testCase.lineInfo.file;
- auto lastSlash = filename.find_last_of("\\/");
- if (lastSlash != std::string::npos) {
- filename.erase(0, lastSlash);
- filename[0] = '#';
- }
+ 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);
- }
+ auto lastDot = filename.find_last_of('.');
+ if (lastDot != std::string::npos) {
+ filename.erase(lastDot);
+ }
- tags.push_back(std::move(filename));
- setTags(testCase, tags);
+ tags.push_back(std::move(filename));
+ setTags(testCase, tags);
+ }
}
- }
-}
-
-namespace Catch {
+ } // anon namespace
Session::Session() {
static bool alreadyInstantiated = false;