catch2/internal/catch_config.hpp

178 lines
4.5 KiB
C++
Raw Normal View History

/*
2011-01-01 01:29:58 +01:00
* catch_config.hpp
* 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
#include "catch_interfaces_reporter.h"
2011-01-05 22:04:13 +01:00
#include "catch_hub.h"
#include <memory>
#include <vector>
#include <string>
2011-01-05 22:04:13 +01:00
#include <iostream>
namespace Catch
{
class Config : public IReporterConfig
{
private:
Config( const Config& other );
Config& operator = ( const Config& other );
public:
struct Include { enum What
{
FailedOnly,
SuccessfulResults
}; };
2011-01-01 01:37:49 +01:00
struct List{ enum What
{
2011-01-01 01:37:49 +01:00
None = 0,
2011-01-01 01:37:49 +01:00
Reports = 1,
Tests = 2,
All = 3,
2011-01-01 01:37:49 +01:00
WhatMask = 0xf,
2011-01-01 01:37:49 +01:00
AsText = 0x10,
AsXml = 0x11,
2011-01-01 01:37:49 +01:00
AsMask = 0xf0
}; };
Config()
: 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 ),
m_showHelp( false ),
m_os( std::cout.rdbuf() ),
m_includeWhat( Include::FailedOnly )
{}
void setReporter( const std::string& reporterName )
{
if( m_reporter.get() )
return setError( "Only one reporter may be specified" );
setReporter( Hub::getReporterRegistry().create( reporterName, *this ) );
}
void addTestSpec( const std::string& testSpec )
{
m_testSpecs.push_back( testSpec );
}
2011-01-01 01:37:49 +01:00
void setListSpec( List::What listSpec )
{
m_listSpec = listSpec;
}
void setFilename( const std::string& filename )
{
m_filename = filename;
}
std::string getFilename()
{
return m_filename;
}
void setError( const std::string& errorMessage )
{
m_message = errorMessage + "\n\n" + "Usage: ...";
}
void setReporter( IReporter* reporter )
{
m_reporter = std::auto_ptr<IReporter>( reporter );
}
IReporter* getReporter()
{
if( !m_reporter.get() )
setReporter( Hub::getReporterRegistry().create( "basic", *this ) );
return m_reporter.get();
}
IReporter* getReporter() const
{
return const_cast<Config*>( this )->getReporter();
}
2011-01-01 01:37:49 +01:00
List::What listWhat() const
{
2011-01-01 01:37:49 +01:00
return (List::What)( m_listSpec & List::WhatMask );
}
2011-01-01 01:37:49 +01:00
List::What listAs() const
{
2011-01-01 01:37:49 +01:00
return (List::What)( m_listSpec & List::AsMask );
}
void setIncludeWhat( Include::What includeWhat )
{
m_includeWhat = includeWhat;
}
void setShouldDebugBreak( bool shouldDebugBreak )
{
m_shouldDebugBreak = shouldDebugBreak;
}
bool shouldDebugBreak() const
{
return m_shouldDebugBreak;
}
2010-12-30 19:51:02 +01:00
void setShowHelp( bool showHelp )
{
m_showHelp = showHelp;
}
bool showHelp() const
{
return m_showHelp;
}
///////////////////////////////////////////////////////////////////////////
virtual std::ostream& stream() const
{
return m_os;
}
///////////////////////////////////////////////////////////////////////////
void setStreamBuf( std::streambuf* buf )
{
m_os.rdbuf( buf );
}
///////////////////////////////////////////////////////////////////////////
virtual bool includeSuccessfulResults() const
{
return m_includeWhat == Include::SuccessfulResults;
}
2010-12-30 19:51:02 +01:00
std::auto_ptr<IReporter> m_reporter;
std::string m_filename;
std::string m_message;
2011-01-01 01:37:49 +01:00
List::What m_listSpec;
std::vector<std::string> m_testSpecs;
bool m_shouldDebugBreak;
2010-12-30 19:51:02 +01:00
bool m_showHelp;
mutable std::ostream m_os;
Include::What m_includeWhat;
};
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED