Reformatting

This commit is contained in:
Phil Nash
2012-05-16 15:02:51 +01:00
parent 0afa09f7c1
commit ee18b8c507
6 changed files with 65 additions and 191 deletions

View File

@@ -1,55 +1,44 @@
/*
* main.cpp
* Catch - Test
*
* Created by Phil on 22/10/2010.
* Copyright 2010 Two Blue Cubes Ltd
*
* 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)
*
*/
#include "catch_self_test.hpp"
TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results" )
{
TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results" ) {
using namespace Catch;
///////////////////////////////////////////////////////////////////////////
SECTION( "selftest/expected result",
"Tests do what they claim" )
{
"Tests do what they claim" ) {
SECTION( "selftest/expected result/failing tests",
"Tests in the 'failing' branch fail" )
{
"Tests in the 'failing' branch fail" ) {
MetaTestRunner::runMatching( "./failing/*", MetaTestRunner::Expected::ToFail );
}
SECTION( "selftest/expected result/succeeding tests",
"Tests in the 'succeeding' branch succeed" )
{
"Tests in the 'succeeding' branch succeed" ) {
MetaTestRunner::runMatching( "./succeeding/*", MetaTestRunner::Expected::ToSucceed );
}
}
///////////////////////////////////////////////////////////////////////////
SECTION( "selftest/test counts",
"Number of test cases that run is fixed" )
{
"Number of test cases that run is fixed" ) {
EmbeddedRunner runner;
SECTION( "selftest/test counts/succeeding tests",
"Number of 'succeeding' tests is fixed" )
{
"Number of 'succeeding' tests is fixed" ) {
runner.runMatching( "./succeeding/*" );
CHECK( runner.getTotals().assertions.passed == 276 );
CHECK( runner.getTotals().assertions.failed == 0 );
}
SECTION( "selftest/test counts/failing tests",
"Number of 'failing' tests is fixed" )
{
"Number of 'failing' tests is fixed" ) {
runner.runMatching( "./failing/*" );
CHECK( runner.getTotals().assertions.passed == 0 );
CHECK( runner.getTotals().assertions.failed == 71 );
@@ -57,12 +46,10 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
}
}
TEST_CASE( "meta/Misc/Sections", "looped tests" )
{
TEST_CASE( "meta/Misc/Sections", "looped tests" ) {
Catch::EmbeddedRunner runner;
runner.runMatching( "./mixed/Misc/Sections/nested2" );
CHECK( runner.getTotals().assertions.passed == 2 );
CHECK( runner.getTotals().assertions.failed == 1 );
}

View File

@@ -15,10 +15,7 @@
namespace Catch{
std::size_t EmbeddedRunner::runMatching(
const std::string& rawTestSpec,
const std::string& reporter )
{
std::size_t EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& reporter ) {
std::ostringstream oss;
Config config;
config.setStreamBuf( oss.rdbuf() );
@@ -38,17 +35,11 @@ namespace Catch{
return result;
}
void MockReporter::Result
(
const ResultInfo& resultInfo
)
{
void MockReporter::Result( const ResultInfo& resultInfo ) {
if( resultInfo.getResultType() == ResultWas::Ok )
return;
switch( resultInfo.getResultType() )
{
switch( resultInfo.getResultType() ) {
case ResultWas::Info:
m_log << "Info";
break;
@@ -96,10 +87,8 @@ namespace Catch{
m_log << resultInfo.getExpandedExpression();
}
void MockReporter::openLabel( const std::string& label, const std::string& arg )
{
if( shouldRecord( label ) )
{
void MockReporter::openLabel( const std::string& label, const std::string& arg ) {
if( shouldRecord( label ) ) {
m_log << m_indent << "\\" << label;
if( !arg.empty() )
m_log << " " << arg;
@@ -108,10 +97,8 @@ namespace Catch{
}
}
void MockReporter::closeLabel( const std::string& label, const std::string& arg )
{
if( shouldRecord( label ) )
{
void MockReporter::closeLabel( const std::string& label, const std::string& arg ) {
if( shouldRecord( label ) ) {
m_indent = m_indent.substr( 0, m_indent.size()-1 );
m_log << m_indent << "/" << label;
if( !arg.empty() )

View File

@@ -1,13 +1,9 @@
/*
* catch_self_test.hpp
* Catch
*
* Created by Phil on 14/01/2011.
* Copyright 2011 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_SELF_TEST_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_SELF_TEST_HPP_INCLUDED
@@ -16,8 +12,8 @@
#include "set"
namespace Catch
{
namespace Catch {
class MockReporter : public SharedImpl<IReporter> {
public:
@@ -105,44 +101,27 @@ namespace Catch
std::set<std::string> m_recorders;
};
class EmbeddedRunner
{
class EmbeddedRunner {
public:
///////////////////////////////////////////////////////////////////////////
EmbeddedRunner
()
: m_reporter( new MockReporter() )
{
}
EmbeddedRunner() : m_reporter( new MockReporter() ) {}
std::size_t runMatching
( const std::string& rawTestSpec,
const std::string& reporter = "basic" );
std::size_t runMatching( const std::string& rawTestSpec,
const std::string& reporter = "basic" );
///////////////////////////////////////////////////////////////////////////
std::string getOutput
()
{
std::string getOutput() {
return m_output;
}
///////////////////////////////////////////////////////////////////////////
const Totals& getTotals
()
const
{
const Totals& getTotals() const {
return m_totals;
}
///////////////////////////////////////////////////////////////////////////
void addRecorder( const std::string& recorder )
{
void addRecorder( const std::string& recorder ) {
m_reporter->addRecorder( recorder );
}
///////////////////////////////////////////////////////////////////////////
std::string getLog() const
{
std::string getLog() const {
return m_reporter->getLog();
}
@@ -152,52 +131,29 @@ namespace Catch
Ptr<MockReporter> m_reporter;
};
class MetaTestRunner
{
class MetaTestRunner {
public:
struct Expected
{
enum Result
{
ToSucceed,
ToFail
};
};
struct Expected { enum Result {
ToSucceed,
ToFail
}; };
///////////////////////////////////////////////////////////////////////////
MetaTestRunner
(
Expected::Result expectedResult
)
: m_expectedResult( expectedResult )
{
}
MetaTestRunner( Expected::Result expectedResult ) : m_expectedResult( expectedResult ) {}
///////////////////////////////////////////////////////////////////////////
static void runMatching
(
const std::string& testSpec,
Expected::Result expectedResult
)
{
static void runMatching( const std::string& testSpec,
Expected::Result expectedResult ) {
forEach( Context::getTestCaseRegistry().getMatchingTestCases( testSpec ),
MetaTestRunner( expectedResult ) );
}
///////////////////////////////////////////////////////////////////////////
void operator()
(
const TestCaseInfo& testCase
)
{
void operator()( const TestCaseInfo& testCase ) {
EmbeddedRunner runner;
runner.runMatching( testCase.getName() );
Totals totals = runner.getTotals();
switch( m_expectedResult )
{
switch( m_expectedResult ) {
case Expected::ToSucceed:
if( totals.assertions.failed > 0 )
{
if( totals.assertions.failed > 0 ) {
INFO( runner.getOutput() );
FAIL( "Expected test case '"
<< testCase.getName()
@@ -206,8 +162,7 @@ namespace Catch
}
break;
case Expected::ToFail:
if( totals.assertions.passed > 0 )
{
if( totals.assertions.passed > 0 ) {
INFO( runner.getOutput() );
FAIL( "Expected test case '"
<< testCase.getName()
@@ -223,32 +178,24 @@ namespace Catch
};
struct LineInfoRegistry
{
static LineInfoRegistry& get
()
{
struct LineInfoRegistry {
static LineInfoRegistry& get() {
static LineInfoRegistry s_instance;
return s_instance;
}
void registerLineInfo
(
const std::string& name,
const SourceLineInfo& info
)
{
void registerLineInfo( const std::string& name,
const SourceLineInfo& info ) {
m_registry.insert( std::make_pair( name, info ) );
}
const SourceLineInfo* find( const std::string& name ) const
{
const SourceLineInfo* find( const std::string& name ) const {
std::map<std::string, SourceLineInfo>::const_iterator it = m_registry.find( name );
return it == m_registry.end() ? NULL : &(it->second);
}
const std::string infoForName( const std::string& name ) const
{
const std::string infoForName( const std::string& name ) const {
std::map<std::string, SourceLineInfo>::const_iterator it = m_registry.find( name );
if( it == m_registry.end() )
return "";
@@ -260,10 +207,8 @@ namespace Catch
std::map<std::string, SourceLineInfo> m_registry;
};
struct LineInfoRegistrar
{
LineInfoRegistrar( const char* name, const SourceLineInfo& lineInfo )
{
struct LineInfoRegistrar {
LineInfoRegistrar( const char* name, const SourceLineInfo& lineInfo ) {
LineInfoRegistry::get().registerLineInfo( name, lineInfo );
}
};