2010-11-12 20:55:53 +01:00
|
|
|
/*
|
2011-01-01 01:29:58 +01:00
|
|
|
* catch_config.hpp
|
2010-11-12 20:55:53 +01:00
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2010-12-31 23:46:51 +01:00
|
|
|
#include "catch_interfaces_reporter.h"
|
2011-01-05 22:04:13 +01:00
|
|
|
#include "catch_hub.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>
|
2010-11-12 20:55:53 +01:00
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
2011-01-18 10:20:06 +01:00
|
|
|
|
2011-01-01 01:20:14 +01:00
|
|
|
class Config : public IReporterConfig
|
2010-12-31 23:07:47 +01:00
|
|
|
{
|
|
|
|
private:
|
2011-01-01 01:20:14 +01:00
|
|
|
Config( const Config& other );
|
|
|
|
Config& operator = ( const Config& other );
|
2010-12-31 23:07:47 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
struct Include { enum What
|
|
|
|
{
|
2011-01-01 01:18:35 +01:00
|
|
|
FailedOnly,
|
|
|
|
SuccessfulResults
|
|
|
|
}; };
|
2010-12-31 23:07:47 +01:00
|
|
|
|
2011-01-01 01:37:49 +01:00
|
|
|
struct List{ enum What
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
2011-01-01 01:37:49 +01:00
|
|
|
None = 0,
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2011-01-01 01:37:49 +01:00
|
|
|
Reports = 1,
|
|
|
|
Tests = 2,
|
|
|
|
All = 3,
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2011-01-01 01:37:49 +01:00
|
|
|
WhatMask = 0xf,
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2011-01-01 01:37:49 +01:00
|
|
|
AsText = 0x10,
|
|
|
|
AsXml = 0x11,
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2011-01-01 01:37:49 +01:00
|
|
|
AsMask = 0xf0
|
|
|
|
}; };
|
2010-11-12 20:55:53 +01:00
|
|
|
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-01 01:20:14 +01:00
|
|
|
Config()
|
2010-12-28 15:17:27 +01:00
|
|
|
: m_reporter( NULL ),
|
2011-01-01 01:37:49 +01:00
|
|
|
m_listSpec( List::None ),
|
2010-12-30 19:51:02 +01:00
|
|
|
m_shouldDebugBreak( false ),
|
2011-01-01 01:18:35 +01:00
|
|
|
m_showHelp( false ),
|
2011-01-18 10:20:06 +01:00
|
|
|
m_streambuf( std::cout.rdbuf() ),
|
|
|
|
m_os( m_streambuf ),
|
2011-01-01 01:18:35 +01:00
|
|
|
m_includeWhat( Include::FailedOnly )
|
2010-11-12 20:55:53 +01:00
|
|
|
{}
|
|
|
|
|
2011-01-18 10:20:06 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
~Config()
|
|
|
|
{
|
|
|
|
setStreamBuf( NULL );
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-05 22:07:20 +01:00
|
|
|
void setReporter( const std::string& reporterName )
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
|
|
|
if( m_reporter.get() )
|
|
|
|
return setError( "Only one reporter may be specified" );
|
2011-01-01 01:18:35 +01:00
|
|
|
setReporter( Hub::getReporterRegistry().create( reporterName, *this ) );
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-11-12 20:55:53 +01:00
|
|
|
void addTestSpec( const std::string& testSpec )
|
|
|
|
{
|
|
|
|
m_testSpecs.push_back( testSpec );
|
|
|
|
}
|
2011-01-18 20:49:00 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
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;
|
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-01 01:37:49 +01:00
|
|
|
void setListSpec( List::What listSpec )
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
|
|
|
m_listSpec = listSpec;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-11-12 20:55:53 +01:00
|
|
|
void setFilename( const std::string& filename )
|
|
|
|
{
|
|
|
|
m_filename = filename;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 20:49:00 +01:00
|
|
|
const std::string& getFilename() const
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
2011-01-18 20:49:00 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
const std::string& getMessage() const
|
|
|
|
{
|
|
|
|
return m_message;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-11-12 20:55:53 +01:00
|
|
|
void setError( const std::string& errorMessage )
|
|
|
|
{
|
|
|
|
m_message = errorMessage + "\n\n" + "Usage: ...";
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-12-31 23:07:47 +01:00
|
|
|
void setReporter( IReporter* reporter )
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
2010-12-31 23:07:47 +01:00
|
|
|
m_reporter = std::auto_ptr<IReporter>( reporter );
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-18 20:49:00 +01:00
|
|
|
IReporter* getReporter() const
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
|
|
|
if( !m_reporter.get() )
|
2011-01-18 20:49:00 +01:00
|
|
|
const_cast<Config*>( this )->setReporter( Hub::getReporterRegistry().create( "basic", *this ) );
|
2010-11-12 20:55:53 +01:00
|
|
|
return m_reporter.get();
|
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-01 01:37:49 +01:00
|
|
|
List::What listWhat() const
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
2011-01-31 11:10:20 +01:00
|
|
|
return static_cast<List::What>( m_listSpec & List::WhatMask );
|
2011-01-11 20:48:48 +01:00
|
|
|
}
|
2010-11-12 20:55:53 +01:00
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-01 01:37:49 +01:00
|
|
|
List::What listAs() const
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
2011-01-31 11:10:20 +01:00
|
|
|
return static_cast<List::What>( m_listSpec & List::AsMask );
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-01 01:18:35 +01:00
|
|
|
void setIncludeWhat( Include::What includeWhat )
|
2010-11-12 20:55:53 +01:00
|
|
|
{
|
2011-01-01 01:18:35 +01:00
|
|
|
m_includeWhat = includeWhat;
|
2010-11-12 20:55:53 +01:00
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-31 11:10:20 +01:00
|
|
|
void setShouldDebugBreak( bool shouldDebugBreakFlag )
|
2010-12-27 21:49:19 +01:00
|
|
|
{
|
2011-01-31 11:10:20 +01:00
|
|
|
m_shouldDebugBreak = shouldDebugBreakFlag;
|
2010-12-27 21:49:19 +01:00
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
2011-04-12 09:07:39 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
void setName( const std::string& name )
|
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
std::string getName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-12-27 21:49:19 +01:00
|
|
|
bool shouldDebugBreak() const
|
|
|
|
{
|
|
|
|
return m_shouldDebugBreak;
|
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-31 11:10:20 +01:00
|
|
|
void setShowHelp( bool showHelpFlag )
|
2010-12-30 19:51:02 +01:00
|
|
|
{
|
2011-01-31 11:10:20 +01:00
|
|
|
m_showHelp = showHelpFlag;
|
2010-12-30 19:51:02 +01:00
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-12-30 19:51:02 +01:00
|
|
|
bool showHelp() const
|
|
|
|
{
|
|
|
|
return m_showHelp;
|
|
|
|
}
|
2011-01-01 01:18:35 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual std::ostream& stream() const
|
|
|
|
{
|
|
|
|
return m_os;
|
2011-01-18 10:20:06 +01:00
|
|
|
}
|
2011-01-01 01:18:35 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
void setStreamBuf( std::streambuf* buf )
|
|
|
|
{
|
2011-01-18 10:20:06 +01:00
|
|
|
// Delete previous stream buf if we own it
|
|
|
|
if( m_streambuf && dynamic_cast<StreamBufBase*>( m_streambuf ) )
|
|
|
|
delete m_streambuf;
|
|
|
|
|
|
|
|
m_streambuf = buf;
|
|
|
|
m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
|
2011-01-01 01:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-01-18 10:20:06 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
void useStream( const std::string& streamName )
|
|
|
|
{
|
|
|
|
setStreamBuf( Hub::createStreamBuf( streamName ) );
|
|
|
|
}
|
|
|
|
|
2011-01-01 01:18:35 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual bool includeSuccessfulResults() const
|
|
|
|
{
|
|
|
|
return m_includeWhat == Include::SuccessfulResults;
|
|
|
|
}
|
|
|
|
|
2011-01-18 20:49:00 +01:00
|
|
|
private:
|
2010-12-31 23:07:47 +01:00
|
|
|
std::auto_ptr<IReporter> m_reporter;
|
2010-11-12 20:55:53 +01:00
|
|
|
std::string m_filename;
|
|
|
|
std::string m_message;
|
2011-01-01 01:37:49 +01:00
|
|
|
List::What m_listSpec;
|
2010-11-12 20:55:53 +01:00
|
|
|
std::vector<std::string> m_testSpecs;
|
2010-12-27 21:49:19 +01:00
|
|
|
bool m_shouldDebugBreak;
|
2010-12-30 19:51:02 +01:00
|
|
|
bool m_showHelp;
|
2011-01-18 10:20:06 +01:00
|
|
|
std::streambuf* m_streambuf;
|
2011-01-01 01:18:35 +01:00
|
|
|
mutable std::ostream m_os;
|
2011-04-12 09:07:39 +02:00
|
|
|
Include::What m_includeWhat;
|
|
|
|
std::string m_name;
|
|
|
|
|
2010-11-12 20:55:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED
|