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
|
|
|
|
2012-08-23 21:08:50 +02:00
|
|
|
#include "catch_test_spec.h"
|
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"
|
2012-09-26 19:36:58 +02:00
|
|
|
#include "catch_stream.hpp"
|
2010-11-12 20:55:53 +01:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-01-05 22:04:13 +01:00
|
|
|
#include <iostream>
|
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 {
|
|
|
|
|
2012-05-31 20:40:26 +02:00
|
|
|
struct Include { enum WhichResults {
|
|
|
|
FailedOnly,
|
|
|
|
SuccessfulResults
|
|
|
|
}; };
|
|
|
|
|
|
|
|
struct List{ enum What {
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
Reports = 1,
|
|
|
|
Tests = 2,
|
2013-03-29 12:42:10 +01:00
|
|
|
Tags = 4,
|
|
|
|
All = Reports | Tests | Tags,
|
2012-08-23 21:08:50 +02:00
|
|
|
|
2012-05-31 20:40:26 +02:00
|
|
|
WhatMask = 0xf,
|
|
|
|
|
|
|
|
AsText = 0x10,
|
2012-08-28 09:20:18 +02:00
|
|
|
AsXml = 0x20,
|
2012-05-31 20:40:26 +02:00
|
|
|
|
|
|
|
AsMask = 0xf0
|
|
|
|
}; };
|
|
|
|
|
2012-06-08 09:22:56 +02:00
|
|
|
struct ConfigData {
|
2012-08-28 09:20:18 +02:00
|
|
|
|
|
|
|
struct WarnAbout { enum What {
|
|
|
|
Nothing = 0x00,
|
|
|
|
NoAssertions = 0x01
|
|
|
|
}; };
|
|
|
|
|
2012-06-08 09:22:56 +02:00
|
|
|
ConfigData()
|
|
|
|
: listSpec( List::None ),
|
|
|
|
shouldDebugBreak( false ),
|
|
|
|
includeWhichResults( Include::FailedOnly ),
|
|
|
|
cutoff( -1 ),
|
2012-08-28 09:20:18 +02:00
|
|
|
allowThrows( true ),
|
|
|
|
warnings( WarnAbout::Nothing )
|
2012-06-08 09:22:56 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
std::string reporter;
|
|
|
|
std::string outputFilename;
|
|
|
|
List::What listSpec;
|
2012-08-23 21:08:50 +02:00
|
|
|
std::vector<TestCaseFilters> filters;
|
2012-06-08 09:22:56 +02:00
|
|
|
bool shouldDebugBreak;
|
|
|
|
std::string stream;
|
|
|
|
Include::WhichResults includeWhichResults;
|
|
|
|
std::string name;
|
|
|
|
int cutoff;
|
|
|
|
bool allowThrows;
|
2012-08-28 09:20:18 +02:00
|
|
|
WarnAbout::What warnings;
|
2012-06-08 09:22:56 +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-09-26 19:36:58 +02:00
|
|
|
: m_os( std::cout.rdbuf() )
|
2012-06-08 09:22:56 +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 ),
|
2013-05-28 20:07:29 +02:00
|
|
|
m_os( std::cout.rdbuf() ),
|
|
|
|
m_filters( data.filters )
|
2010-11-12 20:55:53 +01:00
|
|
|
{}
|
|
|
|
|
2012-08-13 08:46:10 +02:00
|
|
|
virtual ~Config() {
|
2011-05-31 19:47:30 +02:00
|
|
|
m_os.rdbuf( std::cout.rdbuf() );
|
2012-09-26 19:36:58 +02:00
|
|
|
m_stream.release();
|
2011-01-18 10:20:06 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 19:58:56 +02:00
|
|
|
void setFilename( std::string const& filename ) {
|
2012-06-08 09:22:56 +02:00
|
|
|
m_data.outputFilename = filename;
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
2011-01-18 20:49:00 +01: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-05-29 08:59:01 +02:00
|
|
|
bool listTests() const { return m_data.listSpec & List::Tests; }
|
|
|
|
bool listTags() const { return m_data.listSpec & List::Tags; }
|
|
|
|
bool listReporters() const { return m_data.listSpec & List::Reports; }
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
std::string getName() const {
|
2012-06-08 09:22:56 +02:00
|
|
|
return m_data.name;
|
2011-04-12 09:07:39 +02:00
|
|
|
}
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
bool shouldDebugBreak() const {
|
2012-06-08 09:22:56 +02:00
|
|
|
return m_data.shouldDebugBreak;
|
2010-12-30 19:51:02 +01:00
|
|
|
}
|
2011-01-01 01:18:35 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
void setStreamBuf( std::streambuf* buf ) {
|
2011-01-18 10:20:06 +01:00
|
|
|
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
|
2011-01-01 01:18:35 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 19:58:56 +02:00
|
|
|
void useStream( std::string const& streamName ) {
|
2012-09-26 19:36:58 +02:00
|
|
|
Stream stream = createStream( streamName );
|
|
|
|
setStreamBuf( stream.streamBuf );
|
|
|
|
m_stream.release();
|
|
|
|
m_stream = stream;
|
2012-05-04 08:55:11 +02:00
|
|
|
}
|
2013-05-28 20:07:29 +02:00
|
|
|
|
|
|
|
std::string getStreamName() const { return m_data.stream; }
|
|
|
|
|
|
|
|
std::string getReporterName() const { return m_data.reporter; }
|
2012-09-07 18:52:15 +02:00
|
|
|
|
2013-04-23 19:58:56 +02:00
|
|
|
void addTestSpec( std::string const& testSpec ) {
|
2012-09-07 18:52:15 +02:00
|
|
|
TestCaseFilters filters( testSpec );
|
|
|
|
filters.addFilter( TestCaseFilter( testSpec ) );
|
|
|
|
m_data.filters.push_back( filters );
|
|
|
|
}
|
2013-05-28 19:39:32 +02:00
|
|
|
|
2013-05-28 19:51:53 +02:00
|
|
|
int abortAfter() const {
|
2012-06-08 09:22:56 +02:00
|
|
|
return m_data.cutoff;
|
2012-06-01 20:40:27 +02:00
|
|
|
}
|
|
|
|
|
2013-05-28 20:07:29 +02:00
|
|
|
std::vector<TestCaseFilters> const& filters() const {
|
|
|
|
return m_filters;
|
2012-06-05 21:50:47 +02:00
|
|
|
}
|
2012-08-31 09:10:36 +02:00
|
|
|
|
2013-05-28 19:39:32 +02:00
|
|
|
// IConfig interface
|
|
|
|
virtual bool allowThrows() const { return m_data.allowThrows; }
|
|
|
|
virtual std::ostream& stream() const { return m_os; }
|
|
|
|
virtual std::string name() const { return m_data.name; }
|
|
|
|
virtual bool includeSuccessfulResults() const { return m_data.includeWhichResults == Include::SuccessfulResults; }
|
|
|
|
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & ConfigData::WarnAbout::NoAssertions; }
|
|
|
|
|
2011-01-18 20:49:00 +01:00
|
|
|
private:
|
2012-06-08 09:22:56 +02:00
|
|
|
ConfigData m_data;
|
|
|
|
|
2012-09-26 19:36:58 +02:00
|
|
|
Stream m_stream;
|
2011-01-01 01:18:35 +01:00
|
|
|
mutable std::ostream m_os;
|
2013-05-28 20:07:29 +02:00
|
|
|
std::vector<TestCaseFilters> m_filters;
|
2012-05-31 20:40:26 +02:00
|
|
|
};
|
2012-06-08 09:22:56 +02:00
|
|
|
|
2012-05-31 20:40:26 +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
|