Files
Catch2/include/internal/catch_config.hpp
T

135 lines
4.8 KiB
C++
Raw Normal View History

2010-11-12 19:55:53 +00:00
/*
* Created by Phil on 08/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
2010-11-12 19:55:53 +00:00
2014-05-16 18:24:07 +01:00
#include "catch_test_spec_parser.hpp"
2012-05-10 07:58:48 +01:00
#include "catch_context.h"
2012-08-28 08:20:18 +01:00
#include "catch_interfaces_config.h"
#include "catch_stream.h"
2010-11-12 19:55:53 +00:00
#include <memory>
#include <vector>
#include <string>
#include <stdexcept>
2010-11-12 19:55:53 +00:00
#ifndef CATCH_CONFIG_CONSOLE_WIDTH
#define CATCH_CONFIG_CONSOLE_WIDTH 80
#endif
2012-05-15 23:58:23 +01:00
namespace Catch {
2013-07-03 19:14:59 +01:00
2012-06-08 08:22:56 +01:00
struct ConfigData {
bool listTests = false;
bool listTags = false;
bool listReporters = false;
bool listTestNamesOnly = false;
2012-08-28 08:20:18 +01:00
bool showSuccessfulTests = false;
bool shouldDebugBreak = false;
bool noThrow = false;
bool showHelp = false;
bool showInvisibles = false;
bool filenamesAsTags = false;
2013-07-03 19:14:59 +01:00
int abortAfter = -1;
unsigned int rngSeed = 0;
Verbosity::Level verbosity = Verbosity::Normal;
WarnAbout::What warnings = WarnAbout::Nothing;
ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
UseColour::YesOrNo useColour = UseColour::Auto;
2012-06-08 08:22:56 +01:00
std::string outputFilename;
std::string name;
std::string processName;
2015-08-05 19:02:17 +01:00
std::vector<std::string> reporterNames;
std::vector<std::string> testsOrTags;
std::vector<std::string> sectionsToRun;
2012-06-08 08:22:56 +01:00
};
2013-07-03 19:14:59 +01:00
class Config : public IConfig {
virtual void dummy();
public:
Config()
2012-06-08 08:22:56 +01:00
{}
2013-07-03 19:14:59 +01:00
2013-04-23 18:58:56 +01:00
Config( ConfigData const& data )
2012-06-08 08:22:56 +01:00
: m_data( data ),
2015-09-29 19:21:08 +01:00
m_stream( openStream() )
{
if( !data.testsOrTags.empty() ) {
2014-06-30 07:33:17 +01:00
TestSpecParser parser( ITagAliasRegistry::get() );
for( auto const& testOrTags : data.testsOrTags )
parser.parse( testOrTags );
2014-05-16 18:24:07 +01:00
m_testSpec = parser.testSpec();
}
}
2013-07-03 19:14:59 +01:00
virtual ~Config() {}
2013-07-03 19:14:59 +01:00
2013-04-23 18:58:56 +01:00
std::string const& getFilename() const {
2012-06-08 08:22:56 +01:00
return m_data.outputFilename ;
2010-11-12 19:55:53 +00:00
}
2013-07-03 19:14:59 +01:00
bool listTests() const { return m_data.listTests; }
bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
bool listTags() const { return m_data.listTags; }
bool listReporters() const { return m_data.listReporters; }
2013-07-03 19:14:59 +01:00
2014-05-16 18:24:07 +01:00
std::string getProcessName() const { return m_data.processName; }
std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
2017-04-25 12:41:30 +02:00
std::vector<std::string> const& getSectionsToRun() const override { return m_data.sectionsToRun; }
2017-04-25 12:41:30 +02:00
virtual TestSpec const& testSpec() const override { return m_testSpec; }
2013-07-03 19:14:59 +01:00
2013-06-04 22:49:14 +01:00
bool showHelp() const { return m_data.showHelp; }
2013-05-28 18:39:32 +01:00
// IConfig interface
2017-04-25 12:41:30 +02:00
virtual bool allowThrows() const override { return !m_data.noThrow; }
virtual std::ostream& stream() const override { return m_stream->stream(); }
virtual std::string name() const override { return m_data.name.empty() ? m_data.processName : m_data.name; }
virtual bool includeSuccessfulResults() const override { return m_data.showSuccessfulTests; }
virtual bool warnAboutMissingAssertions() const override { return m_data.warnings & WarnAbout::NoAssertions; }
virtual ShowDurations::OrNot showDurations() const override { return m_data.showDurations; }
virtual RunTests::InWhatOrder runOrder() const override { return m_data.runOrder; }
virtual unsigned int rngSeed() const override { return m_data.rngSeed; }
virtual UseColour::YesOrNo useColour() const override { return m_data.useColour; }
virtual bool shouldDebugBreak() const override { return m_data.shouldDebugBreak; }
virtual int abortAfter() const override { return m_data.abortAfter; }
virtual bool showInvisibles() const override { return m_data.showInvisibles; }
2013-05-28 18:39:32 +01:00
2011-01-18 19:49:00 +00:00
private:
2015-09-29 19:21:08 +01:00
IStream const* openStream() {
if( m_data.outputFilename.empty() )
return new CoutStream();
else if( m_data.outputFilename[0] == '%' ) {
if( m_data.outputFilename == "%debug" )
return new DebugOutStream();
else
CATCH_ERROR( "Unrecognised stream: '" << m_data.outputFilename << "'" );
2015-09-29 19:21:08 +01:00
}
else
return new FileStream( m_data.outputFilename );
}
2012-06-08 08:22:56 +01:00
ConfigData m_data;
2013-07-03 19:14:59 +01:00
2017-04-25 12:41:30 +02:00
std::unique_ptr<IStream const> m_stream;
2014-05-16 18:24:07 +01:00
TestSpec m_testSpec;
2010-11-12 19:55:53 +00:00
};
2013-07-03 19:14:59 +01:00
2010-11-12 19:55:53 +00:00
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED