Merged implemention of #934, but using 'verbose' option on command line instead.

(see 616f7235ef on master for original merge)
This commit is contained in:
Baruch Burstein 2017-06-20 22:14:38 +03:00 committed by Phil Nash
parent 9382534d59
commit 1e7000ed55
4 changed files with 52 additions and 24 deletions

View File

@ -73,6 +73,18 @@ namespace Catch {
return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" ); return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
return ParserResult::ok( ParseResultType::Matched ); return ParserResult::ok( ParseResultType::Matched );
}; };
auto const setVerbosity = [&]( std::string const& verbosity ) {
auto lcVerbosity = toLower( verbosity );
if( lcVerbosity == "quiet" )
config.verbosity = Verbosity::Quiet;
else if( lcVerbosity == "normal" )
config.verbosity = Verbosity::Normal;
else if( lcVerbosity == "high" )
config.verbosity = Verbosity::High;
else
return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" );
return ParserResult::ok( ParseResultType::Matched );
};
auto cli auto cli
= ExeName( config.processName ) = ExeName( config.processName )
@ -125,6 +137,9 @@ namespace Catch {
+ Opt( config.sectionsToRun, "section name" ) + Opt( config.sectionsToRun, "section name" )
["-c"]["--section"] ["-c"]["--section"]
( "specify section to run" ) ( "specify section to run" )
+ Opt( setVerbosity, "quiet|normal|high" )
["-v"]["--verbosity"]
( "set output verbosity" )
+ Opt( config.listTestNamesOnly ) + Opt( config.listTestNamesOnly )
["--list-test-names-only"] ["--list-test-names-only"]
( "list all/matching test cases names only" ) ( "list all/matching test cases names only" )

View File

@ -40,7 +40,7 @@ namespace Catch {
int abortAfter = -1; int abortAfter = -1;
unsigned int rngSeed = 0; unsigned int rngSeed = 0;
Verbosity::Level verbosity = Verbosity::Normal; Verbosity verbosity = Verbosity::Normal;
WarnAbout::What warnings = WarnAbout::Nothing; WarnAbout::What warnings = WarnAbout::Nothing;
ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter; ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder; RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
@ -86,6 +86,8 @@ namespace Catch {
bool listTags() const { return m_data.listTags; } bool listTags() const { return m_data.listTags; }
bool listReporters() const { return m_data.listReporters; } bool listReporters() const { return m_data.listReporters; }
Verbosity verbosity() const { return m_data.verbosity; }
std::string getProcessName() const { return m_data.processName; } std::string getProcessName() const { return m_data.processName; }
std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; } std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }

View File

@ -17,11 +17,11 @@
namespace Catch { namespace Catch {
struct Verbosity { enum Level { enum class Verbosity {
NoOutput = 0, Quiet = 0,
Quiet, Normal,
Normal High
}; }; };
struct WarnAbout { enum What { struct WarnAbout { enum What {
Nothing = 0x00, Nothing = 0x00,

View File

@ -30,8 +30,9 @@ namespace Catch {
} }
std::size_t matchedTests = 0; std::size_t matchedTests = 0;
TextAttributes nameAttr, tagsAttr; TextAttributes nameAttr, descAttr, tagsAttr;
nameAttr.setInitialIndent( 2 ).setIndent( 4 ); nameAttr.setInitialIndent( 2 ).setIndent( 4 );
descAttr.setIndent( 4 );
tagsAttr.setIndent( 6 ); tagsAttr.setIndent( 6 );
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
@ -43,6 +44,13 @@ namespace Catch {
Colour colourGuard( colour ); Colour colourGuard( colour );
Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
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;
}
if( !testCaseInfo.tags.empty() ) if( !testCaseInfo.tags.empty() )
Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
} }
@ -63,9 +71,12 @@ namespace Catch {
for( auto const& testCaseInfo : matchedTestCases ) { for( auto const& testCaseInfo : matchedTestCases ) {
matchedTests++; matchedTests++;
if( startsWith( testCaseInfo.name, '#' ) ) if( startsWith( testCaseInfo.name, '#' ) )
Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl; Catch::cout() << '"' << testCaseInfo.name << '"';
else else
Catch::cout() << testCaseInfo.name << std::endl; Catch::cout() << testCaseInfo.name;
if ( config.verbosity() >= Verbosity::High )
Catch::cout() << "\t@" << testCaseInfo.lineInfo;
Catch::cout() << std::endl;
} }
return matchedTests; return matchedTests;
} }