Replaced some uses of tbc_text_format with TextFlow (from Clara)

This commit is contained in:
Phil Nash 2017-07-18 20:27:42 +01:00
parent d43024ff6b
commit b0e3f45a22
5 changed files with 41 additions and 40 deletions

View File

@ -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;
}

View File

@ -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"

View File

@ -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<TestCase> 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, ' ' )

View File

@ -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;

View File

@ -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"