• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Created by Martin on 19/07/2017.
3  *
4  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
5  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  */
7 
8 #include "catch_config.hpp"
9 #include "catch_enforce.h"
10 #include "catch_stringref.h"
11 
12 namespace Catch {
13 
Config(ConfigData const & data)14     Config::Config( ConfigData const& data )
15     :   m_data( data ),
16         m_stream( openStream() )
17     {
18         // We need to trim filter specs to avoid trouble with superfluous
19         // whitespace (esp. important for bdd macros, as those are manually
20         // aligned with whitespace).
21 
22         for (auto& elem : m_data.testsOrTags) {
23             elem = trim(elem);
24         }
25         for (auto& elem : m_data.sectionsToRun) {
26             elem = trim(elem);
27         }
28 
29         TestSpecParser parser(ITagAliasRegistry::get());
30         if (!m_data.testsOrTags.empty()) {
31             m_hasTestFilters = true;
32             for (auto const& testOrTags : m_data.testsOrTags) {
33                 parser.parse(testOrTags);
34             }
35         }
36         m_testSpec = parser.testSpec();
37     }
38 
getFilename() const39     std::string const& Config::getFilename() const {
40         return m_data.outputFilename ;
41     }
42 
listTests() const43     bool Config::listTests() const          { return m_data.listTests; }
listTestNamesOnly() const44     bool Config::listTestNamesOnly() const  { return m_data.listTestNamesOnly; }
listTags() const45     bool Config::listTags() const           { return m_data.listTags; }
listReporters() const46     bool Config::listReporters() const      { return m_data.listReporters; }
47 
getProcessName() const48     std::string Config::getProcessName() const { return m_data.processName; }
getReporterName() const49     std::string const& Config::getReporterName() const { return m_data.reporterName; }
50 
getTestsOrTags() const51     std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; }
getSectionsToRun() const52     std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
53 
testSpec() const54     TestSpec const& Config::testSpec() const { return m_testSpec; }
hasTestFilters() const55     bool Config::hasTestFilters() const { return m_hasTestFilters; }
56 
showHelp() const57     bool Config::showHelp() const { return m_data.showHelp; }
58 
59     // IConfig interface
allowThrows() const60     bool Config::allowThrows() const                   { return !m_data.noThrow; }
stream() const61     std::ostream& Config::stream() const               { return m_stream->stream(); }
name() const62     std::string Config::name() const                   { return m_data.name.empty() ? m_data.processName : m_data.name; }
includeSuccessfulResults() const63     bool Config::includeSuccessfulResults() const      { return m_data.showSuccessfulTests; }
warnAboutMissingAssertions() const64     bool Config::warnAboutMissingAssertions() const    { return !!(m_data.warnings & WarnAbout::NoAssertions); }
warnAboutNoTests() const65     bool Config::warnAboutNoTests() const              { return !!(m_data.warnings & WarnAbout::NoTests); }
showDurations() const66     ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; }
runOrder() const67     RunTests::InWhatOrder Config::runOrder() const     { return m_data.runOrder; }
rngSeed() const68     unsigned int Config::rngSeed() const               { return m_data.rngSeed; }
useColour() const69     UseColour::YesOrNo Config::useColour() const       { return m_data.useColour; }
shouldDebugBreak() const70     bool Config::shouldDebugBreak() const              { return m_data.shouldDebugBreak; }
abortAfter() const71     int Config::abortAfter() const                     { return m_data.abortAfter; }
showInvisibles() const72     bool Config::showInvisibles() const                { return m_data.showInvisibles; }
verbosity() const73     Verbosity Config::verbosity() const                { return m_data.verbosity; }
74 
benchmarkNoAnalysis() const75     bool Config::benchmarkNoAnalysis() const                      { return m_data.benchmarkNoAnalysis; }
benchmarkSamples() const76     int Config::benchmarkSamples() const                          { return m_data.benchmarkSamples; }
benchmarkConfidenceInterval() const77     double Config::benchmarkConfidenceInterval() const            { return m_data.benchmarkConfidenceInterval; }
benchmarkResamples() const78     unsigned int Config::benchmarkResamples() const               { return m_data.benchmarkResamples; }
benchmarkWarmupTime() const79     std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
80 
openStream()81     IStream const* Config::openStream() {
82         return Catch::makeStream(m_data.outputFilename);
83     }
84 
85 } // end namespace Catch
86