diff options
| author | Phil Nash | 2013-01-13 21:51:44 +0000 |
|---|---|---|
| committer | Phil Nash | 2013-01-13 21:51:44 +0000 |
| commit | 42aef1d99cc22bb92f80f6e3fb13f2aab071646c (patch) | |
| tree | d836fb3fcffa611982b73045a45e1b61a2675e34 /include/internal | |
| parent | e9305ecd65d0b9a6983dde6b33b6edb19b6633d5 (diff) | |
| download | catch3-42aef1d99cc22bb92f80f6e3fb13f2aab071646c.tar.gz | |
Fairly major reworking of console reporter (still in progress).
Changed reporter interface a bit.
Diffstat (limited to 'include/internal')
| -rw-r--r-- | include/internal/catch_commandline.hpp | 2 | ||||
| -rw-r--r-- | include/internal/catch_common.h | 6 | ||||
| -rw-r--r-- | include/internal/catch_impl.hpp | 1 | ||||
| -rw-r--r-- | include/internal/catch_interfaces_reporter.h | 13 | ||||
| -rw-r--r-- | include/internal/catch_line_wrap.h | 20 | ||||
| -rw-r--r-- | include/internal/catch_line_wrap.hpp | 67 | ||||
| -rw-r--r-- | include/internal/catch_notimplemented_exception.hpp | 2 | ||||
| -rw-r--r-- | include/internal/catch_runner_impl.hpp | 14 |
8 files changed, 111 insertions, 14 deletions
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 8c88ee27..660cbffe 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -16,7 +16,7 @@ namespace Catch { class Command { public: Command(){} - + explicit Command( const std::string& name ) : m_name( name ) { } diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index ec8cd2e9..a575b4fa 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -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() ); } } diff --git a/include/internal/catch_impl.hpp b/include/internal/catch_impl.hpp index b6da5488..f8f2baa4 100644 --- a/include/internal/catch_impl.hpp +++ b/include/internal/catch_impl.hpp @@ -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" diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index 29c6a7a9..17974a22 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -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; diff --git a/include/internal/catch_line_wrap.h b/include/internal/catch_line_wrap.h new file mode 100644 index 00000000..1197fb0b --- /dev/null +++ b/include/internal/catch_line_wrap.h @@ -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 diff --git a/include/internal/catch_line_wrap.hpp b/include/internal/catch_line_wrap.hpp new file mode 100644 index 00000000..c6e03d20 --- /dev/null +++ b/include/internal/catch_line_wrap.hpp @@ -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 diff --git a/include/internal/catch_notimplemented_exception.hpp b/include/internal/catch_notimplemented_exception.hpp index f051ed3d..36368e8c 100644 --- a/include/internal/catch_notimplemented_exception.hpp +++ b/include/internal/catch_notimplemented_exception.hpp @@ -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(); } diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp index 8c94aa22..03f1fcde 100644 --- a/include/internal/catch_runner_impl.hpp +++ b/include/internal/catch_runner_impl.hpp @@ -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; } |