163088a11f
Also added a set of unit tests for them (incomplete)
198 lines
5.3 KiB
C++
198 lines
5.3 KiB
C++
/*
|
|
* 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
|
|
|
|
#include "catch_interfaces_reporter.h"
|
|
#include "catch_context.h"
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <iostream>
|
|
|
|
namespace Catch {
|
|
|
|
struct Include { enum WhichResults {
|
|
FailedOnly,
|
|
SuccessfulResults
|
|
}; };
|
|
|
|
struct List{ enum What {
|
|
None = 0,
|
|
|
|
Reports = 1,
|
|
Tests = 2,
|
|
All = 3,
|
|
|
|
WhatMask = 0xf,
|
|
|
|
AsText = 0x10,
|
|
AsXml = 0x11,
|
|
|
|
AsMask = 0xf0
|
|
}; };
|
|
|
|
class Config : public IReporterConfig {
|
|
private:
|
|
Config( const Config& other );
|
|
Config& operator = ( const Config& other );
|
|
public:
|
|
|
|
Config()
|
|
: m_listSpec( List::None ),
|
|
m_shouldDebugBreak( false ),
|
|
m_showHelp( false ),
|
|
m_streambuf( NULL ),
|
|
m_os( std::cout.rdbuf() ),
|
|
m_includeWhichResults( Include::FailedOnly )
|
|
{}
|
|
|
|
~Config() {
|
|
m_os.rdbuf( std::cout.rdbuf() );
|
|
delete m_streambuf;
|
|
}
|
|
|
|
void setReporter( const std::string& reporterName ) {
|
|
if( m_reporter.get() )
|
|
return setError( "Only one reporter may be specified" );
|
|
setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
|
|
}
|
|
|
|
void addTestSpec( const std::string& testSpec ) {
|
|
m_testSpecs.push_back( testSpec );
|
|
}
|
|
|
|
bool testsSpecified() const {
|
|
return !m_testSpecs.empty();
|
|
}
|
|
|
|
const std::vector<std::string>& getTestSpecs() const {
|
|
return m_testSpecs;
|
|
}
|
|
|
|
List::What getListSpec( void ) const {
|
|
return m_listSpec;
|
|
}
|
|
|
|
void setListSpec( List::What listSpec ) {
|
|
m_listSpec = listSpec;
|
|
}
|
|
|
|
void setFilename( const std::string& filename ) {
|
|
m_filename = filename;
|
|
}
|
|
|
|
const std::string& getFilename() const {
|
|
return m_filename;
|
|
}
|
|
|
|
const std::string& getMessage() const {
|
|
return m_message;
|
|
}
|
|
|
|
void setError( const std::string& errorMessage ) {
|
|
m_message = errorMessage;
|
|
}
|
|
|
|
void setReporter( IReporter* reporter ) {
|
|
m_reporter = reporter;
|
|
}
|
|
|
|
Ptr<IReporter> getReporter() {
|
|
if( !m_reporter.get() )
|
|
const_cast<Config*>( this )->setReporter( getCurrentContext().getReporterRegistry().create( "basic", *this ) );
|
|
return m_reporter;
|
|
}
|
|
|
|
List::What listWhat() const {
|
|
return static_cast<List::What>( m_listSpec & List::WhatMask );
|
|
}
|
|
|
|
List::What listAs() const {
|
|
return static_cast<List::What>( m_listSpec & List::AsMask );
|
|
}
|
|
|
|
void setIncludeWhichResults( Include::WhichResults includeWhichResults ) {
|
|
m_includeWhichResults = includeWhichResults;
|
|
}
|
|
|
|
void setShouldDebugBreak( bool shouldDebugBreakFlag ) {
|
|
m_shouldDebugBreak = shouldDebugBreakFlag;
|
|
}
|
|
|
|
void setName( const std::string& name ) {
|
|
m_name = name;
|
|
}
|
|
|
|
std::string getName() const {
|
|
return m_name;
|
|
}
|
|
|
|
bool shouldDebugBreak() const {
|
|
return m_shouldDebugBreak;
|
|
}
|
|
|
|
void setShowHelp( bool showHelpFlag ) {
|
|
m_showHelp = showHelpFlag;
|
|
}
|
|
|
|
bool showHelp() const {
|
|
return m_showHelp;
|
|
}
|
|
|
|
virtual std::ostream& stream() const {
|
|
return m_os;
|
|
}
|
|
|
|
void setStreamBuf( std::streambuf* buf ) {
|
|
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
|
|
}
|
|
|
|
void useStream( const std::string& streamName ) {
|
|
std::streambuf* newBuf = Context::createStreamBuf( streamName );
|
|
setStreamBuf( newBuf );
|
|
delete m_streambuf;
|
|
m_streambuf = newBuf;
|
|
}
|
|
|
|
virtual bool includeSuccessfulResults() const {
|
|
return m_includeWhichResults == Include::SuccessfulResults;
|
|
}
|
|
|
|
private:
|
|
Ptr<IReporter> m_reporter;
|
|
std::string m_filename;
|
|
std::string m_message;
|
|
List::What m_listSpec;
|
|
std::vector<std::string> m_testSpecs;
|
|
bool m_shouldDebugBreak;
|
|
bool m_showHelp;
|
|
std::streambuf* m_streambuf;
|
|
mutable std::ostream m_os;
|
|
Include::WhichResults m_includeWhichResults;
|
|
std::string m_name;
|
|
};
|
|
|
|
struct NewConfig {
|
|
std::string reporter;
|
|
std::string outputFilename;
|
|
List::What listSpec;
|
|
std::vector<std::string> testSpecs;
|
|
bool shouldDebugBreak;
|
|
bool showHelp;
|
|
Include::WhichResults includeWhichResults;
|
|
std::string name;
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|