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         int benchmarkResolutionMultiple = 100;
46 
47         Verbosity verbosity = Verbosity::Normal;
48         WarnAbout::What warnings = WarnAbout::Nothing;
49         ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
50         RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
51         UseColour::YesOrNo useColour = UseColour::Auto;
52         WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
53 
54         std::string outputFilename;
55         std::string name;
56         std::string processName;
57 
58         std::vector<std::string> reporterNames;
59         std::vector<std::string> testsOrTags;
60         std::vector<std::string> sectionsToRun;
61     };
62 
63 
64     class Config : public IConfig {
65     public:
66 
67         Config() = default;
68         Config( ConfigData const& data );
69         virtual ~Config() = default;
70 
71         std::string const& getFilename() const;
72 
73         bool listTests() const;
74         bool listTestNamesOnly() const;
75         bool listTags() const;
76         bool listReporters() const;
77 
78         std::string getProcessName() const;
79 
80         std::vector<std::string> const& getReporterNames() const;
81         std::vector<std::string> const& getTestsOrTags() const;
82         std::vector<std::string> const& getSectionsToRun() const override;
83 
84         virtual TestSpec const& testSpec() const override;
85         bool hasTestFilters() const override;
86 
87         bool showHelp() const;
88 
89         // IConfig interface
90         bool allowThrows() const override;
91         std::ostream& stream() const override;
92         std::string name() const override;
93         bool includeSuccessfulResults() const override;
94         bool warnAboutMissingAssertions() const override;
95         bool warnAboutNoTests() const override;
96         ShowDurations::OrNot showDurations() const override;
97         RunTests::InWhatOrder runOrder() const override;
98         unsigned int rngSeed() const override;
99         int benchmarkResolutionMultiple() const override;
100         UseColour::YesOrNo useColour() const override;
101         bool shouldDebugBreak() const override;
102         int abortAfter() const override;
103         bool showInvisibles() const override;
104         Verbosity verbosity() const override;
105 
106     private:
107 
108         IStream const* openStream();
109         ConfigData m_data;
110 
111         std::unique_ptr<IStream const> m_stream;
112         TestSpec m_testSpec;
113         bool m_hasTestFilters = false;
114     };
115 
116 } // end namespace Catch
117 
118 #endif // TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
119