From b0e3f45a22d47dfa73710574a505c191baa2fb27 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 18 Jul 2017 20:27:42 +0100 Subject: [PATCH] Replaced some uses of tbc_text_format with TextFlow (from Clara) --- include/catch_session.hpp | 16 +++--- include/internal/catch_clara.h | 2 +- include/internal/catch_list.cpp | 54 +++++++++---------- include/reporters/catch_reporter_teamcity.hpp | 8 +-- projects/SelfTest/TestMain.cpp | 1 + 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/include/catch_session.hpp b/include/catch_session.hpp index 8ebe88ca..05ebff47 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -14,7 +14,6 @@ #include "internal/catch_run_context.hpp" #include "internal/catch_test_spec.hpp" #include "internal/catch_version.h" -#include "internal/catch_text.h" #include "internal/catch_interfaces_reporter.h" #include "internal/catch_startup_exception_registry.h" @@ -24,6 +23,8 @@ namespace Catch { + using namespace clara::TextFlow; + IStreamingReporterPtr createReporter( std::string const& reporterName, IConfigPtr const& config ) { auto reporter = getRegistryHub().getReporterRegistry().create( reporterName, config ); CATCH_ENFORCE( reporter, "No reporter registered with name: '" << reporterName << "'" ); @@ -120,13 +121,12 @@ namespace Catch { int applyCommandLine( int argc, char* argv[] ) { auto result = m_cli.parse( clara::Args( argc, argv ) ); if( !result ) { - { - Colour colourGuard( Colour::Red ); - Catch::cerr() - << "\nError(s) in input:\n" - << Text( result.errorMessage(), TextAttributes().setIndent(2) ) - << "\n\n"; - } + Catch::cerr() + << Colour( Colour::Red ) + << "\nError(s) in input:\n" + << Column( result.errorMessage() ).indent( 2 ) + << "\n\n"; + Catch::cerr() << m_cli << std::endl; return MaxExitCode; } diff --git a/include/internal/catch_clara.h b/include/internal/catch_clara.h index 1aeb4658..abe7626b 100644 --- a/include/internal/catch_clara.h +++ b/include/internal/catch_clara.h @@ -14,7 +14,7 @@ #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH #undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH #endif -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 #include "../external/clara.hpp" diff --git a/include/internal/catch_list.cpp b/include/internal/catch_list.cpp index 8f13be8d..b8c4cc2f 100644 --- a/include/internal/catch_list.cpp +++ b/include/internal/catch_list.cpp @@ -12,7 +12,8 @@ #include "catch_interfaces_reporter.h" #include "catch_interfaces_testcase.h" -#include "catch_text.h" +#include "catch_clara.h" // For TextFlow + #include "catch_console_colour.hpp" #include "catch_test_spec_parser.hpp" @@ -22,6 +23,8 @@ namespace Catch { + using namespace clara::TextFlow; + std::size_t listTests( Config const& config ) { TestSpec testSpec = config.testSpec(); if( config.testSpec().hasFilters() ) @@ -31,37 +34,31 @@ namespace Catch { testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); } - std::size_t matchedTests = 0; - TextAttributes nameAttr, descAttr, tagsAttr; - nameAttr.setInitialIndent( 2 ).setIndent( 4 ); - descAttr.setIndent( 4 ); - tagsAttr.setIndent( 6 ); - - std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); for( auto const& testCaseInfo : matchedTestCases ) { - matchedTests++; Colour::Code colour = testCaseInfo.isHidden() ? Colour::SecondaryText : Colour::None; Colour colourGuard( colour ); - Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; + Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n"; if( config.verbosity() >= Verbosity::High ) { - Catch::cout() << " " << testCaseInfo.lineInfo << std::endl; - std::string description = testCaseInfo.description; - if( description == "" ) - description = "(NO DESCRIPTION)"; - Catch::cout() << Text( description, descAttr ) << std::endl; + std::string description = testCaseInfo.description.empty() + ? std::string( "(NO DESCRIPTION)" ) + : testCaseInfo.description; + Catch::cout() + << " " << testCaseInfo.lineInfo << "\n" + << Column( description ).indent( 4 ) << "\n"; } if( !testCaseInfo.tags.empty() ) - Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; + Catch::cout() << Column( testCaseInfo.tagsAsString ).indent( 6 ) << "\n"; } if( !config.testSpec().hasFilters() ) - Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl; + Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl; else - Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl; - return matchedTests; + Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl; + return matchedTestCases.size(); } std::size_t listTestsNamesOnly( Config const& config ) { @@ -120,10 +117,10 @@ namespace Catch { for( auto const& tagCount : tagCounts ) { std::ostringstream oss; oss << " " << std::setw(2) << tagCount.second.count << " "; - Text wrapper( tagCount.second.all(), TextAttributes() - .setInitialIndent( 0 ) - .setIndent( oss.str().size() ) - .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); + auto wrapper = Column( tagCount.second.all() ) + .initialIndent( 0 ) + .indent( oss.str().size() ) + .width( CATCH_CONFIG_CONSOLE_WIDTH-10 ); Catch::cout() << oss.str() << wrapper << '\n'; } Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; @@ -138,11 +135,12 @@ namespace Catch { maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() ); for( auto const& factoryKvp : getRegistryHub().getReporterRegistry().getFactories() ) { - Text wrapper( factoryKvp.second->getDescription(), TextAttributes() - .setInitialIndent( 0 ) - .setIndent( 7+maxNameLen ) - .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); - Catch::cout() << " " + auto wrapper = Column( factoryKvp.second->getDescription() ) + .initialIndent( 0 ) + .indent( 7+maxNameLen ) + .width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ); + Catch::cout() + << " " << factoryKvp.first << ':' << std::string( maxNameLen - factoryKvp.first.size() + 2, ' ' ) diff --git a/include/reporters/catch_reporter_teamcity.hpp b/include/reporters/catch_reporter_teamcity.hpp index 623ae6a3..82e18660 100644 --- a/include/reporters/catch_reporter_teamcity.hpp +++ b/include/reporters/catch_reporter_teamcity.hpp @@ -23,6 +23,8 @@ namespace Catch { + using namespace clara::TextFlow; + struct TeamCityReporter : StreamingReporterBase { TeamCityReporter( ReporterConfig const& _config ) : StreamingReporterBase( _config ) @@ -194,9 +196,9 @@ namespace Catch { i+=2; else i = 0; - os << Text( _string, TextAttributes() - .setIndent( indent+i) - .setInitialIndent( indent ) ) << "\n"; + os << Column( _string ) + .indent( indent+i) + .initialIndent( indent ) << "\n"; } private: bool m_headerPrintedForThisSection = false; diff --git a/projects/SelfTest/TestMain.cpp b/projects/SelfTest/TestMain.cpp index 4a01441c..10a2ae4d 100644 --- a/projects/SelfTest/TestMain.cpp +++ b/projects/SelfTest/TestMain.cpp @@ -8,6 +8,7 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" +#include "internal/catch_text.h" // temporarily #include "../include/reporters/catch_reporter_teamcity.hpp" #include "../include/reporters/catch_reporter_tap.hpp" #include "../include/reporters/catch_reporter_automake.hpp"