--list-test-names-and-sources functionality

This commit is contained in:
Cyberboss 2016-06-05 15:41:19 -04:00
parent f666f5f0ae
commit 406e568d80
3 changed files with 28 additions and 17 deletions

View File

@ -174,6 +174,10 @@ namespace Catch {
.bind( &ConfigData::filenamesAsTags );
// Less common commands which don't have a short form
cli["--list-test-names-and-sources"]
.describe("list all/matching test cases names along with their source files")
.bind(&ConfigData::listTestNamesAndSources);
cli["--list-test-names-only"]
.describe( "list all/matching test cases names only" )
.bind( &ConfigData::listTestNamesOnly );

View File

@ -31,6 +31,7 @@ namespace Catch {
: listTests( false ),
listTags( false ),
listReporters( false ),
listTestNamesAndSources( false ),
listTestNamesOnly( false ),
showSuccessfulTests( false ),
shouldDebugBreak( false ),
@ -50,6 +51,7 @@ namespace Catch {
bool listTests;
bool listTags;
bool listReporters;
bool listTestNamesAndSources;
bool listTestNamesOnly;
bool showSuccessfulTests;
@ -107,6 +109,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 listTags() const { return m_data.listTags; }
bool listReporters() const { return m_data.listReporters; }

View File

@ -57,7 +57,7 @@ namespace Catch {
return matchedTests;
}
inline std::size_t listTestsNamesOnly( Config const& config ) {
inline std::size_t listTestsNames( Config const& config , const bool includeSources ) {
TestSpec testSpec = config.testSpec();
if( !config.testSpec().hasFilters() )
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
@ -69,6 +69,8 @@ namespace Catch {
matchedTests++;
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
Catch::cout() << testCaseInfo.name << std::endl;
if( includeSources )
Catch::cout() << testCaseInfo.lineInfo << std::endl;
}
return matchedTests;
}
@ -163,7 +165,9 @@ namespace Catch {
if( config.listTests() )
listedCount = listedCount.valueOr(0) + listTests( config );
if( config.listTestNamesOnly() )
listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
listedCount = listedCount.valueOr(0) + listTestsNames( config , false );
if( config.listTestNamesAndSources() )
listedCount = listedCount.valueOr(0) + listTestsNames( config , true );
if( config.listTags() )
listedCount = listedCount.valueOr(0) + listTags( config );
if( config.listReporters() )