mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-14 09:25:40 +02:00
Reformatting
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
/*
|
||||
* catch_reporter_junit.hpp
|
||||
* Catch
|
||||
*
|
||||
* Created by Phil on 26/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_REPORTER_JUNIT_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
|
||||
@@ -17,24 +13,20 @@
|
||||
#include "../internal/catch_reporter_registrars.hpp"
|
||||
#include "../internal/catch_xmlwriter.hpp"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
class JunitReporter : public SharedImpl<IReporter>
|
||||
{
|
||||
struct TestStats
|
||||
{
|
||||
namespace Catch {
|
||||
|
||||
class JunitReporter : public SharedImpl<IReporter> {
|
||||
|
||||
struct TestStats {
|
||||
std::string m_element;
|
||||
std::string m_resultType;
|
||||
std::string m_message;
|
||||
std::string m_content;
|
||||
};
|
||||
|
||||
struct TestCaseStats
|
||||
{
|
||||
TestCaseStats( const std::string& name = std::string() )
|
||||
: m_name( name )
|
||||
{
|
||||
}
|
||||
struct TestCaseStats {
|
||||
|
||||
TestCaseStats( const std::string& name = std::string() ) :m_name( name ){}
|
||||
|
||||
double m_timeInSeconds;
|
||||
std::string m_status;
|
||||
@@ -43,8 +35,8 @@ namespace Catch
|
||||
std::vector<TestStats> m_testStats;
|
||||
};
|
||||
|
||||
struct Stats
|
||||
{
|
||||
struct Stats {
|
||||
|
||||
Stats( const std::string& name = std::string() )
|
||||
: m_testsCount( 0 ),
|
||||
m_failuresCount( 0 ),
|
||||
@@ -52,8 +44,7 @@ namespace Catch
|
||||
m_errorsCount( 0 ),
|
||||
m_timeInSeconds( 0 ),
|
||||
m_name( name )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
std::size_t m_testsCount;
|
||||
std::size_t m_failuresCount;
|
||||
@@ -66,83 +57,55 @@ namespace Catch
|
||||
};
|
||||
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
JunitReporter( const IReporterConfig& config )
|
||||
: m_config( config ),
|
||||
m_testSuiteStats( "AllTests" ),
|
||||
m_currentStats( &m_testSuiteStats )
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
static std::string getDescription()
|
||||
{
|
||||
static std::string getDescription() {
|
||||
return "Reports test results in an XML format that looks like Ant's junitreport target";
|
||||
}
|
||||
|
||||
private: // IReporter
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual bool shouldRedirectStdout
|
||||
()
|
||||
const
|
||||
{
|
||||
virtual bool shouldRedirectStdout() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartTesting()
|
||||
{
|
||||
}
|
||||
virtual void StartTesting(){}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartGroup( const std::string& groupName )
|
||||
{
|
||||
|
||||
virtual void StartGroup( const std::string& groupName ) {
|
||||
m_statsForSuites.push_back( Stats( groupName ) );
|
||||
m_currentStats = &m_statsForSuites.back();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndGroup( const std::string&, const Totals& totals )
|
||||
{
|
||||
virtual void EndGroup( const std::string&, const Totals& totals ) {
|
||||
m_currentStats->m_testsCount = totals.assertions.total();
|
||||
m_currentStats = &m_testSuiteStats;
|
||||
}
|
||||
|
||||
virtual void StartSection( const std::string& /*sectionName*/, const std::string /*description*/ )
|
||||
{
|
||||
}
|
||||
virtual void StartSection( const std::string&, const std::string& ){}
|
||||
|
||||
virtual void EndSection( const std::string& /*sectionName*/, const Counts& /* assertions */ )
|
||||
{
|
||||
virtual void EndSection( const std::string&, const Counts& ){}
|
||||
|
||||
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
|
||||
m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo )
|
||||
{
|
||||
m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) );
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void Result( const Catch::ResultInfo& resultInfo )
|
||||
{
|
||||
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults() )
|
||||
{
|
||||
virtual void Result( const Catch::ResultInfo& resultInfo ) {
|
||||
if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults() ) {
|
||||
TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back();
|
||||
TestStats stats;
|
||||
std::ostringstream oss;
|
||||
if( !resultInfo.getMessage().empty() )
|
||||
{
|
||||
oss << resultInfo.getMessage() << " at ";
|
||||
}
|
||||
oss << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
|
||||
stats.m_content = oss.str();
|
||||
stats.m_message = resultInfo.getExpandedExpression();
|
||||
stats.m_resultType = resultInfo.getTestMacroName();
|
||||
switch( resultInfo.getResultType() )
|
||||
{
|
||||
|
||||
switch( resultInfo.getResultType() ) {
|
||||
case ResultWas::ThrewException:
|
||||
stats.m_element = "error";
|
||||
m_currentStats->m_errorsCount++;
|
||||
@@ -172,23 +135,18 @@ namespace Catch
|
||||
stats.m_element = "unknown";
|
||||
break;
|
||||
}
|
||||
testCaseStats.m_testStats.push_back( stats );
|
||||
|
||||
testCaseStats.m_testStats.push_back( stats );
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals& /* totals */, const std::string& stdOut, const std::string& stdErr )
|
||||
{
|
||||
virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string& stdOut, const std::string& stdErr ) {
|
||||
if( !stdOut.empty() )
|
||||
m_stdOut << stdOut << "\n";
|
||||
if( !stdErr.empty() )
|
||||
m_stdErr << stdErr << "\n";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTesting( const Totals& /* totals */ )
|
||||
{
|
||||
virtual void EndTesting( const Totals& ) {
|
||||
std::ostream& str = m_config.stream();
|
||||
{
|
||||
XmlWriter xml( str );
|
||||
@@ -199,8 +157,7 @@ namespace Catch
|
||||
std::vector<Stats>::const_iterator it = m_statsForSuites.begin();
|
||||
std::vector<Stats>::const_iterator itEnd = m_statsForSuites.end();
|
||||
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
|
||||
xml.writeAttribute( "name", it->m_name );
|
||||
xml.writeAttribute( "errors", it->m_errorsCount );
|
||||
@@ -218,13 +175,10 @@ namespace Catch
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void OutputTestCases( XmlWriter& xml, const Stats& stats )
|
||||
{
|
||||
void OutputTestCases( XmlWriter& xml, const Stats& stats ) {
|
||||
std::vector<TestCaseStats>::const_iterator it = stats.m_testCaseStats.begin();
|
||||
std::vector<TestCaseStats>::const_iterator itEnd = stats.m_testCaseStats.end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
xml.writeBlankLine();
|
||||
xml.writeComment( "Test case" );
|
||||
|
||||
@@ -238,15 +192,11 @@ namespace Catch
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void OutputTestResult( XmlWriter& xml, const TestCaseStats& stats )
|
||||
{
|
||||
void OutputTestResult( XmlWriter& xml, const TestCaseStats& stats ) {
|
||||
std::vector<TestStats>::const_iterator it = stats.m_testStats.begin();
|
||||
std::vector<TestStats>::const_iterator itEnd = stats.m_testStats.end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
if( it->m_element != "success" )
|
||||
{
|
||||
for(; it != itEnd; ++it ) {
|
||||
if( it->m_element != "success" ) {
|
||||
XmlWriter::ScopedElement e = xml.scopedElement( it->m_element );
|
||||
|
||||
xml.writeAttribute( "message", it->m_message );
|
||||
|
Reference in New Issue
Block a user