Remove trailing whitespaces

This commit is contained in:
Michael Vetter 2015-11-02 13:55:21 +01:00
parent d758428fe2
commit 4f2e51cafe
19 changed files with 178 additions and 178 deletions

View File

@ -62,7 +62,7 @@ namespace Catch {
} }
std::vector<TestCase> skippedTestCases; std::vector<TestCase> skippedTestCases;
getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true ); getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true );
for( std::vector<TestCase>::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end(); for( std::vector<TestCase>::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end();
it != itEnd; it != itEnd;
++it ) ++it )

View File

@ -158,7 +158,7 @@ namespace Catch {
.describe( "list all/matching test cases names only" ) .describe( "list all/matching test cases names only" )
.bind( &ConfigData::listTestNamesOnly ); .bind( &ConfigData::listTestNamesOnly );
cli["--list-reporters"] cli["--list-reporters"]
.describe( "list all reporters" ) .describe( "list all reporters" )
.bind( &ConfigData::listReporters ); .bind( &ConfigData::listReporters );

View File

@ -36,7 +36,7 @@ namespace Catch {
return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
} }
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
bool replaced = false; bool replaced = false;
std::size_t i = str.find( replaceThis ); std::size_t i = str.find( replaceThis );
@ -50,7 +50,7 @@ namespace Catch {
} }
return replaced; return replaced;
} }
pluralise::pluralise( std::size_t count, std::string const& label ) pluralise::pluralise( std::size_t count, std::string const& label )
: m_count( count ), : m_count( count ),
m_label( label ) m_label( label )

View File

@ -83,7 +83,7 @@ namespace Catch {
private: private:
static void sortTests( IConfig const& config, std::vector<TestCase>& matchingTestCases ) { static void sortTests( IConfig const& config, std::vector<TestCase>& matchingTestCases ) {
switch( config.runOrder() ) { switch( config.runOrder() ) {
case RunTests::InLexicographicalOrder: case RunTests::InLexicographicalOrder:
std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() ); std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() );

View File

@ -16,9 +16,9 @@ namespace Catch {
namespace SectionTracking { namespace SectionTracking {
class TrackedSection { class TrackedSection {
typedef std::map<std::string, TrackedSection> TrackedSections; typedef std::map<std::string, TrackedSection> TrackedSections;
public: public:
enum RunState { enum RunState {
NotStarted, NotStarted,
@ -26,13 +26,13 @@ namespace SectionTracking {
ExecutingChildren, ExecutingChildren,
Completed Completed
}; };
TrackedSection( std::string const& name, TrackedSection* parent ) TrackedSection( std::string const& name, TrackedSection* parent )
: m_name( name ), m_runState( NotStarted ), m_parent( parent ) : m_name( name ), m_runState( NotStarted ), m_parent( parent )
{} {}
RunState runState() const { return m_runState; } RunState runState() const { return m_runState; }
TrackedSection* findChild( std::string const& childName ); TrackedSection* findChild( std::string const& childName );
TrackedSection* acquireChild( std::string const& childName ); TrackedSection* acquireChild( std::string const& childName );
@ -48,14 +48,14 @@ namespace SectionTracking {
bool hasChildren() const { bool hasChildren() const {
return !m_children.empty(); return !m_children.empty();
} }
private: private:
std::string m_name; std::string m_name;
RunState m_runState; RunState m_runState;
TrackedSections m_children; TrackedSections m_children;
TrackedSection* m_parent; TrackedSection* m_parent;
}; };
inline TrackedSection* TrackedSection::findChild( std::string const& childName ) { inline TrackedSection* TrackedSection::findChild( std::string const& childName ) {
TrackedSections::iterator it = m_children.find( childName ); TrackedSections::iterator it = m_children.find( childName );
return it != m_children.end() return it != m_children.end()

View File

@ -108,7 +108,7 @@ namespace Catch {
SectionNode const& rootSection = *testCaseNode.children.front(); SectionNode const& rootSection = *testCaseNode.children.front();
std::string className = stats.testInfo.className; std::string className = stats.testInfo.className;
if( className.empty() ) { if( className.empty() ) {
if( rootSection.childSections.empty() ) if( rootSection.childSections.empty() )
className = "global"; className = "global";
@ -122,7 +122,7 @@ namespace Catch {
std::string name = trim( sectionNode.stats.sectionInfo.name ); std::string name = trim( sectionNode.stats.sectionInfo.name );
if( !rootName.empty() ) if( !rootName.empty() )
name = rootName + "/" + name; name = rootName + "/" + name;
if( !sectionNode.assertions.empty() || if( !sectionNode.assertions.empty() ||
!sectionNode.stdOut.empty() || !sectionNode.stdOut.empty() ||
!sectionNode.stdErr.empty() ) { !sectionNode.stdErr.empty() ) {
@ -191,7 +191,7 @@ namespace Catch {
elementName = "internalError"; elementName = "internalError";
break; break;
} }
XmlWriter::ScopedElement e = xml.scopedElement( elementName ); XmlWriter::ScopedElement e = xml.scopedElement( elementName );
xml.writeAttribute( "message", result.getExpandedExpression() ); xml.writeAttribute( "message", result.getExpandedExpression() );
@ -220,7 +220,7 @@ namespace Catch {
unsigned int unexpectedExceptions; unsigned int unexpectedExceptions;
}; };
INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
} // end namespace Catch } // end namespace Catch

View File

@ -22,13 +22,13 @@
#endif #endif
namespace Catch { namespace Catch {
struct TeamCityReporter : StreamingReporterBase { struct TeamCityReporter : StreamingReporterBase {
TeamCityReporter( ReporterConfig const& _config ) TeamCityReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ), : StreamingReporterBase( _config ),
m_headerPrintedForThisSection( false ) m_headerPrintedForThisSection( false )
{} {}
static std::string escape( std::string const& str ) { static std::string escape( std::string const& str ) {
std::string escaped = str; std::string escaped = str;
replaceInPlace( escaped, "|", "||" ); replaceInPlace( escaped, "|", "||" );
@ -59,9 +59,9 @@ namespace Catch {
stream << " message='test skipped because it didn|'t match the test spec'"; stream << " message='test skipped because it didn|'t match the test spec'";
stream << "]\n"; stream << "]\n";
} }
virtual void noMatchingTestCases( std::string const& /* spec */ ) {} virtual void noMatchingTestCases( std::string const& /* spec */ ) {}
virtual void testGroupStarting( GroupInfo const& groupInfo ) { virtual void testGroupStarting( GroupInfo const& groupInfo ) {
StreamingReporterBase::testGroupStarting( groupInfo ); StreamingReporterBase::testGroupStarting( groupInfo );
stream << "##teamcity[testSuiteStarted name='" stream << "##teamcity[testSuiteStarted name='"
@ -73,21 +73,21 @@ namespace Catch {
<< escape( testGroupStats.groupInfo.name ) << "']\n"; << escape( testGroupStats.groupInfo.name ) << "']\n";
} }
virtual void assertionStarting( AssertionInfo const& ) { virtual void assertionStarting( AssertionInfo const& ) {
} }
virtual bool assertionEnded( AssertionStats const& assertionStats ) { virtual bool assertionEnded( AssertionStats const& assertionStats ) {
AssertionResult const& result = assertionStats.assertionResult; AssertionResult const& result = assertionStats.assertionResult;
if( !result.isOk() ) { if( !result.isOk() ) {
std::ostringstream msg; std::ostringstream msg;
if( !m_headerPrintedForThisSection ) if( !m_headerPrintedForThisSection )
printSectionHeader( msg ); printSectionHeader( msg );
m_headerPrintedForThisSection = true; m_headerPrintedForThisSection = true;
msg << result.getSourceInfo() << "\n"; msg << result.getSourceInfo() << "\n";
switch( result.getResultType() ) { switch( result.getResultType() ) {
case ResultWas::ExpressionFailed: case ResultWas::ExpressionFailed:
msg << "expression failed"; msg << "expression failed";
@ -126,15 +126,15 @@ namespace Catch {
it != itEnd; it != itEnd;
++it ) ++it )
msg << "\n \"" << it->message << "\""; msg << "\n \"" << it->message << "\"";
if( result.hasExpression() ) { if( result.hasExpression() ) {
msg << msg <<
"\n " << result.getExpressionInMacro() << "\n" "\n " << result.getExpressionInMacro() << "\n"
"with expansion:\n" << "with expansion:\n" <<
" " << result.getExpandedExpression() << "\n"; " " << result.getExpandedExpression() << "\n";
} }
stream << "##teamcity[testFailed" stream << "##teamcity[testFailed"
<< " name='" << escape( currentTestCaseInfo->name )<< "'" << " name='" << escape( currentTestCaseInfo->name )<< "'"
<< " message='" << escape( msg.str() ) << "'" << " message='" << escape( msg.str() ) << "'"
@ -142,7 +142,7 @@ namespace Catch {
} }
return true; return true;
} }
virtual void sectionStarting( SectionInfo const& sectionInfo ) { virtual void sectionStarting( SectionInfo const& sectionInfo ) {
m_headerPrintedForThisSection = false; m_headerPrintedForThisSection = false;
StreamingReporterBase::sectionStarting( sectionInfo ); StreamingReporterBase::sectionStarting( sectionInfo );
@ -153,7 +153,7 @@ namespace Catch {
stream << "##teamcity[testStarted name='" stream << "##teamcity[testStarted name='"
<< escape( testInfo.name ) << "']\n"; << escape( testInfo.name ) << "']\n";
} }
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) { virtual void testCaseEnded( TestCaseStats const& testCaseStats ) {
StreamingReporterBase::testCaseEnded( testCaseStats ); StreamingReporterBase::testCaseEnded( testCaseStats );
if( !testCaseStats.stdOut.empty() ) if( !testCaseStats.stdOut.empty() )
@ -182,9 +182,9 @@ namespace Catch {
printHeaderString( os, it->name ); printHeaderString( os, it->name );
os << getLineOfChars<'-'>() << "\n"; os << getLineOfChars<'-'>() << "\n";
} }
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
if( !lineInfo.empty() ) if( !lineInfo.empty() )
os << lineInfo << "\n"; os << lineInfo << "\n";
os << getLineOfChars<'.'>() << "\n\n"; os << getLineOfChars<'.'>() << "\n\n";
@ -204,15 +204,15 @@ namespace Catch {
} }
private: private:
bool m_headerPrintedForThisSection; bool m_headerPrintedForThisSection;
}; };
#ifdef CATCH_IMPL #ifdef CATCH_IMPL
TeamCityReporter::~TeamCityReporter() {} TeamCityReporter::~TeamCityReporter() {}
#endif #endif
INTERNAL_CATCH_REGISTER_REPORTER( "teamcity", TeamCityReporter ) INTERNAL_CATCH_REGISTER_REPORTER( "teamcity", TeamCityReporter )
} // end namespace Catch } // end namespace Catch
#ifdef __clang__ #ifdef __clang__

View File

@ -24,7 +24,7 @@ namespace Catch {
{} {}
virtual ~XmlReporter(); virtual ~XmlReporter();
static std::string getDescription() { static std::string getDescription() {
return "Reports test results as an XML document"; return "Reports test results as an XML document";
} }
@ -75,7 +75,7 @@ namespace Catch {
virtual bool assertionEnded( AssertionStats const& assertionStats ) { virtual bool assertionEnded( AssertionStats const& assertionStats ) {
const AssertionResult& assertionResult = assertionStats.assertionResult; const AssertionResult& assertionResult = assertionStats.assertionResult;
// Print any info messages in <Info> tags. // Print any info messages in <Info> tags.
if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
@ -137,10 +137,10 @@ namespace Catch {
default: default:
break; break;
} }
if( assertionResult.hasExpression() ) if( assertionResult.hasExpression() )
m_xml.endElement(); m_xml.endElement();
return true; return true;
} }
@ -179,7 +179,7 @@ namespace Catch {
.writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
m_xml.endElement(); m_xml.endElement();
} }
virtual void testRunEnded( TestRunStats const& testRunStats ) { virtual void testRunEnded( TestRunStats const& testRunStats ) {
StreamingReporterBase::testRunEnded( testRunStats ); StreamingReporterBase::testRunEnded( testRunStats );
m_xml.scopedElement( "OverallResults" ) m_xml.scopedElement( "OverallResults" )

View File

@ -16,7 +16,7 @@ TEST_CASE
) )
{ {
double d = 1.23; double d = 1.23;
REQUIRE( d == Approx( 1.23 ) ); REQUIRE( d == Approx( 1.23 ) );
REQUIRE( d != Approx( 1.22 ) ); REQUIRE( d != Approx( 1.22 ) );
REQUIRE( d != Approx( 1.24 ) ); REQUIRE( d != Approx( 1.24 ) );
@ -34,7 +34,7 @@ TEST_CASE
) )
{ {
double d = 1.23; double d = 1.23;
REQUIRE( d != Approx( 1.231 ) ); REQUIRE( d != Approx( 1.231 ) );
REQUIRE( d == Approx( 1.231 ).epsilon( 0.1 ) ); REQUIRE( d == Approx( 1.231 ).epsilon( 0.1 ) );
} }
@ -71,7 +71,7 @@ TEST_CASE
const double dZero = 0; const double dZero = 0;
const double dSmall = 0.00001; const double dSmall = 0.00001;
const double dMedium = 1.234; const double dMedium = 1.234;
REQUIRE( 1.0f == Approx( 1 ) ); REQUIRE( 1.0f == Approx( 1 ) );
REQUIRE( 0 == Approx( dZero) ); REQUIRE( 0 == Approx( dZero) );
REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) ); REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) );
@ -87,14 +87,14 @@ TEST_CASE
) )
{ {
double d = 1.23; double d = 1.23;
Approx approx = Approx::custom().epsilon( 0.005 ); Approx approx = Approx::custom().epsilon( 0.005 );
REQUIRE( d == approx( 1.23 ) ); REQUIRE( d == approx( 1.23 ) );
REQUIRE( d == approx( 1.22 ) ); REQUIRE( d == approx( 1.22 ) );
REQUIRE( d == approx( 1.24 ) ); REQUIRE( d == approx( 1.24 ) );
REQUIRE( d != approx( 1.25 ) ); REQUIRE( d != approx( 1.25 ) );
REQUIRE( approx( d ) == 1.23 ); REQUIRE( approx( d ) == 1.23 );
REQUIRE( approx( d ) == 1.22 ); REQUIRE( approx( d ) == 1.22 );
REQUIRE( approx( d ) == 1.24 ); REQUIRE( approx( d ) == 1.24 );

View File

@ -30,13 +30,13 @@ SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capa
GIVEN( "an empty vector" ) { GIVEN( "an empty vector" ) {
std::vector<int> v; std::vector<int> v;
REQUIRE( v.size() == 0 ); REQUIRE( v.size() == 0 );
WHEN( "it is made larger" ) { WHEN( "it is made larger" ) {
v.resize( 10 ); v.resize( 10 );
THEN( "the size and capacity go up" ) { THEN( "the size and capacity go up" ) {
REQUIRE( v.size() == 10 ); REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 ); REQUIRE( v.capacity() >= 10 );
AND_WHEN( "it is made smaller again" ) { AND_WHEN( "it is made smaller again" ) {
v.resize( 5 ); v.resize( 5 );
THEN( "the size goes down but the capacity stays the same" ) { THEN( "the size goes down but the capacity stays the same" ) {
@ -46,7 +46,7 @@ SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capa
} }
} }
} }
WHEN( "we reserve more space" ) { WHEN( "we reserve more space" ) {
v.reserve( 10 ); v.reserve( 10 );
THEN( "The capacity is increased but the size remains the same" ) { THEN( "The capacity is increased but the size remains the same" ) {
@ -76,19 +76,19 @@ struct Fixture
: d_counter(0) : d_counter(0)
{ {
} }
int counter() int counter()
{ {
return d_counter++; return d_counter++;
} }
int d_counter; int d_counter;
}; };
} }
SCENARIO_METHOD(Fixture, SCENARIO_METHOD(Fixture,
"BDD tests requiring Fixtures to provide commonly-accessed data or methods", "BDD tests requiring Fixtures to provide commonly-accessed data or methods",
"[bdd][fixtures]") { "[bdd][fixtures]") {
const int before(counter()); const int before(counter());
GIVEN("No operations precede me") { GIVEN("No operations precede me") {

View File

@ -13,18 +13,18 @@ namespace
class TestClass class TestClass
{ {
std::string s; std::string s;
public: public:
TestClass() TestClass()
: s( "hello" ) : s( "hello" )
{} {}
void succeedingCase() void succeedingCase()
{ {
REQUIRE( s == "hello" ); REQUIRE( s == "hello" );
} }
void failingCase() void failingCase()
{ {
REQUIRE( s == "world" ); REQUIRE( s == "world" );
} }
}; };
@ -38,20 +38,20 @@ METHOD_AS_TEST_CASE( TestClass::failingCase, "A METHOD_AS_TEST_CASE based test r
struct Fixture struct Fixture
{ {
Fixture() : m_a( 1 ) {} Fixture() : m_a( 1 ) {}
int m_a; int m_a;
}; };
TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that succeeds", "[class]" ) TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that succeeds", "[class]" )
{ {
REQUIRE( m_a == 1 ); REQUIRE( m_a == 1 );
} }
// We should be able to write our tests within a different namespace // We should be able to write our tests within a different namespace
namespace Inner namespace Inner
{ {
TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that fails", "[.][class][failing]" ) TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that fails", "[.][class][failing]" )
{ {
REQUIRE( m_a == 2 ); REQUIRE( m_a == 2 );
} }
} }

View File

@ -21,7 +21,7 @@ struct TestData {
float_nine_point_one( 9.1f ), float_nine_point_one( 9.1f ),
double_pi( 3.1415926535 ) double_pi( 3.1415926535 )
{} {}
int int_seven; int int_seven;
std::string str_hello; std::string str_hello;
float float_nine_point_one; float float_nine_point_one;
@ -36,7 +36,7 @@ struct TestDef {
TestDef& operator[]( const std::string& ) { TestDef& operator[]( const std::string& ) {
return *this; return *this;
} }
}; };
// The "failing" tests all use the CHECK macro, which continues if the specific test fails. // The "failing" tests all use the CHECK macro, which continues if the specific test fails.
@ -48,14 +48,14 @@ TEST_CASE( "Equality checks that should succeed", "" )
TestDef td; TestDef td;
td + "hello" + "hello"; td + "hello" + "hello";
TestData data; TestData data;
REQUIRE( data.int_seven == 7 ); REQUIRE( data.int_seven == 7 );
REQUIRE( data.float_nine_point_one == Approx( 9.1f ) ); REQUIRE( data.float_nine_point_one == Approx( 9.1f ) );
REQUIRE( data.double_pi == Approx( 3.1415926535 ) ); REQUIRE( data.double_pi == Approx( 3.1415926535 ) );
REQUIRE( data.str_hello == "hello" ); REQUIRE( data.str_hello == "hello" );
REQUIRE( "hello" == data.str_hello ); REQUIRE( "hello" == data.str_hello );
REQUIRE( data.str_hello.size() == 5 ); REQUIRE( data.str_hello.size() == 5 );
double x = 1.1 + 0.1 + 0.1; double x = 1.1 + 0.1 + 0.1;
@ -65,7 +65,7 @@ TEST_CASE( "Equality checks that should succeed", "" )
TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" ) TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" )
{ {
TestData data; TestData data;
CHECK( data.int_seven == 6 ); CHECK( data.int_seven == 6 );
CHECK( data.int_seven == 8 ); CHECK( data.int_seven == 8 );
CHECK( data.int_seven == 0 ); CHECK( data.int_seven == 0 );
@ -86,7 +86,7 @@ TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" )
TEST_CASE( "Inequality checks that should succeed", "" ) TEST_CASE( "Inequality checks that should succeed", "" )
{ {
TestData data; TestData data;
REQUIRE( data.int_seven != 6 ); REQUIRE( data.int_seven != 6 );
REQUIRE( data.int_seven != 8 ); REQUIRE( data.int_seven != 8 );
REQUIRE( data.float_nine_point_one != Approx( 9.11f ) ); REQUIRE( data.float_nine_point_one != Approx( 9.11f ) );
@ -103,7 +103,7 @@ TEST_CASE( "Inequality checks that should succeed", "" )
TEST_CASE( "Inequality checks that should fail", "[.][failing]" ) TEST_CASE( "Inequality checks that should fail", "[.][failing]" )
{ {
TestData data; TestData data;
CHECK( data.int_seven != 7 ); CHECK( data.int_seven != 7 );
CHECK( data.float_nine_point_one != Approx( 9.1f ) ); CHECK( data.float_nine_point_one != Approx( 9.1f ) );
CHECK( data.double_pi != Approx( 3.1415926535 ) ); CHECK( data.double_pi != Approx( 3.1415926535 ) );
@ -115,7 +115,7 @@ TEST_CASE( "Inequality checks that should fail", "[.][failing]" )
TEST_CASE( "Ordering comparison checks that should succeed", "" ) TEST_CASE( "Ordering comparison checks that should succeed", "" )
{ {
TestData data; TestData data;
REQUIRE( data.int_seven < 8 ); REQUIRE( data.int_seven < 8 );
REQUIRE( data.int_seven > 6 ); REQUIRE( data.int_seven > 6 );
REQUIRE( data.int_seven > 0 ); REQUIRE( data.int_seven > 0 );
@ -125,14 +125,14 @@ TEST_CASE( "Ordering comparison checks that should succeed", "" )
REQUIRE( data.int_seven >= 6 ); REQUIRE( data.int_seven >= 6 );
REQUIRE( data.int_seven <= 7 ); REQUIRE( data.int_seven <= 7 );
REQUIRE( data.int_seven <= 8 ); REQUIRE( data.int_seven <= 8 );
REQUIRE( data.float_nine_point_one > 9 ); REQUIRE( data.float_nine_point_one > 9 );
REQUIRE( data.float_nine_point_one < 10 ); REQUIRE( data.float_nine_point_one < 10 );
REQUIRE( data.float_nine_point_one < 9.2 ); REQUIRE( data.float_nine_point_one < 9.2 );
REQUIRE( data.str_hello <= "hello" ); REQUIRE( data.str_hello <= "hello" );
REQUIRE( data.str_hello >= "hello" ); REQUIRE( data.str_hello >= "hello" );
REQUIRE( data.str_hello < "hellp" ); REQUIRE( data.str_hello < "hellp" );
REQUIRE( data.str_hello < "zebra" ); REQUIRE( data.str_hello < "zebra" );
REQUIRE( data.str_hello > "hellm" ); REQUIRE( data.str_hello > "hellm" );
@ -142,7 +142,7 @@ TEST_CASE( "Ordering comparison checks that should succeed", "" )
TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" ) TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" )
{ {
TestData data; TestData data;
CHECK( data.int_seven > 7 ); CHECK( data.int_seven > 7 );
CHECK( data.int_seven < 7 ); CHECK( data.int_seven < 7 );
CHECK( data.int_seven > 8 ); CHECK( data.int_seven > 8 );
@ -152,11 +152,11 @@ TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" )
CHECK( data.int_seven >= 8 ); CHECK( data.int_seven >= 8 );
CHECK( data.int_seven <= 6 ); CHECK( data.int_seven <= 6 );
CHECK( data.float_nine_point_one < 9 ); CHECK( data.float_nine_point_one < 9 );
CHECK( data.float_nine_point_one > 10 ); CHECK( data.float_nine_point_one > 10 );
CHECK( data.float_nine_point_one > 9.2 ); CHECK( data.float_nine_point_one > 9.2 );
CHECK( data.str_hello > "hello" ); CHECK( data.str_hello > "hello" );
CHECK( data.str_hello < "hello" ); CHECK( data.str_hello < "hello" );
CHECK( data.str_hello > "hellp" ); CHECK( data.str_hello > "hellp" );
@ -177,7 +177,7 @@ TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigne
unsigned long ul = 4; unsigned long ul = 4;
char c = 5; char c = 5;
unsigned char uc = 6; unsigned char uc = 6;
REQUIRE( i == 1 ); REQUIRE( i == 1 );
REQUIRE( ui == 2 ); REQUIRE( ui == 2 );
REQUIRE( l == 3 ); REQUIRE( l == 3 );
@ -214,7 +214,7 @@ TEST_CASE( "comparisons between int variables", "" )
unsigned short unsigned_short_var = 1; unsigned short unsigned_short_var = 1;
unsigned int unsigned_int_var = 1; unsigned int unsigned_int_var = 1;
unsigned long unsigned_long_var = 1L; unsigned long unsigned_long_var = 1L;
REQUIRE( long_var == unsigned_char_var ); REQUIRE( long_var == unsigned_char_var );
REQUIRE( long_var == unsigned_short_var ); REQUIRE( long_var == unsigned_short_var );
REQUIRE( long_var == unsigned_int_var ); REQUIRE( long_var == unsigned_int_var );
@ -251,7 +251,7 @@ template<typename T>
struct Ex struct Ex
{ {
Ex( T ){} Ex( T ){}
bool operator == ( const T& ) const { return true; } bool operator == ( const T& ) const { return true; }
T operator * ( const T& ) const { return T(); } T operator * ( const T& ) const { return T(); }
}; };
@ -272,13 +272,13 @@ TEST_CASE( "Pointers can be compared to null", "" )
{ {
TestData* p = NULL; TestData* p = NULL;
TestData* pNULL = NULL; TestData* pNULL = NULL;
REQUIRE( p == NULL ); REQUIRE( p == NULL );
REQUIRE( p == pNULL ); REQUIRE( p == pNULL );
TestData data; TestData data;
p = &data; p = &data;
REQUIRE( p != NULL ); REQUIRE( p != NULL );
const TestData* cp = p; const TestData* cp = p;
@ -289,7 +289,7 @@ TEST_CASE( "Pointers can be compared to null", "" )
REQUIRE( returnsNull() == NULL ); REQUIRE( returnsNull() == NULL );
REQUIRE( returnsConstNull() == NULL ); REQUIRE( returnsConstNull() == NULL );
REQUIRE( NULL != p ); REQUIRE( NULL != p );
} }
@ -303,7 +303,7 @@ TEST_CASE( "Pointers can be compared to null", "" )
TEST_CASE( "'Not' checks that should succeed", "" ) TEST_CASE( "'Not' checks that should succeed", "" )
{ {
bool falseValue = false; bool falseValue = false;
REQUIRE( false == false ); REQUIRE( false == false );
REQUIRE( true == true ); REQUIRE( true == true );
REQUIRE( !false ); REQUIRE( !false );
@ -319,15 +319,15 @@ TEST_CASE( "'Not' checks that should succeed", "" )
TEST_CASE( "'Not' checks that should fail", "[.][failing]" ) TEST_CASE( "'Not' checks that should fail", "[.][failing]" )
{ {
bool trueValue = true; bool trueValue = true;
CHECK( false != false ); CHECK( false != false );
CHECK( true != true ); CHECK( true != true );
CHECK( !true ); CHECK( !true );
CHECK_FALSE( true ); CHECK_FALSE( true );
CHECK( !trueValue ); CHECK( !trueValue );
CHECK_FALSE( trueValue ); CHECK_FALSE( trueValue );
CHECK( !(1 == 1) ); CHECK( !(1 == 1) );
CHECK_FALSE( 1 == 1 ); CHECK_FALSE( 1 == 1 );
} }

View File

@ -96,12 +96,12 @@ public:
CustomException( const std::string& msg ) CustomException( const std::string& msg )
: m_msg( msg ) : m_msg( msg )
{} {}
std::string getMessage() const std::string getMessage() const
{ {
return m_msg; return m_msg;
} }
private: private:
std::string m_msg; std::string m_msg;
}; };

View File

@ -19,10 +19,10 @@ inline int multiply( int a, int b )
CATCH_TEST_CASE( "Generators over two ranges", "[generators]" ) CATCH_TEST_CASE( "Generators over two ranges", "[generators]" )
{ {
using namespace Catch::Generators; using namespace Catch::Generators;
int i = CATCH_GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) ); int i = CATCH_GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) );
int j = CATCH_GENERATE( between( 100, 107 ) ); int j = CATCH_GENERATE( between( 100, 107 ) );
CATCH_REQUIRE( multiply( i, 2 ) == i*2 ); CATCH_REQUIRE( multiply( i, 2 ) == i*2 );
CATCH_REQUIRE( multiply( j, 2 ) == j*2 ); CATCH_REQUIRE( multiply( j, 2 ) == j*2 );
} }
@ -32,11 +32,11 @@ struct IntPair { int first, second; };
CATCH_TEST_CASE( "Generator over a range of pairs", "[generators]" ) CATCH_TEST_CASE( "Generator over a range of pairs", "[generators]" )
{ {
using namespace Catch::Generators; using namespace Catch::Generators;
IntPair p[] = { { 0, 1 }, { 2, 3 } }; IntPair p[] = { { 0, 1 }, { 2, 3 } };
IntPair* i = CATCH_GENERATE( between( p, &p[1] ) ); IntPair* i = CATCH_GENERATE( between( p, &p[1] ) );
CATCH_REQUIRE( i->first == i->second-1 ); CATCH_REQUIRE( i->first == i->second-1 );
} }

View File

@ -38,7 +38,7 @@ TEST_CASE( "INFO gets logged on failure, even if captured before successful asse
CHECK( a == 2 ); CHECK( a == 2 );
INFO( "this message should be logged" ); INFO( "this message should be logged" );
CHECK( a == 1 ); CHECK( a == 1 );
INFO( "and this, but later" ); INFO( "and this, but later" );
@ -85,7 +85,7 @@ TEST_CASE( "Standard output from all sections is reported", "[messages][.]" )
{ {
std::cout << "Message from section one" << std::endl; std::cout << "Message from section one" << std::endl;
} }
SECTION( "two", "" ) SECTION( "two", "" )
{ {
std::cout << "Message from section two" << std::endl; std::cout << "Message from section two" << std::endl;

View File

@ -18,7 +18,7 @@ TEST_CASE( "random SECTION tests", "[.][sections][failing]" )
{ {
int a = 1; int a = 1;
int b = 2; int b = 2;
SECTION( "s1", "doesn't equal" ) SECTION( "s1", "doesn't equal" )
{ {
REQUIRE( a != b ); REQUIRE( a != b );
@ -35,7 +35,7 @@ TEST_CASE( "nested SECTION tests", "[.][sections][failing]" )
{ {
int a = 1; int a = 1;
int b = 2; int b = 2;
SECTION( "s1", "doesn't equal" ) SECTION( "s1", "doesn't equal" )
{ {
REQUIRE( a != b ); REQUIRE( a != b );
@ -52,7 +52,7 @@ TEST_CASE( "more nested SECTION tests", "[sections][failing][.]" )
{ {
int a = 1; int a = 1;
int b = 2; int b = 2;
SECTION( "s1", "doesn't equal" ) SECTION( "s1", "doesn't equal" )
{ {
SECTION( "s2", "equal" ) SECTION( "s2", "equal" )
@ -78,7 +78,7 @@ TEST_CASE( "even more nested SECTION tests", "[sections]" )
SECTION( "d (leaf)", "" ) SECTION( "d (leaf)", "" )
{ {
} }
SECTION( "e (leaf)", "" ) SECTION( "e (leaf)", "" )
{ {
} }
@ -92,14 +92,14 @@ TEST_CASE( "even more nested SECTION tests", "[sections]" )
TEST_CASE( "looped SECTION tests", "[.][failing][sections]" ) TEST_CASE( "looped SECTION tests", "[.][failing][sections]" )
{ {
int a = 1; int a = 1;
for( int b = 0; b < 10; ++b ) for( int b = 0; b < 10; ++b )
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "b is currently: " << b; oss << "b is currently: " << b;
SECTION( "s1", oss.str() ) SECTION( "s1", oss.str() )
{ {
CHECK( b > a ); CHECK( b > a );
} }
} }
} }
@ -107,18 +107,18 @@ TEST_CASE( "looped SECTION tests", "[.][failing][sections]" )
TEST_CASE( "looped tests", "[.][failing]" ) TEST_CASE( "looped tests", "[.][failing]" )
{ {
static const int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21 }; static const int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21 };
for( size_t i=0; i < sizeof(fib)/sizeof(int); ++i ) for( size_t i=0; i < sizeof(fib)/sizeof(int); ++i )
{ {
INFO( "Testing if fib[" << i << "] (" << fib[i] << ") is even" ); INFO( "Testing if fib[" << i << "] (" << fib[i] << ") is even" );
CHECK( ( fib[i] % 2 ) == 0 ); CHECK( ( fib[i] % 2 ) == 0 );
} }
} }
TEST_CASE( "Sends stuff to stdout and stderr", "[.]" ) TEST_CASE( "Sends stuff to stdout and stderr", "[.]" )
{ {
std::cout << "A string sent directly to stdout" << std::endl; std::cout << "A string sent directly to stdout" << std::endl;
std::cerr << "A string sent directly to stderr" << std::endl; std::cerr << "A string sent directly to stderr" << std::endl;
} }
@ -156,7 +156,7 @@ inline bool testCheckedElse( bool flag )
{ {
CHECKED_ELSE( flag ) CHECKED_ELSE( flag )
return false; return false;
return true; return true;
} }
@ -185,13 +185,13 @@ TEST_CASE( "xmlentitycheck", "" )
TEST_CASE( "send a single char to INFO", "[failing][.]" ) TEST_CASE( "send a single char to INFO", "[failing][.]" )
{ {
INFO(3); INFO(3);
REQUIRE(false); REQUIRE(false);
} }
TEST_CASE( "atomic if", "[failing][0]") TEST_CASE( "atomic if", "[failing][0]")
{ {
size_t x = 0; size_t x = 0;
if( x ) if( x )
REQUIRE(x > 0); REQUIRE(x > 0);
else else
@ -205,7 +205,7 @@ inline const char* testStringForMatching()
TEST_CASE("String matchers", "[matchers]" ) TEST_CASE("String matchers", "[matchers]" )
{ {
REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); REQUIRE_THAT( testStringForMatching(), Contains( "string" ) );
CHECK_THAT( testStringForMatching(), Contains( "abc" ) ); CHECK_THAT( testStringForMatching(), Contains( "abc" ) );
CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ); CHECK_THAT( testStringForMatching(), StartsWith( "this" ) );
@ -291,38 +291,38 @@ TEST_CASE( "second tag", "[tag2]" )
TEST_CASE( "vectors can be sized and resized", "[vector]" ) { TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
std::vector<int> v( 5 ); std::vector<int> v( 5 );
REQUIRE( v.size() == 5 ); REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 ); REQUIRE( v.capacity() >= 5 );
SECTION( "resizing bigger changes size and capacity", "" ) { SECTION( "resizing bigger changes size and capacity", "" ) {
v.resize( 10 ); v.resize( 10 );
REQUIRE( v.size() == 10 ); REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 ); REQUIRE( v.capacity() >= 10 );
} }
SECTION( "resizing smaller changes size but not capacity", "" ) { SECTION( "resizing smaller changes size but not capacity", "" ) {
v.resize( 0 ); v.resize( 0 );
REQUIRE( v.size() == 0 ); REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 ); REQUIRE( v.capacity() >= 5 );
SECTION( "We can use the 'swap trick' to reset the capacity", "" ) { SECTION( "We can use the 'swap trick' to reset the capacity", "" ) {
std::vector<int> empty; std::vector<int> empty;
empty.swap( v ); empty.swap( v );
REQUIRE( v.capacity() == 0 ); REQUIRE( v.capacity() == 0 );
} }
} }
SECTION( "reserving bigger changes capacity but not size", "" ) { SECTION( "reserving bigger changes capacity but not size", "" ) {
v.reserve( 10 ); v.reserve( 10 );
REQUIRE( v.size() == 5 ); REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 ); REQUIRE( v.capacity() >= 10 );
} }
SECTION( "reserving smaller does not change size or capacity", "" ) { SECTION( "reserving smaller does not change size or capacity", "" ) {
v.reserve( 0 ); v.reserve( 0 );
REQUIRE( v.size() == 5 ); REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 ); REQUIRE( v.capacity() >= 5 );
} }

View File

@ -90,7 +90,7 @@ TEST_CASE( "section tracking", "" ) {
// Leave test case - now complete // Leave test case - now complete
} }
CHECK( testCaseTracker.isCompleted() ); CHECK( testCaseTracker.isCompleted() );
} }
SECTION( "test case with one section within another", "" ) { SECTION( "test case with one section within another", "" ) {
@ -112,6 +112,6 @@ TEST_CASE( "section tracking", "" ) {
// Leave test case - now complete // Leave test case - now complete
} }
CHECK( testCaseTracker.isCompleted() ); CHECK( testCaseTracker.isCompleted() );
} }
} }

View File

@ -48,13 +48,13 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
SECTION( "default - no arguments", "" ) { SECTION( "default - no arguments", "" ) {
const char* argv[] = { "test" }; const char* argv[] = { "test" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
CHECK( config.shouldDebugBreak == false ); CHECK( config.shouldDebugBreak == false );
CHECK( config.abortAfter == -1 ); CHECK( config.abortAfter == -1 );
CHECK( config.noThrow == false ); CHECK( config.noThrow == false );
CHECK( config.reporterName.empty() ); CHECK( config.reporterName.empty() );
} }
SECTION( "test lists", "" ) { SECTION( "test lists", "" ) {
SECTION( "1 test", "Specify one test case using" ) { SECTION( "1 test", "Specify one test case using" ) {
const char* argv[] = { "test", "test1" }; const char* argv[] = { "test", "test1" };
@ -83,43 +83,43 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
} }
} }
SECTION( "reporter", "" ) { SECTION( "reporter", "" ) {
SECTION( "-r/console", "" ) { SECTION( "-r/console", "" ) {
const char* argv[] = { "test", "-r", "console" }; const char* argv[] = { "test", "-r", "console" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.reporterName == "console" ); REQUIRE( config.reporterName == "console" );
} }
SECTION( "-r/xml", "" ) { SECTION( "-r/xml", "" ) {
const char* argv[] = { "test", "-r", "xml" }; const char* argv[] = { "test", "-r", "xml" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.reporterName == "xml" ); REQUIRE( config.reporterName == "xml" );
} }
SECTION( "--reporter/junit", "" ) { SECTION( "--reporter/junit", "" ) {
const char* argv[] = { "test", "--reporter", "junit" }; const char* argv[] = { "test", "--reporter", "junit" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.reporterName == "junit" ); REQUIRE( config.reporterName == "junit" );
} }
} }
SECTION( "debugger", "" ) { SECTION( "debugger", "" ) {
SECTION( "-b", "" ) { SECTION( "-b", "" ) {
const char* argv[] = { "test", "-b" }; const char* argv[] = { "test", "-b" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.shouldDebugBreak == true ); REQUIRE( config.shouldDebugBreak == true );
} }
SECTION( "--break", "" ) { SECTION( "--break", "" ) {
const char* argv[] = { "test", "--break" }; const char* argv[] = { "test", "--break" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.shouldDebugBreak ); REQUIRE( config.shouldDebugBreak );
} }
} }
SECTION( "abort", "" ) { SECTION( "abort", "" ) {
SECTION( "-a aborts after first failure", "" ) { SECTION( "-a aborts after first failure", "" ) {
const char* argv[] = { "test", "-a" }; const char* argv[] = { "test", "-a" };
@ -142,7 +142,7 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "-x" ) ); REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "-x" ) );
} }
} }
SECTION( "nothrow", "" ) { SECTION( "nothrow", "" ) {
SECTION( "-e", "" ) { SECTION( "-e", "" ) {
const char* argv[] = { "test", "-e" }; const char* argv[] = { "test", "-e" };
@ -208,7 +208,7 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
SECTION( "plain string", "" ) { SECTION( "plain string", "" ) {
// guide: 123456789012345678 // guide: 123456789012345678
std::string testString = "one two three four"; std::string testString = "one two three four";
SECTION( "No wrapping", "" ) { SECTION( "No wrapping", "" ) {
CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString ); CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
CHECK( Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString ); CHECK( Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString );
@ -252,14 +252,14 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
.setInitialIndent( 1 ) ); .setInitialIndent( 1 ) );
CHECK( text.toString() == " one two\n three\n four" ); CHECK( text.toString() == " one two\n three\n four" );
} }
} }
SECTION( "With newlines", "" ) { SECTION( "With newlines", "" ) {
// guide: 1234567890123456789 // guide: 1234567890123456789
std::string testString = "one two\nthree four"; std::string testString = "one two\nthree four";
SECTION( "No wrapping" , "" ) { SECTION( "No wrapping" , "" ) {
CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString ); CHECK( Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString );
CHECK( Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString ); CHECK( Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString );
@ -279,17 +279,17 @@ TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {
CHECK( Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" ); CHECK( Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" );
} }
} }
SECTION( "With tabs", "" ) { SECTION( "With tabs", "" ) {
// guide: 1234567890123456789 // guide: 1234567890123456789
std::string testString = "one two \tthree four five six"; std::string testString = "one two \tthree four five six";
CHECK( Text( testString, TextAttributes().setWidth( 15 ) ).toString() CHECK( Text( testString, TextAttributes().setWidth( 15 ) ).toString()
== "one two three\n four\n five\n six" ); == "one two three\n four\n five\n six" );
} }
} }
using namespace Catch; using namespace Catch;
@ -315,7 +315,7 @@ public:
ColourString( std::string const& _string, std::vector<ColourIndex> const& _colours ) ColourString( std::string const& _string, std::vector<ColourIndex> const& _colours )
: string( _string ), colours( _colours ) : string( _string ), colours( _colours )
{} {}
ColourString& addColour( Colour::Code colour, int _index ) { ColourString& addColour( Colour::Code colour, int _index ) {
colours.push_back( ColourIndex( colour, colours.push_back( ColourIndex( colour,
resolveRelativeIndex( _index ), resolveRelativeIndex( _index ),
@ -328,7 +328,7 @@ public:
resolveLastRelativeIndex( _toIndex ) ) ); resolveLastRelativeIndex( _toIndex ) ) );
return *this; return *this;
} }
void writeToStream( std::ostream& _stream ) const { void writeToStream( std::ostream& _stream ) const {
std::size_t last = 0; std::size_t last = 0;
for( std::size_t i = 0; i < colours.size(); ++i ) { for( std::size_t i = 0; i < colours.size(); ++i ) {
@ -342,7 +342,7 @@ public:
last = index.toIndex; last = index.toIndex;
} }
if( last < string.size() ) if( last < string.size() )
_stream << string.substr( last ); _stream << string.substr( last );
} }
friend std::ostream& operator << ( std::ostream& _stream, ColourString const& _colourString ) { friend std::ostream& operator << ( std::ostream& _stream, ColourString const& _colourString ) {
_colourString.writeToStream( _stream ); _colourString.writeToStream( _stream );
@ -399,7 +399,7 @@ TEST_CASE( "replaceInPlace", "" ) {
// !TBD: This will be folded into Text class // !TBD: This will be folded into Text class
TEST_CASE( "Strings can be rendered with colour", "[.colour]" ) { TEST_CASE( "Strings can be rendered with colour", "[.colour]" ) {
{ {
ColourString cs( "hello" ); ColourString cs( "hello" );
cs .addColour( Colour::Red, 0 ) cs .addColour( Colour::Red, 0 )
@ -411,19 +411,19 @@ TEST_CASE( "Strings can be rendered with colour", "[.colour]" ) {
{ {
ColourString cs( "hello" ); ColourString cs( "hello" );
cs .addColour( Colour::Blue, 1, -2 ); cs .addColour( Colour::Blue, 1, -2 );
Catch::cout() << cs << std::endl; Catch::cout() << cs << std::endl;
} }
} }
TEST_CASE( "Text can be formatted using the Text class", "" ) { TEST_CASE( "Text can be formatted using the Text class", "" ) {
CHECK( Text( "hi there" ).toString() == "hi there" ); CHECK( Text( "hi there" ).toString() == "hi there" );
TextAttributes narrow; TextAttributes narrow;
narrow.setWidth( 6 ); narrow.setWidth( 6 );
CHECK( Text( "hi there", narrow ).toString() == "hi\nthere" ); CHECK( Text( "hi there", narrow ).toString() == "hi\nthere" );
} }
@ -436,5 +436,5 @@ TEST_CASE( "Long text is truncted", "[Text][Truncated]" ) {
oss << longLine << longLine << "\n"; oss << longLine << longLine << "\n";
Text t( oss.str() ); Text t( oss.str() );
CHECK_THAT( t.toString(), EndsWith( "... message truncated due to excessive size" ) ); CHECK_THAT( t.toString(), EndsWith( "... message truncated due to excessive size" ) );
} }

View File

@ -25,7 +25,7 @@ namespace Catch
std::ostringstream oss; std::ostringstream oss;
oss << "std::pair( " << value.first << ", " << value.second << " )"; oss << "std::pair( " << value.first << ", " << value.second << " )";
return oss.str(); return oss.str();
} }
} }
@ -38,7 +38,7 @@ TEST_CASE
{ {
std::pair<int, int> aNicePair( 1, 2 ); std::pair<int, int> aNicePair( 1, 2 );
REQUIRE( (std::pair<int, int>( 1, 2 )) == aNicePair ); REQUIRE( (std::pair<int, int>( 1, 2 )) == aNicePair );
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -62,7 +62,7 @@ TEST_CASE
/* /*
int a = 1; int a = 1;
int b = 2; int b = 2;
// This only captures part of the expression, but issues a warning about the rest // This only captures part of the expression, but issues a warning about the rest
REQUIRE( a+1 == b-1 ); REQUIRE( a+1 == b-1 );
*/ */
@ -85,38 +85,38 @@ TEST_CASE
"[Tricky][failing][.]" "[Tricky][failing][.]"
) )
{ {
Opaque o1, o2; Opaque o1, o2;
o1.val = 7; o1.val = 7;
o2.val = 8; o2.val = 8;
CHECK( &o1 == &o2 ); CHECK( &o1 == &o2 );
CHECK( o1 == o2 ); CHECK( o1 == o2 );
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
TEST_CASE TEST_CASE
( (
"string literals of different sizes can be compared", "string literals of different sizes can be compared",
"[Tricky][failing][.]" "[Tricky][failing][.]"
) )
{ {
REQUIRE( std::string( "first" ) == "second" ); REQUIRE( std::string( "first" ) == "second" );
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
TEST_CASE TEST_CASE
( (
"An expression with side-effects should only be evaluated once", "An expression with side-effects should only be evaluated once",
"[Tricky]" "[Tricky]"
) )
{ {
int i = 7; int i = 7;
REQUIRE( i++ == 7 ); REQUIRE( i++ == 7 );
REQUIRE( i++ == 8 ); REQUIRE( i++ == 8 );
} }
namespace A { namespace A {
@ -167,8 +167,8 @@ TEST_CASE
*/ */
namespace ObjectWithConversions namespace ObjectWithConversions
{ {
struct Object struct Object
{ {
operator unsigned int() {return 0xc0000000;} operator unsigned int() {return 0xc0000000;}
}; };
@ -179,31 +179,31 @@ namespace ObjectWithConversions
"Operators at different namespace levels not hijacked by Koenig lookup", "Operators at different namespace levels not hijacked by Koenig lookup",
"[Tricky]" "[Tricky]"
) )
{ {
Object o; Object o;
REQUIRE(0xc0000000 == o ); REQUIRE(0xc0000000 == o );
} }
} }
namespace ObjectWithNonConstEqualityOperator namespace ObjectWithNonConstEqualityOperator
{ {
struct Test struct Test
{ {
Test( unsigned int v ) Test( unsigned int v )
: m_value(v) : m_value(v)
{} {}
bool operator==( const Test&rhs ) bool operator==( const Test&rhs )
{ {
return (m_value == rhs.m_value); return (m_value == rhs.m_value);
} }
bool operator==( const Test&rhs ) const bool operator==( const Test&rhs ) const
{ {
return (m_value != rhs.m_value); return (m_value != rhs.m_value);
} }
unsigned int m_value; unsigned int m_value;
}; };
TEST_CASE("Demonstrate that a non-const == is not used", "[Tricky]" ) TEST_CASE("Demonstrate that a non-const == is not used", "[Tricky]" )
{ {
Test t( 1 ); Test t( 1 );
@ -226,7 +226,7 @@ namespace EnumBitFieldTests
struct Obj struct Obj
{ {
Obj():prop(&p){} Obj():prop(&p){}
int p; int p;
int* prop; int* prop;
}; };
@ -284,11 +284,11 @@ TEST_CASE( "(unimplemented) static bools can be evaluated", "[Tricky]" )
/* /*
TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" ) TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" )
{ {
} }
TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" ) TEST_CASE( "Tests with the same name are not allowed", "[Tricky]" )
{ {
} }
*/ */
@ -317,13 +317,13 @@ TEST_CASE( "Assertions then sections", "[Tricky]" )
{ {
// This was causing a failure due to the way the console reporter was handling // This was causing a failure due to the way the console reporter was handling
// the current section // the current section
REQUIRE( Catch::alwaysTrue() ); REQUIRE( Catch::alwaysTrue() );
SECTION( "A section", "" ) SECTION( "A section", "" )
{ {
REQUIRE( Catch::alwaysTrue() ); REQUIRE( Catch::alwaysTrue() );
SECTION( "Another section", "" ) SECTION( "Another section", "" )
{ {
REQUIRE( Catch::alwaysTrue() ); REQUIRE( Catch::alwaysTrue() );