catch_config.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. #ifndef CATCH_CONFIG_HPP_INCLUDED
  7. #define CATCH_CONFIG_HPP_INCLUDED
  8. #include <catch2/catch_test_spec.hpp>
  9. #include <catch2/interfaces/catch_interfaces_config.hpp>
  10. #include <catch2/internal/catch_unique_ptr.hpp>
  11. #include <catch2/internal/catch_optional.hpp>
  12. #include <catch2/internal/catch_stringref.hpp>
  13. #include <catch2/internal/catch_random_seed_generation.hpp>
  14. #include <catch2/internal/catch_reporter_spec_parser.hpp>
  15. #include <chrono>
  16. #include <map>
  17. #include <string>
  18. #include <vector>
  19. namespace Catch {
  20. class IStream;
  21. /**
  22. * `ReporterSpec` but with the defaults filled in.
  23. *
  24. * Like `ReporterSpec`, the semantics are unchecked.
  25. */
  26. struct ProcessedReporterSpec {
  27. std::string name;
  28. std::string outputFilename;
  29. ColourMode colourMode;
  30. std::map<std::string, std::string> customOptions;
  31. friend bool operator==( ProcessedReporterSpec const& lhs,
  32. ProcessedReporterSpec const& rhs );
  33. friend bool operator!=( ProcessedReporterSpec const& lhs,
  34. ProcessedReporterSpec const& rhs ) {
  35. return !( lhs == rhs );
  36. }
  37. };
  38. struct ConfigData {
  39. bool listTests = false;
  40. bool listTags = false;
  41. bool listReporters = false;
  42. bool listListeners = false;
  43. bool showSuccessfulTests = false;
  44. bool shouldDebugBreak = false;
  45. bool noThrow = false;
  46. bool showHelp = false;
  47. bool showInvisibles = false;
  48. bool filenamesAsTags = false;
  49. bool libIdentify = false;
  50. bool allowZeroTests = false;
  51. int abortAfter = -1;
  52. uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
  53. unsigned int shardCount = 1;
  54. unsigned int shardIndex = 0;
  55. bool skipBenchmarks = false;
  56. bool benchmarkNoAnalysis = false;
  57. unsigned int benchmarkSamples = 100;
  58. double benchmarkConfidenceInterval = 0.95;
  59. unsigned int benchmarkResamples = 100000;
  60. std::chrono::milliseconds::rep benchmarkWarmupTime = 100;
  61. Verbosity verbosity = Verbosity::Normal;
  62. WarnAbout::What warnings = WarnAbout::Nothing;
  63. ShowDurations showDurations = ShowDurations::DefaultForReporter;
  64. double minDuration = -1;
  65. TestRunOrder runOrder = TestRunOrder::Declared;
  66. ColourMode defaultColourMode = ColourMode::PlatformDefault;
  67. WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
  68. std::string defaultOutputFilename;
  69. std::string name;
  70. std::string processName;
  71. std::vector<ReporterSpec> reporterSpecifications;
  72. std::vector<std::string> testsOrTags;
  73. std::vector<std::string> sectionsToRun;
  74. };
  75. class Config : public IConfig {
  76. public:
  77. Config() = default;
  78. Config( ConfigData const& data );
  79. ~Config() override; // = default in the cpp file
  80. bool listTests() const;
  81. bool listTags() const;
  82. bool listReporters() const;
  83. bool listListeners() const;
  84. std::vector<ReporterSpec> const& getReporterSpecs() const;
  85. std::vector<ProcessedReporterSpec> const&
  86. getProcessedReporterSpecs() const;
  87. std::vector<std::string> const& getTestsOrTags() const override;
  88. std::vector<std::string> const& getSectionsToRun() const override;
  89. TestSpec const& testSpec() const override;
  90. bool hasTestFilters() const override;
  91. bool showHelp() const;
  92. // IConfig interface
  93. bool allowThrows() const override;
  94. StringRef name() const override;
  95. bool includeSuccessfulResults() const override;
  96. bool warnAboutMissingAssertions() const override;
  97. bool warnAboutUnmatchedTestSpecs() const override;
  98. bool zeroTestsCountAsSuccess() const override;
  99. ShowDurations showDurations() const override;
  100. double minDuration() const override;
  101. TestRunOrder runOrder() const override;
  102. uint32_t rngSeed() const override;
  103. unsigned int shardCount() const override;
  104. unsigned int shardIndex() const override;
  105. ColourMode defaultColourMode() const override;
  106. bool shouldDebugBreak() const override;
  107. int abortAfter() const override;
  108. bool showInvisibles() const override;
  109. Verbosity verbosity() const override;
  110. bool skipBenchmarks() const override;
  111. bool benchmarkNoAnalysis() const override;
  112. unsigned int benchmarkSamples() const override;
  113. double benchmarkConfidenceInterval() const override;
  114. unsigned int benchmarkResamples() const override;
  115. std::chrono::milliseconds benchmarkWarmupTime() const override;
  116. private:
  117. ConfigData m_data;
  118. std::vector<ProcessedReporterSpec> m_processedReporterSpecs;
  119. TestSpec m_testSpec;
  120. bool m_hasTestFilters = false;
  121. };
  122. } // end namespace Catch
  123. #endif // CATCH_CONFIG_HPP_INCLUDED