catch2/include/internal/catch_config.hpp

164 lines
4.5 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
2012-08-23 21:08:50 +02:00
#include "catch_test_spec.h"
#include "catch_context.h"
#include "catch_interfaces_config.h"
2012-09-26 19:36:58 +02:00
#include "catch_stream.hpp"
#include <memory>
#include <vector>
#include <string>
2011-01-05 22:04:13 +01:00
#include <iostream>
#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 {
struct Verbosity { enum Level {
NoOutput = 0,
Quiet,
Normal
}; };
struct WarnAbout { enum What {
Nothing = 0x00,
NoAssertions = 0x01
}; };
2012-06-08 09:22:56 +02:00
ConfigData()
: listTests( false ),
listTags( false ),
listReporters( false ),
2013-05-29 19:34:11 +02:00
showSuccessfulTests( false ),
shouldDebugBreak( false ),
2013-05-29 19:34:11 +02:00
noThrow( false ),
cutoff( -1 ),
warnings( WarnAbout::Nothing )
2012-06-08 09:22:56 +02:00
{}
bool listTests;
bool listTags;
bool listReporters;
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; // !TBD
2012-06-08 09:22:56 +02:00
int cutoff;
// Verbosity::Level verbosity;
WarnAbout::What warnings;
std::string reporter;
std::string outputFilename;
std::string name;
std::vector<TestCaseFilters> filters; // !TBD strings
std::string stream;
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-09-26 19:36:58 +02:00
: m_os( std::cout.rdbuf() )
2012-06-08 09:22:56 +02:00
{}
Config( ConfigData const& data )
2012-06-08 09:22:56 +02:00
: m_data( data ),
m_os( std::cout.rdbuf() ),
m_filters( data.filters )
{}
virtual ~Config() {
m_os.rdbuf( std::cout.rdbuf() );
2012-09-26 19:36:58 +02:00
m_stream.release();
}
void setFilename( std::string const& filename ) {
2012-06-08 09:22:56 +02:00
m_data.outputFilename = filename;
}
2011-01-18 20:49:00 +01:00
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 listTags() const { return m_data.listTags; }
bool listReporters() const { return m_data.listReporters; }
2012-05-16 00:58:23 +02:00
std::string getName() const {
2012-06-08 09:22:56 +02:00
return m_data.name;
}
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
}
2012-05-16 00:58:23 +02:00
void setStreamBuf( std::streambuf* buf ) {
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
}
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;
}
std::string getStreamName() const { return m_data.stream; }
std::string getReporterName() const { return m_data.reporter; }
void addTestSpec( std::string const& testSpec ) {
TestCaseFilters filters( testSpec );
filters.addFilter( TestCaseFilter( testSpec ) );
m_data.filters.push_back( filters );
}
int abortAfter() const {
2012-06-08 09:22:56 +02:00
return m_data.cutoff;
}
std::vector<TestCaseFilters> const& filters() const {
return m_filters;
}
// 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_os; }
virtual std::string name() const { return 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 & 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;
mutable std::ostream m_os;
std::vector<TestCaseFilters> m_filters;
};
2012-06-08 09:22:56 +02:00
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED