catch_config.cpp 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "catch_config.hpp"
  8. #include "catch_enforce.h"
  9. #include "catch_stringref.h"
  10. namespace Catch {
  11. Config::Config( ConfigData const& data )
  12. : m_data( data ),
  13. m_stream( openStream() )
  14. {
  15. // We need to trim filter specs to avoid trouble with superfluous
  16. // whitespace (esp. important for bdd macros, as those are manually
  17. // aligned with whitespace).
  18. for (auto& elem : m_data.testsOrTags) {
  19. elem = trim(elem);
  20. }
  21. for (auto& elem : m_data.sectionsToRun) {
  22. elem = trim(elem);
  23. }
  24. TestSpecParser parser(ITagAliasRegistry::get());
  25. if (!m_data.testsOrTags.empty()) {
  26. m_hasTestFilters = true;
  27. for (auto const& testOrTags : m_data.testsOrTags) {
  28. parser.parse(testOrTags);
  29. }
  30. }
  31. m_testSpec = parser.testSpec();
  32. }
  33. std::string const& Config::getFilename() const {
  34. return m_data.outputFilename ;
  35. }
  36. bool Config::listTests() const { return m_data.listTests; }
  37. bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; }
  38. bool Config::listTags() const { return m_data.listTags; }
  39. bool Config::listReporters() const { return m_data.listReporters; }
  40. std::string Config::getProcessName() const { return m_data.processName; }
  41. std::string const& Config::getReporterName() const { return m_data.reporterName; }
  42. std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; }
  43. std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
  44. TestSpec const& Config::testSpec() const { return m_testSpec; }
  45. bool Config::hasTestFilters() const { return m_hasTestFilters; }
  46. bool Config::showHelp() const { return m_data.showHelp; }
  47. // IConfig interface
  48. bool Config::allowThrows() const { return !m_data.noThrow; }
  49. std::ostream& Config::stream() const { return m_stream->stream(); }
  50. std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
  51. bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
  52. bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); }
  53. bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); }
  54. ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; }
  55. double Config::minDuration() const { return m_data.minDuration; }
  56. RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; }
  57. unsigned int Config::rngSeed() const { return m_data.rngSeed; }
  58. UseColour::YesOrNo Config::useColour() const { return m_data.useColour; }
  59. bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
  60. int Config::abortAfter() const { return m_data.abortAfter; }
  61. bool Config::showInvisibles() const { return m_data.showInvisibles; }
  62. Verbosity Config::verbosity() const { return m_data.verbosity; }
  63. bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; }
  64. int Config::benchmarkSamples() const { return m_data.benchmarkSamples; }
  65. double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; }
  66. unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
  67. std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
  68. IStream const* Config::openStream() {
  69. return Catch::makeStream(m_data.outputFilename);
  70. }
  71. } // end namespace Catch