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_RUNNERCONFIG_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|
|
|
|
|
2012-08-23 20:08:50 +01:00
|
|
|
#include "catch_test_spec.h"
|
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"
|
2010-11-12 19:55:53 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-01-05 21:04:13 +00:00
|
|
|
#include <iostream>
|
2010-11-12 19:55:53 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
namespace Catch {
|
|
|
|
|
2012-05-31 19:40:26 +01:00
|
|
|
struct Include { enum WhichResults {
|
|
|
|
FailedOnly,
|
|
|
|
SuccessfulResults
|
|
|
|
}; };
|
|
|
|
|
|
|
|
struct List{ enum What {
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
Reports = 1,
|
|
|
|
Tests = 2,
|
|
|
|
All = 3,
|
2012-08-23 20:08:50 +01:00
|
|
|
|
|
|
|
TestNames = 6,
|
|
|
|
|
2012-05-31 19:40:26 +01:00
|
|
|
WhatMask = 0xf,
|
|
|
|
|
|
|
|
AsText = 0x10,
|
2012-08-28 08:20:18 +01:00
|
|
|
AsXml = 0x20,
|
2012-05-31 19:40:26 +01:00
|
|
|
|
|
|
|
AsMask = 0xf0
|
|
|
|
}; };
|
|
|
|
|
2012-06-08 08:22:56 +01:00
|
|
|
struct ConfigData {
|
2012-08-28 08:20:18 +01:00
|
|
|
|
|
|
|
struct WarnAbout { enum What {
|
|
|
|
Nothing = 0x00,
|
|
|
|
NoAssertions = 0x01
|
|
|
|
}; };
|
|
|
|
|
2012-06-08 08:22:56 +01:00
|
|
|
ConfigData()
|
|
|
|
: listSpec( List::None ),
|
|
|
|
shouldDebugBreak( false ),
|
|
|
|
includeWhichResults( Include::FailedOnly ),
|
|
|
|
cutoff( -1 ),
|
2012-08-28 08:20:18 +01:00
|
|
|
allowThrows( true ),
|
|
|
|
warnings( WarnAbout::Nothing )
|
2012-06-08 08:22:56 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
std::string reporter;
|
|
|
|
std::string outputFilename;
|
|
|
|
List::What listSpec;
|
2012-08-23 20:08:50 +01:00
|
|
|
std::vector<TestCaseFilters> filters;
|
2012-06-08 08:22:56 +01:00
|
|
|
bool shouldDebugBreak;
|
|
|
|
std::string stream;
|
|
|
|
Include::WhichResults includeWhichResults;
|
|
|
|
std::string name;
|
|
|
|
int cutoff;
|
|
|
|
bool allowThrows;
|
2012-08-28 08:20:18 +01:00
|
|
|
WarnAbout::What warnings;
|
2012-06-08 08:22:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-20 19:07:42 +01:00
|
|
|
class Config : public IConfig {
|
2010-12-31 22:07:47 +00:00
|
|
|
private:
|
2011-01-01 00:20:14 +00:00
|
|
|
Config( const Config& other );
|
|
|
|
Config& operator = ( const Config& other );
|
2012-08-13 07:46:10 +01:00
|
|
|
virtual void dummy();
|
2010-12-31 22:07:47 +00:00
|
|
|
public:
|
2012-08-13 07:46:10 +01:00
|
|
|
|
2011-01-01 00:20:14 +00:00
|
|
|
Config()
|
2012-06-08 08:22:56 +01:00
|
|
|
: m_streambuf( NULL ),
|
|
|
|
m_os( std::cout.rdbuf() )
|
|
|
|
{}
|
|
|
|
|
|
|
|
Config( const ConfigData& data )
|
|
|
|
: m_data( data ),
|
2011-05-31 18:47:30 +01:00
|
|
|
m_streambuf( NULL ),
|
2012-06-08 08:22:56 +01:00
|
|
|
m_os( std::cout.rdbuf() )
|
2010-11-12 19:55:53 +00:00
|
|
|
{}
|
|
|
|
|
2012-08-13 07:46:10 +01:00
|
|
|
virtual ~Config() {
|
2011-05-31 18:47:30 +01:00
|
|
|
m_os.rdbuf( std::cout.rdbuf() );
|
|
|
|
delete m_streambuf;
|
2011-01-18 09:20:06 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 08:22:56 +01:00
|
|
|
void setFilename( const std::string& filename ) {
|
|
|
|
m_data.outputFilename = filename;
|
2010-11-12 19:55:53 +00:00
|
|
|
}
|
2011-01-18 19:49:00 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
List::What getListSpec( void ) const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return m_data.listSpec;
|
2011-01-18 19:49:00 +00:00
|
|
|
}
|
2011-01-11 19:48:48 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
const std::string& getFilename() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return m_data.outputFilename ;
|
2010-11-12 19:55:53 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
List::What listWhat() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
2011-01-11 19:48:48 +00:00
|
|
|
}
|
2010-11-12 19:55:53 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
List::What listAs() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return static_cast<List::What>( m_data.listSpec & List::AsMask );
|
2011-04-12 08:07:39 +01:00
|
|
|
}
|
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
std::string getName() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return m_data.name;
|
2011-04-12 08:07:39 +01:00
|
|
|
}
|
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
bool shouldDebugBreak() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return m_data.shouldDebugBreak;
|
2010-12-30 18:51:02 +00:00
|
|
|
}
|
2011-01-01 00:18:35 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
virtual std::ostream& stream() const {
|
2011-01-01 00:18:35 +00:00
|
|
|
return m_os;
|
2011-01-18 09:20:06 +00:00
|
|
|
}
|
2011-01-01 00:18:35 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
void setStreamBuf( std::streambuf* buf ) {
|
2011-01-18 09:20:06 +00:00
|
|
|
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
|
2011-01-01 00:18:35 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
void useStream( const std::string& streamName ) {
|
2012-08-08 08:33:54 +01:00
|
|
|
std::streambuf* newBuf = createStreamBuf( streamName );
|
2011-05-31 18:47:30 +01:00
|
|
|
setStreamBuf( newBuf );
|
|
|
|
delete m_streambuf;
|
|
|
|
m_streambuf = newBuf;
|
2012-05-04 07:55:11 +01:00
|
|
|
}
|
2012-09-07 17:52:15 +01:00
|
|
|
|
|
|
|
void addTestSpec( const std::string& testSpec ) {
|
|
|
|
TestCaseFilters filters( testSpec );
|
|
|
|
filters.addFilter( TestCaseFilter( testSpec ) );
|
|
|
|
m_data.filters.push_back( filters );
|
|
|
|
}
|
2011-01-18 09:20:06 +00:00
|
|
|
|
2012-05-15 23:58:23 +01:00
|
|
|
virtual bool includeSuccessfulResults() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return m_data.includeWhichResults == Include::SuccessfulResults;
|
2011-01-01 00:18:35 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 19:40:27 +01:00
|
|
|
int getCutoff() const {
|
2012-06-08 08:22:56 +01:00
|
|
|
return m_data.cutoff;
|
2012-06-01 19:40:27 +01:00
|
|
|
}
|
|
|
|
|
2012-06-08 08:22:56 +01:00
|
|
|
virtual bool allowThrows() const {
|
|
|
|
return m_data.allowThrows;
|
2012-06-05 20:50:47 +01:00
|
|
|
}
|
|
|
|
|
2012-08-31 08:10:36 +01:00
|
|
|
const ConfigData& data() const {
|
|
|
|
return m_data;
|
|
|
|
}
|
2012-06-08 08:22:56 +01:00
|
|
|
ConfigData& data() {
|
|
|
|
return m_data;
|
2012-06-05 20:50:47 +01:00
|
|
|
}
|
2012-08-31 08:10:36 +01:00
|
|
|
|
2011-01-18 19:49:00 +00:00
|
|
|
private:
|
2012-06-08 08:22:56 +01:00
|
|
|
ConfigData m_data;
|
|
|
|
|
|
|
|
// !TBD Move these out of here
|
2011-01-18 09:20:06 +00:00
|
|
|
std::streambuf* m_streambuf;
|
2011-01-01 00:18:35 +00:00
|
|
|
mutable std::ostream m_os;
|
2012-05-31 19:40:26 +01:00
|
|
|
};
|
2012-06-08 08:22:56 +01:00
|
|
|
|
2012-05-31 19:40:26 +01:00
|
|
|
|
2010-11-12 19:55:53 +00:00
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|