mirror of https://github.com/catchorg/Catch2.git
Replaced some uses of tbc_text_format with TextFlow (from Clara)
This commit is contained in:
parent
d43024ff6b
commit
b0e3f45a22
|
@ -14,7 +14,6 @@
|
||||||
#include "internal/catch_run_context.hpp"
|
#include "internal/catch_run_context.hpp"
|
||||||
#include "internal/catch_test_spec.hpp"
|
#include "internal/catch_test_spec.hpp"
|
||||||
#include "internal/catch_version.h"
|
#include "internal/catch_version.h"
|
||||||
#include "internal/catch_text.h"
|
|
||||||
#include "internal/catch_interfaces_reporter.h"
|
#include "internal/catch_interfaces_reporter.h"
|
||||||
#include "internal/catch_startup_exception_registry.h"
|
#include "internal/catch_startup_exception_registry.h"
|
||||||
|
|
||||||
|
@ -24,6 +23,8 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
using namespace clara::TextFlow;
|
||||||
|
|
||||||
IStreamingReporterPtr createReporter( std::string const& reporterName, IConfigPtr const& config ) {
|
IStreamingReporterPtr createReporter( std::string const& reporterName, IConfigPtr const& config ) {
|
||||||
auto reporter = getRegistryHub().getReporterRegistry().create( reporterName, config );
|
auto reporter = getRegistryHub().getReporterRegistry().create( reporterName, config );
|
||||||
CATCH_ENFORCE( reporter, "No reporter registered with name: '" << reporterName << "'" );
|
CATCH_ENFORCE( reporter, "No reporter registered with name: '" << reporterName << "'" );
|
||||||
|
@ -120,13 +121,12 @@ namespace Catch {
|
||||||
int applyCommandLine( int argc, char* argv[] ) {
|
int applyCommandLine( int argc, char* argv[] ) {
|
||||||
auto result = m_cli.parse( clara::Args( argc, argv ) );
|
auto result = m_cli.parse( clara::Args( argc, argv ) );
|
||||||
if( !result ) {
|
if( !result ) {
|
||||||
{
|
Catch::cerr()
|
||||||
Colour colourGuard( Colour::Red );
|
<< Colour( Colour::Red )
|
||||||
Catch::cerr()
|
<< "\nError(s) in input:\n"
|
||||||
<< "\nError(s) in input:\n"
|
<< Column( result.errorMessage() ).indent( 2 )
|
||||||
<< Text( result.errorMessage(), TextAttributes().setIndent(2) )
|
<< "\n\n";
|
||||||
<< "\n\n";
|
|
||||||
}
|
|
||||||
Catch::cerr() << m_cli << std::endl;
|
Catch::cerr() << m_cli << std::endl;
|
||||||
return MaxExitCode;
|
return MaxExitCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
||||||
#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
||||||
#endif
|
#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"
|
#include "../external/clara.hpp"
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
#include "catch_interfaces_reporter.h"
|
#include "catch_interfaces_reporter.h"
|
||||||
#include "catch_interfaces_testcase.h"
|
#include "catch_interfaces_testcase.h"
|
||||||
|
|
||||||
#include "catch_text.h"
|
#include "catch_clara.h" // For TextFlow
|
||||||
|
|
||||||
#include "catch_console_colour.hpp"
|
#include "catch_console_colour.hpp"
|
||||||
#include "catch_test_spec_parser.hpp"
|
#include "catch_test_spec_parser.hpp"
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
using namespace clara::TextFlow;
|
||||||
|
|
||||||
std::size_t listTests( Config const& config ) {
|
std::size_t listTests( Config const& config ) {
|
||||||
TestSpec testSpec = config.testSpec();
|
TestSpec testSpec = config.testSpec();
|
||||||
if( config.testSpec().hasFilters() )
|
if( config.testSpec().hasFilters() )
|
||||||
|
@ -31,37 +34,31 @@ namespace Catch {
|
||||||
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t matchedTests = 0;
|
auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
||||||
TextAttributes nameAttr, descAttr, tagsAttr;
|
|
||||||
nameAttr.setInitialIndent( 2 ).setIndent( 4 );
|
|
||||||
descAttr.setIndent( 4 );
|
|
||||||
tagsAttr.setIndent( 6 );
|
|
||||||
|
|
||||||
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
|
||||||
for( auto const& testCaseInfo : matchedTestCases ) {
|
for( auto const& testCaseInfo : matchedTestCases ) {
|
||||||
matchedTests++;
|
|
||||||
Colour::Code colour = testCaseInfo.isHidden()
|
Colour::Code colour = testCaseInfo.isHidden()
|
||||||
? Colour::SecondaryText
|
? Colour::SecondaryText
|
||||||
: Colour::None;
|
: Colour::None;
|
||||||
Colour colourGuard( colour );
|
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 ) {
|
if( config.verbosity() >= Verbosity::High ) {
|
||||||
Catch::cout() << " " << testCaseInfo.lineInfo << std::endl;
|
std::string description = testCaseInfo.description.empty()
|
||||||
std::string description = testCaseInfo.description;
|
? std::string( "(NO DESCRIPTION)" )
|
||||||
if( description == "" )
|
: testCaseInfo.description;
|
||||||
description = "(NO DESCRIPTION)";
|
Catch::cout()
|
||||||
Catch::cout() << Text( description, descAttr ) << std::endl;
|
<< " " << testCaseInfo.lineInfo << "\n"
|
||||||
|
<< Column( description ).indent( 4 ) << "\n";
|
||||||
}
|
}
|
||||||
if( !testCaseInfo.tags.empty() )
|
if( !testCaseInfo.tags.empty() )
|
||||||
Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
|
Catch::cout() << Column( testCaseInfo.tagsAsString ).indent( 6 ) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !config.testSpec().hasFilters() )
|
if( !config.testSpec().hasFilters() )
|
||||||
Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl;
|
Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl;
|
||||||
else
|
else
|
||||||
Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl;
|
Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl;
|
||||||
return matchedTests;
|
return matchedTestCases.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t listTestsNamesOnly( Config const& config ) {
|
std::size_t listTestsNamesOnly( Config const& config ) {
|
||||||
|
@ -120,10 +117,10 @@ namespace Catch {
|
||||||
for( auto const& tagCount : tagCounts ) {
|
for( auto const& tagCount : tagCounts ) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << " " << std::setw(2) << tagCount.second.count << " ";
|
oss << " " << std::setw(2) << tagCount.second.count << " ";
|
||||||
Text wrapper( tagCount.second.all(), TextAttributes()
|
auto wrapper = Column( tagCount.second.all() )
|
||||||
.setInitialIndent( 0 )
|
.initialIndent( 0 )
|
||||||
.setIndent( oss.str().size() )
|
.indent( oss.str().size() )
|
||||||
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
|
.width( CATCH_CONFIG_CONSOLE_WIDTH-10 );
|
||||||
Catch::cout() << oss.str() << wrapper << '\n';
|
Catch::cout() << oss.str() << wrapper << '\n';
|
||||||
}
|
}
|
||||||
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
|
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
|
||||||
|
@ -138,11 +135,12 @@ namespace Catch {
|
||||||
maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
|
maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
|
||||||
|
|
||||||
for( auto const& factoryKvp : getRegistryHub().getReporterRegistry().getFactories() ) {
|
for( auto const& factoryKvp : getRegistryHub().getReporterRegistry().getFactories() ) {
|
||||||
Text wrapper( factoryKvp.second->getDescription(), TextAttributes()
|
auto wrapper = Column( factoryKvp.second->getDescription() )
|
||||||
.setInitialIndent( 0 )
|
.initialIndent( 0 )
|
||||||
.setIndent( 7+maxNameLen )
|
.indent( 7+maxNameLen )
|
||||||
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
|
.width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 );
|
||||||
Catch::cout() << " "
|
Catch::cout()
|
||||||
|
<< " "
|
||||||
<< factoryKvp.first
|
<< factoryKvp.first
|
||||||
<< ':'
|
<< ':'
|
||||||
<< std::string( maxNameLen - factoryKvp.first.size() + 2, ' ' )
|
<< std::string( maxNameLen - factoryKvp.first.size() + 2, ' ' )
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
using namespace clara::TextFlow;
|
||||||
|
|
||||||
struct TeamCityReporter : StreamingReporterBase {
|
struct TeamCityReporter : StreamingReporterBase {
|
||||||
TeamCityReporter( ReporterConfig const& _config )
|
TeamCityReporter( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config )
|
: StreamingReporterBase( _config )
|
||||||
|
@ -194,9 +196,9 @@ namespace Catch {
|
||||||
i+=2;
|
i+=2;
|
||||||
else
|
else
|
||||||
i = 0;
|
i = 0;
|
||||||
os << Text( _string, TextAttributes()
|
os << Column( _string )
|
||||||
.setIndent( indent+i)
|
.indent( indent+i)
|
||||||
.setInitialIndent( indent ) ) << "\n";
|
.initialIndent( indent ) << "\n";
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
bool m_headerPrintedForThisSection = false;
|
bool m_headerPrintedForThisSection = false;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
#include "internal/catch_text.h" // temporarily
|
||||||
#include "../include/reporters/catch_reporter_teamcity.hpp"
|
#include "../include/reporters/catch_reporter_teamcity.hpp"
|
||||||
#include "../include/reporters/catch_reporter_tap.hpp"
|
#include "../include/reporters/catch_reporter_tap.hpp"
|
||||||
#include "../include/reporters/catch_reporter_automake.hpp"
|
#include "../include/reporters/catch_reporter_automake.hpp"
|
||||||
|
|
Loading…
Reference in New Issue