mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Fairly major reworking of console reporter (still in progress).
Changed reporter interface a bit.
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Catch {
|
||||
class Command {
|
||||
public:
|
||||
Command(){}
|
||||
|
||||
|
||||
explicit Command( const std::string& name ) : m_name( name ) {
|
||||
}
|
||||
|
||||
|
@@ -119,9 +119,9 @@ namespace Catch {
|
||||
|
||||
inline std::ostream& operator << ( std::ostream& os, const SourceLineInfo& info ) {
|
||||
#ifndef __GNUG__
|
||||
os << info.file << "(" << info.line << "): ";
|
||||
os << info.file << "(" << info.line << ")";
|
||||
#else
|
||||
os << info.file << ":" << info.line << ": ";
|
||||
os << info.file << ":" << info.line;
|
||||
#endif
|
||||
return os;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ namespace Catch {
|
||||
CATCH_ATTRIBUTE_NORETURN
|
||||
inline void throwLogicError( const std::string& message, const SourceLineInfo& locationInfo ) {
|
||||
std::ostringstream oss;
|
||||
oss << "Internal Catch error: '" << message << "' at: " << locationInfo;
|
||||
oss << locationInfo << ": Internal Catch error: '" << message << "'";
|
||||
throw std::logic_error( oss.str() );
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "catch_test_case_info.hpp"
|
||||
#include "catch_tags.hpp"
|
||||
#include "catch_version.hpp"
|
||||
#include "catch_line_wrap.hpp"
|
||||
|
||||
#include "../reporters/catch_reporter_basic.hpp"
|
||||
#include "../reporters/catch_reporter_xml.hpp"
|
||||
|
@@ -49,8 +49,17 @@ namespace Catch
|
||||
std::string name;
|
||||
};
|
||||
struct GroupInfo {
|
||||
GroupInfo( std::string const& _name ) : name( _name ) {}
|
||||
GroupInfo( std::string const& _name,
|
||||
std::size_t _groupIndex,
|
||||
std::size_t _groupsCount )
|
||||
: name( _name ),
|
||||
groupIndex( _groupIndex ),
|
||||
groupsCounts( _groupsCount )
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
std::size_t groupIndex;
|
||||
std::size_t groupsCounts;
|
||||
};
|
||||
|
||||
struct SectionInfo {
|
||||
@@ -174,7 +183,7 @@ namespace Catch
|
||||
struct IStreamingReporter : IShared {
|
||||
virtual ~IStreamingReporter();
|
||||
|
||||
// Implementing class must also provide the following static methid:
|
||||
// Implementing class must also provide the following static method:
|
||||
// static std::string getDescription();
|
||||
|
||||
virtual ReporterPreferences getPreferences() const = 0;
|
||||
|
20
include/internal/catch_line_wrap.h
Normal file
20
include/internal/catch_line_wrap.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Created by Phil on 11/1/2013.
|
||||
* Copyright 2013 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_LINE_WRAP_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
void wrapLongStrings( std::ostream& stream, const std::string& str, std::size_t columns, std::size_t indent = 0 );
|
||||
std::string wrapLongStrings( const std::string& str, std::size_t columns, std::size_t indent = 0 );
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_LINE_WRAP_H_INCLUDED
|
67
include/internal/catch_line_wrap.hpp
Normal file
67
include/internal/catch_line_wrap.hpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Created by Phil on 11/1/2013.
|
||||
* Copyright 2013 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_LINE_WRAP_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_LINE_WRAP_HPP_INCLUDED
|
||||
|
||||
#include "catch_line_wrap.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
namespace {
|
||||
inline void addIndent( std::ostream& os, std::size_t indent ) {
|
||||
while( indent-- > 0 )
|
||||
os << ' ';
|
||||
}
|
||||
|
||||
inline void recursivelyWrapLine( std::ostream& os, std::string paragraph, std::size_t columns, std::size_t indent ) {
|
||||
std::size_t width = columns-indent;
|
||||
std::size_t tab = 0;
|
||||
std::size_t wrapPoint = width;
|
||||
for( std::size_t pos = 0; pos < paragraph.size(); ++pos ) {
|
||||
if( pos == width ) {
|
||||
addIndent( os, indent );
|
||||
os << paragraph.substr( 0, wrapPoint ) << "\n";
|
||||
return recursivelyWrapLine( os, paragraph.substr( wrapPoint+1 ), columns, indent+tab );
|
||||
}
|
||||
if( paragraph[pos] == '\t' ) {
|
||||
tab = pos;
|
||||
paragraph = paragraph.substr( 0, tab ) + paragraph.substr( tab+1 );
|
||||
pos--;
|
||||
}
|
||||
else if( paragraph[pos] == ' ' ) {
|
||||
wrapPoint = pos;
|
||||
}
|
||||
}
|
||||
addIndent( os, indent );
|
||||
os << paragraph;
|
||||
}
|
||||
}
|
||||
|
||||
void wrapLongStrings( std::ostream& stream, const std::string& str, std::size_t columns, std::size_t indent ) {
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type newline = str.find_first_of( '\n' );
|
||||
while( newline != std::string::npos ) {
|
||||
std::string paragraph = str.substr( pos, newline-pos );
|
||||
recursivelyWrapLine( stream, paragraph, columns, indent );
|
||||
stream << "\n";
|
||||
pos = newline+1;
|
||||
newline = str.find_first_of( '\n', pos );
|
||||
}
|
||||
if( pos != str.size() )
|
||||
recursivelyWrapLine( stream, str.substr( pos, str.size()-pos ), columns, indent );
|
||||
}
|
||||
|
||||
std::string wrapLongStrings( const std::string& str, std::size_t columns, std::size_t indent ) {
|
||||
std::ostringstream oss;
|
||||
wrapLongStrings( oss, str, columns, indent );
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_LINE_WRAP_HPP_INCLUDED
|
@@ -16,7 +16,7 @@ namespace Catch {
|
||||
NotImplementedException::NotImplementedException( const SourceLineInfo& lineInfo )
|
||||
: m_lineInfo( lineInfo ) {
|
||||
std::ostringstream oss;
|
||||
oss << lineInfo << "function ";
|
||||
oss << lineInfo << ": function ";
|
||||
oss << "not implemented";
|
||||
m_what = oss.str();
|
||||
}
|
||||
|
@@ -80,27 +80,27 @@ namespace Catch {
|
||||
m_context.setConfig( m_prevConfig );
|
||||
}
|
||||
|
||||
void testGroupStarting( std::string const& testSpec ) {
|
||||
m_reporter->testGroupStarting( GroupInfo( testSpec ) );
|
||||
void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
|
||||
m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
|
||||
}
|
||||
void testGroupEnded( std::string const& testSpec, Totals const& totals ) {
|
||||
m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec ), totals, aborting() ) );
|
||||
void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
|
||||
m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
|
||||
}
|
||||
|
||||
Totals runMatching( const std::string& testSpec ) {
|
||||
Totals runMatching( const std::string& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
|
||||
|
||||
std::vector<TestCase> matchingTests = getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec );
|
||||
|
||||
Totals totals;
|
||||
|
||||
testGroupStarting( testSpec );
|
||||
testGroupStarting( testSpec, groupIndex, groupsCount );
|
||||
|
||||
std::vector<TestCase>::const_iterator it = matchingTests.begin();
|
||||
std::vector<TestCase>::const_iterator itEnd = matchingTests.end();
|
||||
for(; it != itEnd; ++it )
|
||||
totals += runTest( *it );
|
||||
|
||||
testGroupEnded( testSpec, totals );
|
||||
testGroupEnded( testSpec, totals, groupIndex, groupsCount );
|
||||
return totals;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user