Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhil Nash2010-11-29 19:40:44 +0000
committerPhil Nash2010-11-29 19:40:44 +0000
commite6b2b0e656d52f95a9fd292199f9eefb59eae585 (patch)
treeb6f1dce7164b84a38d9d9be2226655f322362b1a
parent3d6fa6897096bd4d0ad1bf3a28436dc9fc922caf (diff)
downloadcatch3-e6b2b0e656d52f95a9fd292199f9eefb59eae585.tar.gz
Implemented more reporter methods and started to fill out Section impl
-rw-r--r--Test/MiscTests.cpp31
-rw-r--r--Test/Test.xcodeproj/project.pbxproj36
-rw-r--r--Test/TestMain.cpp14
-rw-r--r--Test/TrickyTests.cpp1
-rw-r--r--catch_reporter_basic.hpp69
-rw-r--r--catch_reporter_xml.hpp9
-rw-r--r--catch_runner.hpp11
-rw-r--r--internal/catch_capture.hpp12
-rw-r--r--internal/catch_reporter_registry.hpp19
-rw-r--r--internal/catch_resultinfo.hpp14
-rw-r--r--internal/catch_runner_impl.hpp22
-rw-r--r--internal/catch_section.hpp20
12 files changed, 223 insertions, 35 deletions
diff --git a/Test/MiscTests.cpp b/Test/MiscTests.cpp
new file mode 100644
index 00000000..ea004cc8
--- /dev/null
+++ b/Test/MiscTests.cpp
@@ -0,0 +1,31 @@
+/*
+ * MiscTests.cpp
+ * Catch - Test
+ *
+ * Created by Phil on 29/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)
+ *
+ */
+
+#include "../catch.hpp"
+
+TEST_CASE( "succeeding/Misc/Sections", "random SECTION tests" )
+{
+ int a = 1;
+ int b = 2;
+
+ SECTION( "s1", "doesn't equal" )
+ {
+ EXPECT( a != b );
+ EXPECT( b != a );
+ }
+
+ SECTION( "s2", "not equal" )
+ {
+ EXPECT_NOT( a == b);
+ }
+
+}
diff --git a/Test/Test.xcodeproj/project.pbxproj b/Test/Test.xcodeproj/project.pbxproj
index 4cb5cb97..0731e547 100644
--- a/Test/Test.xcodeproj/project.pbxproj
+++ b/Test/Test.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
4A3BFFB9128DCF06005609E3 /* TestMain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A3BFFB8128DCF06005609E3 /* TestMain.cpp */; };
+ 4AA7EA9212A438C7005A0B97 /* MiscTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */; };
4AFC38CD12887D80003A0C29 /* ConditionTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AFC38CC12887D80003A0C29 /* ConditionTests.cpp */; };
4AFC3A9912893C56003A0C29 /* ExceptionTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AFC3A9812893C56003A0C29 /* ExceptionTests.cpp */; };
4AFC3AA912893E54003A0C29 /* MessageTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AFC3AA812893E54003A0C29 /* MessageTests.cpp */; };
@@ -32,6 +33,8 @@
/* Begin PBXFileReference section */
4A3BFFB8128DCF06005609E3 /* TestMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestMain.cpp; sourceTree = "<group>"; };
4A3BFFF0128DD23C005609E3 /* catch_runnerconfig.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_runnerconfig.hpp; path = ../internal/catch_runnerconfig.hpp; sourceTree = SOURCE_ROOT; };
+ 4AA7E968129FA1DF005A0B97 /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_junit.hpp; path = ../../../Lib/Catch/catch_reporter_junit.hpp; sourceTree = SOURCE_ROOT; };
+ 4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
4AFC341712809A36003A0C29 /* catch_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_registry.hpp; path = ../internal/catch_registry.hpp; sourceTree = SOURCE_ROOT; };
@@ -80,13 +83,9 @@
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
+ 4AA7E96C129FA2A0005A0B97 /* Tests */,
4A3BFFB8128DCF06005609E3 /* TestMain.cpp */,
4AFC341312809A12003A0C29 /* Catch */,
- 4AFC38CC12887D80003A0C29 /* ConditionTests.cpp */,
- 4AFC3A9812893C56003A0C29 /* ExceptionTests.cpp */,
- 4AFC3AA812893E54003A0C29 /* MessageTests.cpp */,
- 4AFC3B0A12894114003A0C29 /* ClassTests.cpp */,
- 4AFC3B661289C7E3003A0C29 /* TrickyTests.cpp */,
);
name = Source;
sourceTree = "<group>";
@@ -99,14 +98,36 @@
name = Products;
sourceTree = "<group>";
};
+ 4AA7E96B129FA282005A0B97 /* Reporters */ = {
+ isa = PBXGroup;
+ children = (
+ 4AFC341D12809A45003A0C29 /* catch_reporter_basic.hpp */,
+ 4AFC341E12809A45003A0C29 /* catch_reporter_xml.hpp */,
+ 4AA7E968129FA1DF005A0B97 /* catch_reporter_junit.hpp */,
+ );
+ name = Reporters;
+ sourceTree = "<group>";
+ };
+ 4AA7E96C129FA2A0005A0B97 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ 4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */,
+ 4AFC38CC12887D80003A0C29 /* ConditionTests.cpp */,
+ 4AFC3A9812893C56003A0C29 /* ExceptionTests.cpp */,
+ 4AFC3AA812893E54003A0C29 /* MessageTests.cpp */,
+ 4AFC3B0A12894114003A0C29 /* ClassTests.cpp */,
+ 4AFC3B661289C7E3003A0C29 /* TrickyTests.cpp */,
+ );
+ name = Tests;
+ sourceTree = "<group>";
+ };
4AFC341312809A12003A0C29 /* Catch */ = {
isa = PBXGroup;
children = (
4AFC342012809A45003A0C29 /* catch.hpp */,
4AFC341C12809A45003A0C29 /* catch_default_main.hpp */,
- 4AFC341D12809A45003A0C29 /* catch_reporter_basic.hpp */,
- 4AFC341E12809A45003A0C29 /* catch_reporter_xml.hpp */,
4AFC38161284B387003A0C29 /* catch_runner.hpp */,
+ 4AA7E96B129FA282005A0B97 /* Reporters */,
4AFC341412809A1B003A0C29 /* Internal */,
);
name = Catch;
@@ -187,6 +208,7 @@
4AFC3B0B12894114003A0C29 /* ClassTests.cpp in Sources */,
4AFC3B671289C7E3003A0C29 /* TrickyTests.cpp in Sources */,
4A3BFFB9128DCF06005609E3 /* TestMain.cpp in Sources */,
+ 4AA7EA9212A438C7005A0B97 /* MiscTests.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/Test/TestMain.cpp b/Test/TestMain.cpp
index 98f85160..0fc13551 100644
--- a/Test/TestMain.cpp
+++ b/Test/TestMain.cpp
@@ -14,6 +14,7 @@
#include "../catch_runner.hpp"
// This code runs the meta tests and verifies that the failing ones failed and the successful ones succeeded
+/*
int main (int argc, char * const argv[])
{
using namespace Catch;
@@ -22,17 +23,18 @@ int main (int argc, char * const argv[])
if( argc > 1 && ( std::string( argv[1] ) == "-s" || std::string( argv[1] ) == "--success" ) )
showAllResults = true;
+ std::ostringstream ossSucceeding;
+ std::ostringstream ossFailing;
+
ReporterConfig reporterConfig( ReporterConfig::Include::SuccessfulResults );
BasicReporter reporter (reporterConfig );
- Runner runner;
- runner.setReporter( &reporter );
- std::ostringstream ossSucceeding;
+ Runner runner( &reporter );
+
reporterConfig.setStreamBuf( ossSucceeding.rdbuf() );
runner.runMatching( "succeeding/*" );
std::string succeedingResults = ossSucceeding.str();
- std::ostringstream ossFailing;
reporterConfig.setStreamBuf( ossFailing.rdbuf() );
runner.runMatching( "failing/*" );
std::string failingResults = ossFailing.str();
@@ -56,10 +58,12 @@ int main (int argc, char * const argv[])
{
std::cout << failingResults << "\n\n";
}
-
+
if( result == 0 )
{
std::cout << "All " << runner.getSuccessCount() + runner.getFailureCount() << " tests completed successfully" << std::endl;
}
return result;
}
+*/
+#include "catch_default_main.hpp" \ No newline at end of file
diff --git a/Test/TrickyTests.cpp b/Test/TrickyTests.cpp
index 73378323..3b74675d 100644
--- a/Test/TrickyTests.cpp
+++ b/Test/TrickyTests.cpp
@@ -41,3 +41,4 @@ TEST_CASE( "succeeding/Tricky/complex lhs", "Where the LHS is not a simple value
// This only captures part of the expression, but issues a warning about the rest
EXPECT( a == 2 || b == 2 );
}
+
diff --git a/catch_reporter_basic.hpp b/catch_reporter_basic.hpp
index bdd52ade..3026f70a 100644
--- a/catch_reporter_basic.hpp
+++ b/catch_reporter_basic.hpp
@@ -32,12 +32,80 @@ namespace Catch
return "Reports test results as lines of text";
}
+ private:
+
+ ///////////////////////////////////////////////////////////////////////////
+ void ReportCounts( std::size_t succeeded, std::size_t failed )
+ {
+ if( failed + succeeded == 0 )
+ m_config.stream() << "No tests ran";
+ else if( failed == 0 )
+ m_config.stream() << "All " << succeeded << " test(s) succeeded";
+ else if( succeeded == 0 )
+ m_config.stream() << "All " << failed << " test(s) failed";
+ else
+ m_config.stream() << succeeded << " test(s) passed but " << failed << " test(s) failed";
+ }
+
private: // ITestReporter
+
+ ///////////////////////////////////////////////////////////////////////////
+ virtual void StartTesting()
+ {
+ m_config.stream() << "[Started testing]" << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ virtual void EndTesting( std::size_t succeeded, std::size_t failed )
+ {
+ m_config.stream() << "[Testing completed. ";
+ ReportCounts( succeeded, failed );
+ m_config.stream() << "]" << std::endl;
+ (succeeded, failed);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ virtual void StartGroup( const std::string& groupName )
+ {
+ if( !groupName.empty() )
+ m_config.stream() << "[Started group: '" << groupName << "']" << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ virtual void EndGroup( const std::string& groupName, std::size_t succeeded, std::size_t failed )
+ {
+ if( !groupName.empty() )
+ {
+ m_config.stream() << "[End of group: '" << groupName << "'. ";
+ ReportCounts( succeeded, failed );
+ m_config.stream() << "]\n" << std::endl;
+ }
+ }
///////////////////////////////////////////////////////////////////////////
virtual void StartTestCase( const TestCaseInfo& testInfo )
{
m_config.stream() << std::endl << "[Running: " << testInfo.getName() << "]" << std::endl;
+ m_firstSectionInTestCase = true;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ virtual void StartSection( const std::string& sectionName, const std::string /*description*/ )
+ {
+ if( m_firstSectionInTestCase )
+ {
+ m_config.stream() << "\n";
+ m_firstSectionInTestCase = false;
+ }
+ m_config.stream() << "[Started section: '" << sectionName << "']" << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ virtual void EndSection( const std::string& sectionName, std::size_t succeeded, std::size_t failed )
+ {
+ m_config.stream() << "[End of section: '" << sectionName << "'. ";
+ ReportCounts( succeeded, failed );
+ m_config.stream() << "]\n" << std::endl;
}
///////////////////////////////////////////////////////////////////////////
@@ -92,6 +160,7 @@ namespace Catch
private:
const ReporterConfig& m_config;
+ bool m_firstSectionInTestCase;
};
} // end namespace Catch
diff --git a/catch_reporter_xml.hpp b/catch_reporter_xml.hpp
index ce6f76a0..c9953da2 100644
--- a/catch_reporter_xml.hpp
+++ b/catch_reporter_xml.hpp
@@ -35,6 +35,15 @@ namespace Catch
private: // ITestReporter
+ virtual void StartTesting(){}
+ virtual void EndTesting( std::size_t succeeded, std::size_t failed ){(succeeded, failed);}
+
+ virtual void StartGroup( const std::string& groupName ){(groupName);}
+ virtual void EndGroup( const std::string& groupName, std::size_t succeeded, std::size_t failed ){(groupName, succeeded, failed);}
+
+ virtual void StartSection( const std::string& sectionName, const std::string description ){(sectionName,description);}
+ virtual void EndSection( const std::string& sectionName, std::size_t succeeded, std::size_t failed ){(sectionName, succeeded, failed);}
+
///////////////////////////////////////////////////////////////////////////
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo )
{
diff --git a/catch_runner.hpp b/catch_runner.hpp
index 710e9832..4109f560 100644
--- a/catch_runner.hpp
+++ b/catch_runner.hpp
@@ -17,6 +17,7 @@
#include "internal/catch_list.hpp"
#include "catch_reporter_basic.hpp"
#include "catch_reporter_xml.hpp"
+#include "catch_reporter_junit.hpp"
namespace Catch
{
@@ -24,6 +25,7 @@ namespace Catch
{
ReporterRegistry::instance().registerReporter<BasicReporter>( "basic" );
ReporterRegistry::instance().registerReporter<XmlReporter>( "xml" );
+ ReporterRegistry::instance().registerReporter<JunitReporter>( "junit" );
RunnerConfig config;
ArgParser( argc, argv, config );
@@ -51,13 +53,14 @@ namespace Catch
config.getReporterConfig().setStreamBuf( ofs.rdbuf() );
}
- Runner runner;
- runner.setReporter( config.getReporter() );
+ Runner runner( config.getReporter() );
// Run test specs specified on the command line - or default to all
if( config.m_testSpecs.size() == 0 )
{
+ config.getReporter()->StartGroup( "" );
runner.runAll();
+ config.getReporter()->EndGroup( "", runner.getSuccessCount(), runner.getFailureCount() );
}
else
{
@@ -67,11 +70,15 @@ namespace Catch
std::vector<std::string>::const_iterator itEnd = config.m_testSpecs.end();
for(; it != itEnd; ++it )
{
+ size_t prevSuccess = runner.getSuccessCount();
+ size_t prevFail = runner.getFailureCount();
+ config.getReporter()->StartGroup( *it );
if( runner.runMatching( *it ) == 0 )
{
// Use reporter?
std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
}
+ config.getReporter()->EndGroup( *it, runner.getSuccessCount()-prevSuccess, runner.getFailureCount()-prevFail );
}
}
return runner.getFailureCount();
diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp
index 060c6cf1..cb1dd52f 100644
--- a/internal/catch_capture.hpp
+++ b/internal/catch_capture.hpp
@@ -142,6 +142,8 @@ struct IResultListener
{
virtual ~IResultListener(){}
virtual void testEnded( const ResultInfo& result ) = 0;
+ virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures ) = 0;
+ virtual void sectionEnded( const std::string& name, std::size_t successes, std::size_t failures ) = 0;
};
class ResultsCapture
@@ -209,6 +211,16 @@ public:
instance().currentResult.setMessage( msg );
}
+ static bool acceptSectionStart( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures )
+ {
+ return instance().m_listener->sectionStarted( name, description, successes, failures );
+ }
+
+ static void acceptSectionEnd( const std::string& name, std::size_t successes, std::size_t failures )
+ {
+ instance().m_listener->sectionEnded( name, successes, failures );
+ }
+
private:
MutableResultInfo currentResult;
IResultListener* m_listener;
diff --git a/internal/catch_reporter_registry.hpp b/internal/catch_reporter_registry.hpp
index b2ab3a69..bf89ff31 100644
--- a/internal/catch_reporter_registry.hpp
+++ b/internal/catch_reporter_registry.hpp
@@ -79,16 +79,19 @@ namespace Catch
{
virtual ~ITestReporter(){}
- // !TBD
- // StartTesting
- // EndTesting
- // StartGroup
- // EndGroup
- // StartSection
- // EndSection
+ virtual void StartTesting() = 0;
+ virtual void EndTesting( std::size_t succeeded, std::size_t failed ) = 0;
+
+ virtual void StartGroup( const std::string& groupName ) = 0;
+ virtual void EndGroup( const std::string& groupName, std::size_t succeeded, std::size_t failed ) = 0;
+
+ virtual void StartSection( const std::string& sectionName, const std::string description ) = 0;
+ virtual void EndSection( const std::string& sectionName, std::size_t succeeded, std::size_t failed ) = 0;
+
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
- virtual void Result( const ResultInfo& result ) = 0;
virtual void EndTestCase( const TestCaseInfo& testInfo ) = 0;
+
+ virtual void Result( const ResultInfo& result ) = 0;
};
struct IReporterFactory
diff --git a/internal/catch_resultinfo.hpp b/internal/catch_resultinfo.hpp
index 01d5abd1..f7778cbf 100644
--- a/internal/catch_resultinfo.hpp
+++ b/internal/catch_resultinfo.hpp
@@ -20,13 +20,15 @@ namespace Catch
{
Unknown = -1,
Ok = 0,
- ExpressionFailed = 1,
+ Info = 1,
+ Warning = 2,
+
+ FailureBit = 0x10,
- Info = 2,
- Warning = 3,
- ExplicitFailure = 4,
+ ExpressionFailed = FailureBit | 1,
+ ExplicitFailure = FailureBit | 2,
- Exception = 0x100,
+ Exception = 0x110,
ThrewException = Exception | 1,
DidntThrowException = Exception | 2
@@ -58,7 +60,7 @@ namespace Catch
bool ok() const
{
- return m_result == ResultWas::Ok;
+ return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
}
ResultWas::OfType getResultType() const
diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp
index 535da6d6..9b5e7c67 100644
--- a/internal/catch_runner_impl.hpp
+++ b/internal/catch_runner_impl.hpp
@@ -48,16 +48,17 @@ namespace Catch
class Runner : public IResultListener
{
public:
- Runner()
+ explicit Runner( ITestReporter* reporter )
: m_successes( 0 ),
m_failures( 0 ),
- m_reporter( 0 )
+ m_reporter( reporter )
{
+ m_reporter->StartTesting();
}
- void setReporter( ITestReporter* reporter )
+ ~Runner()
{
- m_reporter = reporter;
+ m_reporter->EndTesting( m_successes, m_failures );
}
void runAll()
@@ -134,6 +135,19 @@ namespace Catch
m_reporter->Result( result );
}
+
+ virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures )
+ {
+ m_reporter->StartSection( name, description );
+ successes = m_successes;
+ failures = m_failures;
+ return true;
+ }
+
+ virtual void sectionEnded( const std::string& name, std::size_t prevSuccesses, std::size_t prevFailures )
+ {
+ m_reporter->EndSection( name, m_successes - prevSuccesses, m_failures - prevFailures );
+ }
private:
std::size_t m_successes;
diff --git a/internal/catch_section.hpp b/internal/catch_section.hpp
index 6eb802d6..0261bb7c 100644
--- a/internal/catch_section.hpp
+++ b/internal/catch_section.hpp
@@ -13,6 +13,8 @@
#ifndef TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
+#include "catch_capture.hpp"
+
#include <string>
namespace Catch
@@ -21,15 +23,27 @@ namespace Catch
{
public:
Section( const std::string& name, const std::string& description )
+ : m_name( name ),
+ m_sectionIncluded( ResultsCapture::acceptSectionStart( name, description, m_successes, m_failures ) )
{
- (name, description); // !TBD notify the runner
}
+ ~Section()
+ {
+ ResultsCapture::acceptSectionEnd( m_name, m_successes, m_failures );
+ }
+
+ // This indicates whether the section should be executed or not
operator bool()
{
- // !TBD get this from runner
- return true;
+ return m_sectionIncluded;
}
+
+ private:
+ std::string m_name;
+ std::size_t m_successes;
+ std::size_t m_failures;
+ bool m_sectionIncluded;
};
} // end namespace Catch