1 /* 2 * Created by Phil on 08/11/2010. 3 * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 #ifndef TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED 9 #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED 10 11 #include "catch_test_spec_parser.h" 12 #include "catch_interfaces_config.h" 13 14 // Libstdc++ doesn't like incomplete classes for unique_ptr 15 #include "catch_stream.h" 16 17 #include <memory> 18 #include <vector> 19 #include <string> 20 21 #ifndef CATCH_CONFIG_CONSOLE_WIDTH 22 #define CATCH_CONFIG_CONSOLE_WIDTH 80 23 #endif 24 25 namespace Catch { 26 27 struct IStream; 28 29 struct ConfigData { 30 bool listTests = false; 31 bool listTags = false; 32 bool listReporters = false; 33 bool listTestNamesOnly = false; 34 35 bool showSuccessfulTests = false; 36 bool shouldDebugBreak = false; 37 bool noThrow = false; 38 bool showHelp = false; 39 bool showInvisibles = false; 40 bool filenamesAsTags = false; 41 bool libIdentify = false; 42 43 int abortAfter = -1; 44 unsigned int rngSeed = 0; 45 46 bool benchmarkNoAnalysis = false; 47 unsigned int benchmarkSamples = 100; 48 double benchmarkConfidenceInterval = 0.95; 49 unsigned int benchmarkResamples = 100000; 50 std::chrono::milliseconds::rep benchmarkWarmupTime = 100; 51 52 Verbosity verbosity = Verbosity::Normal; 53 WarnAbout::What warnings = WarnAbout::Nothing; 54 ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; 55 double minDuration = -1; 56 RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; 57 UseColour::YesOrNo useColour = UseColour::Auto; 58 WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; 59 60 std::string outputFilename; 61 std::string name; 62 std::string processName; 63 #ifndef CATCH_CONFIG_DEFAULT_REPORTER 64 #define CATCH_CONFIG_DEFAULT_REPORTER "console" 65 #endif 66 std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER; 67 #undef CATCH_CONFIG_DEFAULT_REPORTER 68 69 std::vector<std::string> testsOrTags; 70 std::vector<std::string> sectionsToRun; 71 }; 72 73 74 class Config : public IConfig { 75 public: 76 77 Config() = default; 78 Config( ConfigData const& data ); 79 virtual ~Config() = default; 80 81 std::string const& getFilename() const; 82 83 bool listTests() const; 84 bool listTestNamesOnly() const; 85 bool listTags() const; 86 bool listReporters() const; 87 88 std::string getProcessName() const; 89 std::string const& getReporterName() const; 90 91 std::vector<std::string> const& getTestsOrTags() const override; 92 std::vector<std::string> const& getSectionsToRun() const override; 93 94 TestSpec const& testSpec() const override; 95 bool hasTestFilters() const override; 96 97 bool showHelp() const; 98 99 // IConfig interface 100 bool allowThrows() const override; 101 std::ostream& stream() const override; 102 std::string name() const override; 103 bool includeSuccessfulResults() const override; 104 bool warnAboutMissingAssertions() const override; 105 bool warnAboutNoTests() const override; 106 ShowDurations::OrNot showDurations() const override; 107 double minDuration() const override; 108 RunTests::InWhatOrder runOrder() const override; 109 unsigned int rngSeed() const override; 110 UseColour::YesOrNo useColour() const override; 111 bool shouldDebugBreak() const override; 112 int abortAfter() const override; 113 bool showInvisibles() const override; 114 Verbosity verbosity() const override; 115 bool benchmarkNoAnalysis() const override; 116 int benchmarkSamples() const override; 117 double benchmarkConfidenceInterval() const override; 118 unsigned int benchmarkResamples() const override; 119 std::chrono::milliseconds benchmarkWarmupTime() const override; 120 121 private: 122 123 IStream const* openStream(); 124 ConfigData m_data; 125 126 std::unique_ptr<IStream const> m_stream; 127 TestSpec m_testSpec; 128 bool m_hasTestFilters = false; 129 }; 130 131 } // end namespace Catch 132 133 #endif // TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED 134