2010-11-12 20:55:53 +01: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)
|
|
|
|
*/
|
2012-09-17 07:42:29 +02:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2014-05-16 19:24:07 +02:00
|
|
|
#include "catch_test_spec_parser.hpp"
|
2012-05-10 08:58:48 +02:00
|
|
|
#include "catch_context.h"
|
2012-08-28 09:20:18 +02:00
|
|
|
#include "catch_interfaces_config.h"
|
2013-12-03 19:52:41 +01:00
|
|
|
#include "catch_stream.h"
|
2010-11-12 20:55:53 +01:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-01-05 22:04:13 +01:00
|
|
|
#include <iostream>
|
2014-09-15 19:39:31 +02:00
|
|
|
#include <ctime>
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2013-01-26 21:06:55 +01:00
|
|
|
#ifndef CATCH_CONFIG_CONSOLE_WIDTH
|
|
|
|
#define CATCH_CONFIG_CONSOLE_WIDTH 80
|
|
|
|
#endif
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-06-08 09:22:56 +02:00
|
|
|
struct ConfigData {
|
2012-08-28 09:20:18 +02:00
|
|
|
|
2012-06-08 09:22:56 +02:00
|
|
|
ConfigData()
|
2013-05-29 19:42:46 +02:00
|
|
|
: listTests( false ),
|
|
|
|
listTags( false ),
|
|
|
|
listReporters( false ),
|
2016-06-05 21:56:50 +02:00
|
|
|
listTestNamesAndSources( false ),
|
2013-11-26 21:57:34 +01:00
|
|
|
listTestNamesOnly( false ),
|
2016-06-13 16:08:25 +02:00
|
|
|
listTestSources( false ),
|
2013-05-29 19:34:11 +02:00
|
|
|
showSuccessfulTests( false ),
|
2013-05-29 09:12:57 +02:00
|
|
|
shouldDebugBreak( false ),
|
2013-05-29 19:34:11 +02:00
|
|
|
noThrow( false ),
|
2013-05-29 20:01:06 +02:00
|
|
|
showHelp( false ),
|
2014-04-22 19:23:42 +02:00
|
|
|
showInvisibles( false ),
|
2015-07-02 09:20:18 +02:00
|
|
|
filenamesAsTags( false ),
|
2013-05-31 09:01:56 +02:00
|
|
|
abortAfter( -1 ),
|
2014-09-15 19:39:31 +02:00
|
|
|
rngSeed( 0 ),
|
2013-05-29 20:01:06 +02:00
|
|
|
verbosity( Verbosity::Normal ),
|
2013-08-07 19:56:35 +02:00
|
|
|
warnings( WarnAbout::Nothing ),
|
2014-09-15 19:39:31 +02:00
|
|
|
showDurations( ShowDurations::DefaultForReporter ),
|
2016-02-24 19:51:01 +01:00
|
|
|
runOrder( RunTests::InDeclarationOrder ),
|
|
|
|
useColour( UseColour::Auto )
|
2012-06-08 09:22:56 +02:00
|
|
|
{}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-05-29 19:42:46 +02:00
|
|
|
bool listTests;
|
|
|
|
bool listTags;
|
|
|
|
bool listReporters;
|
2016-06-05 21:56:50 +02:00
|
|
|
bool listTestNamesAndSources;
|
2016-06-13 16:08:25 +02:00
|
|
|
bool listTestSources;
|
2016-06-05 21:56:50 +02:00
|
|
|
bool listTestNamesOnly;
|
2013-05-29 20:01:06 +02:00
|
|
|
|
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;
|
2013-05-29 20:01:06 +02:00
|
|
|
bool showHelp;
|
2014-04-22 19:23:42 +02:00
|
|
|
bool showInvisibles;
|
2015-07-02 09:20:18 +02:00
|
|
|
bool filenamesAsTags;
|
2013-05-29 09:12:57 +02:00
|
|
|
|
2013-05-31 09:01:56 +02:00
|
|
|
int abortAfter;
|
2014-09-15 19:39:31 +02:00
|
|
|
unsigned int rngSeed;
|
2013-05-29 09:12:57 +02:00
|
|
|
|
2013-05-29 20:01:06 +02:00
|
|
|
Verbosity::Level verbosity;
|
2012-08-28 09:20:18 +02:00
|
|
|
WarnAbout::What warnings;
|
2013-08-07 19:56:35 +02:00
|
|
|
ShowDurations::OrNot showDurations;
|
2014-09-15 19:39:31 +02:00
|
|
|
RunTests::InWhatOrder runOrder;
|
2016-02-24 19:51:01 +01:00
|
|
|
UseColour::YesOrNo useColour;
|
2013-05-29 09:12:57 +02:00
|
|
|
|
|
|
|
std::string outputFilename;
|
|
|
|
std::string name;
|
2013-06-04 09:37:28 +02:00
|
|
|
std::string processName;
|
2013-05-29 09:12:57 +02:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
std::vector<std::string> reporterNames;
|
2013-05-29 19:56:29 +02:00
|
|
|
std::vector<std::string> testsOrTags;
|
2012-06-08 09:22:56 +02:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
|
|
|
|
2013-05-28 19:39:32 +02:00
|
|
|
class Config : public SharedImpl<IConfig> {
|
2010-12-31 23:07:47 +01:00
|
|
|
private:
|
2013-04-23 19:58:56 +02:00
|
|
|
Config( Config const& other );
|
|
|
|
Config& operator = ( Config const& other );
|
2012-08-13 08:46:10 +02:00
|
|
|
virtual void dummy();
|
2010-12-31 23:07:47 +01:00
|
|
|
public:
|
2012-08-13 08:46:10 +02:00
|
|
|
|
2011-01-01 01:20:14 +01:00
|
|
|
Config()
|
2012-06-08 09:22:56 +02:00
|
|
|
{}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-04-23 19:58:56 +02:00
|
|
|
Config( ConfigData const& data )
|
2012-06-08 09:22:56 +02:00
|
|
|
: m_data( data ),
|
2015-09-29 20:21:08 +02:00
|
|
|
m_stream( openStream() )
|
2013-05-29 19:56:29 +02:00
|
|
|
{
|
2013-06-07 20:06:30 +02:00
|
|
|
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();
|
2013-05-29 19:56:29 +02:00
|
|
|
}
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-08-13 08:46:10 +02:00
|
|
|
virtual ~Config() {
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-04-23 19:58:56 +02:00
|
|
|
std::string const& getFilename() const {
|
2012-06-08 09:22:56 +02:00
|
|
|
return m_data.outputFilename ;
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-05-29 19:42:46 +02:00
|
|
|
bool listTests() const { return m_data.listTests; }
|
2016-06-05 21:56:50 +02:00
|
|
|
bool listTestNamesAndSources() const { return m_data.listTestNamesAndSources; }
|
2013-11-26 21:57:34 +01:00
|
|
|
bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
|
2016-06-13 16:08:25 +02:00
|
|
|
bool listTestSources() const { return m_data.listTestSources; }
|
2013-05-29 19:42:46 +02:00
|
|
|
bool listTags() const { return m_data.listTags; }
|
|
|
|
bool listReporters() const { return m_data.listReporters; }
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2014-05-16 19:24:07 +02:00
|
|
|
std::string getProcessName() const { return m_data.processName; }
|
2013-06-05 09:18:52 +02:00
|
|
|
|
2014-05-16 19:24:07 +02:00
|
|
|
bool shouldDebugBreak() const { return m_data.shouldDebugBreak; }
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
std::vector<std::string> getReporterNames() const { return m_data.reporterNames; }
|
2012-09-07 18:52:15 +02:00
|
|
|
|
2014-05-16 19:24:07 +02:00
|
|
|
int abortAfter() const { return m_data.abortAfter; }
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2014-05-16 19:24:07 +02:00
|
|
|
TestSpec const& testSpec() const { return m_testSpec; }
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-06-04 23:49:14 +02:00
|
|
|
bool showHelp() const { return m_data.showHelp; }
|
2014-04-22 19:23:42 +02:00
|
|
|
bool showInvisibles() const { return m_data.showInvisibles; }
|
2012-08-31 09:10:36 +02:00
|
|
|
|
2013-05-28 19:39:32 +02:00
|
|
|
// IConfig interface
|
2013-05-29 19:34:11 +02:00
|
|
|
virtual bool allowThrows() const { return !m_data.noThrow; }
|
2015-09-29 20:21:08 +02:00
|
|
|
virtual std::ostream& stream() const { return m_stream->stream(); }
|
2013-06-05 09:18:52 +02:00
|
|
|
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; }
|
2013-08-07 19:56:35 +02:00
|
|
|
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
|
|
|
|
virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
|
2014-09-15 19:39:31 +02:00
|
|
|
virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; }
|
|
|
|
virtual unsigned int rngSeed() const { return m_data.rngSeed; }
|
2016-02-24 19:51:01 +01:00
|
|
|
virtual UseColour::YesOrNo useColour() const { return m_data.useColour; }
|
2013-05-28 19:39:32 +02:00
|
|
|
|
2011-01-18 20:49:00 +01:00
|
|
|
private:
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2015-09-29 20:21:08 +02: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
|
|
|
|
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;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2015-09-29 20:21:08 +02:00
|
|
|
std::auto_ptr<IStream const> m_stream;
|
2014-05-16 19:24:07 +02:00
|
|
|
TestSpec m_testSpec;
|
2012-05-31 20:40:26 +02:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-12 20:55:53 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|