From b2c9a681bba484a8edcec5f40472ca3aabf6a645 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 13 Jun 2016 10:08:25 -0400 Subject: [PATCH] Added --list-tests-and-sources --- include/internal/catch_commandline.hpp | 4 ++++ include/internal/catch_config.hpp | 3 +++ include/internal/catch_list.hpp | 16 +++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 978cf078..9395a672 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -182,6 +182,10 @@ namespace Catch { .describe( "list all/matching test cases names only" ) .bind( &ConfigData::listTestNamesOnly ); + cli["--list-tests-and-sources"] + .describe( "list all/matching test cases and their source files" ) + .bind( &ConfigData::listTestSources ); + cli["--list-reporters"] .describe( "list all reporters" ) .bind( &ConfigData::listReporters ); diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 39d406b2..22a50d0c 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -33,6 +33,7 @@ namespace Catch { listReporters( false ), listTestNamesAndSources( false ), listTestNamesOnly( false ), + listTestSources( false ), showSuccessfulTests( false ), shouldDebugBreak( false ), noThrow( false ), @@ -52,6 +53,7 @@ namespace Catch { bool listTags; bool listReporters; bool listTestNamesAndSources; + bool listTestSources; bool listTestNamesOnly; bool showSuccessfulTests; @@ -111,6 +113,7 @@ namespace Catch { bool listTests() const { return m_data.listTests; } bool listTestNamesAndSources() const { return m_data.listTestNamesAndSources; } bool listTestNamesOnly() const { return m_data.listTestNamesOnly; } + bool listTestSources() const { return m_data.listTestSources; } bool listTags() const { return m_data.listTags; } bool listReporters() const { return m_data.listReporters; } diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp index e2d36e3b..a25d50ca 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.hpp @@ -19,13 +19,15 @@ namespace Catch { - inline std::size_t listTests( Config const& config ) { + inline std::size_t listTests( Config const& config, const bool includeSources ) { TestSpec testSpec = config.testSpec(); if( config.testSpec().hasFilters() ) + if( !includeSources ) Catch::cout() << "Matching test cases:\n"; else { - Catch::cout() << "All available test cases:\n"; + if( !includeSources ) + Catch::cout() << "All available test cases:\n"; testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); } @@ -48,6 +50,8 @@ namespace Catch { Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; if( !testCaseInfo.tags.empty() ) Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; + if( includeSources ) + Catch::cout() << testCaseInfo.lineInfo << std::endl; } if( !config.testSpec().hasFilters() ) @@ -163,11 +167,13 @@ namespace Catch { inline Option list( Config const& config ) { Option listedCount; if( config.listTests() ) - listedCount = listedCount.valueOr(0) + listTests( config ); + listedCount = listedCount.valueOr(0) + listTests( config , false ); if( config.listTestNamesAndSources() ) - listedCount = listedCount.valueOr(0) + listTestsNames(config, true); + listedCount = listedCount.valueOr(0) + listTestsNames( config, true ); if( config.listTestNamesOnly() ) - listedCount = listedCount.valueOr(0) + listTestsNames( config , false ); + listedCount = listedCount.valueOr(0) + listTestsNames( config, false ); + if( config.listTestSources() ) + listedCount = listedCount.valueOr(0) + listTests( config, true ); if( config.listTags() ) listedCount = listedCount.valueOr(0) + listTags( config ); if( config.listReporters() )