catch2/include/internal/catch_config.hpp

162 lines
5.1 KiB
C++
Raw Normal View History

/*
* 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
2014-05-16 19:24:07 +02:00
#include "catch_test_spec_parser.hpp"
#include "catch_context.h"
#include "catch_interfaces_config.h"
#include "catch_stream.h"
#include <memory>
#include <vector>
#include <string>
2011-01-05 22:04:13 +01:00
#include <iostream>
#include <ctime>
#ifndef CATCH_CONFIG_CONSOLE_WIDTH
#define CATCH_CONFIG_CONSOLE_WIDTH 80
#endif
2012-05-16 00:58:23 +02:00
namespace Catch {
2012-06-08 09:22:56 +02:00
struct ConfigData {
2012-06-08 09:22:56 +02:00
ConfigData()
: listTests( false ),
listTags( false ),
listReporters( false ),
listTestNamesOnly( false ),
2013-05-29 19:34:11 +02:00
showSuccessfulTests( false ),
shouldDebugBreak( false ),
2013-05-29 19:34:11 +02:00
noThrow( false ),
showHelp( false ),
showInvisibles( false ),
forceColour( false ),
2015-07-02 09:20:18 +02:00
filenamesAsTags( false ),
abortAfter( -1 ),
rngSeed( 0 ),
verbosity( Verbosity::Normal ),
warnings( WarnAbout::Nothing ),
showDurations( ShowDurations::DefaultForReporter ),
runOrder( RunTests::InDeclarationOrder )
2012-06-08 09:22:56 +02:00
{}
bool listTests;
bool listTags;
bool listReporters;
bool listTestNamesOnly;
2013-05-29 19:34:11 +02:00
bool showSuccessfulTests;
2012-06-08 09:22:56 +02:00
bool shouldDebugBreak;
2013-05-29 19:34:11 +02:00
bool noThrow;
bool showHelp;
bool showInvisibles;
bool forceColour;
2015-07-02 09:20:18 +02:00
bool filenamesAsTags;
int abortAfter;
unsigned int rngSeed;
Verbosity::Level verbosity;
WarnAbout::What warnings;
ShowDurations::OrNot showDurations;
RunTests::InWhatOrder runOrder;
std::string outputFilename;
std::string name;
std::string processName;
std::vector<std::string> reporterNames;
std::vector<std::string> testsOrTags;
2012-06-08 09:22:56 +02:00
};
class Config : public SharedImpl<IConfig> {
private:
Config( Config const& other );
Config& operator = ( Config const& other );
virtual void dummy();
public:
Config()
2012-06-08 09:22:56 +02:00
{}
Config( ConfigData const& data )
2012-06-08 09:22:56 +02:00
: m_data( data ),
m_stream( openStream() )
{
if( !data.testsOrTags.empty() ) {
2014-06-30 08:33:17 +02:00
TestSpecParser parser( ITagAliasRegistry::get() );
2014-05-16 19:24:07 +02:00
for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
parser.parse( data.testsOrTags[i] );
m_testSpec = parser.testSpec();
}
}
virtual ~Config() {
}
std::string const& getFilename() const {
2012-06-08 09:22:56 +02:00
return m_data.outputFilename ;
}
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; }
2014-05-16 19:24:07 +02:00
std::string getProcessName() const { return m_data.processName; }
2014-05-16 19:24:07 +02:00
bool shouldDebugBreak() const { return m_data.shouldDebugBreak; }
std::vector<std::string> getReporterNames() const { return m_data.reporterNames; }
2014-05-16 19:24:07 +02:00
int abortAfter() const { return m_data.abortAfter; }
2014-05-16 19:24:07 +02:00
TestSpec const& testSpec() const { return m_testSpec; }
2013-06-04 23:49:14 +02:00
bool showHelp() const { return m_data.showHelp; }
bool showInvisibles() const { return m_data.showInvisibles; }
// IConfig interface
2013-05-29 19:34:11 +02:00
virtual bool allowThrows() const { return !m_data.noThrow; }
virtual std::ostream& stream() const { return m_stream->stream(); }
virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
2013-05-29 19:34:11 +02:00
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; }
virtual unsigned int rngSeed() const { return m_data.rngSeed; }
virtual bool forceColour() const { return m_data.forceColour; }
2011-01-18 20:49:00 +01:00
private:
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
throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
}
else
return new FileStream( m_data.outputFilename );
}
2012-06-08 09:22:56 +02:00
ConfigData m_data;
std::auto_ptr<IStream const> m_stream;
2014-05-16 19:24:07 +02:00
TestSpec m_testSpec;
};
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED