Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2013-11-26 20:57:34 +0000
committerPhil Nash2013-11-26 20:57:34 +0000
commit782c2b58913fa8d95ba2c7155ca2a40cbad3ee6b (patch)
tree41a284b6a49637074e7958a006b6ca14ac149118 /include
parent993430a3c4778d49acba7255e4f705d3b29bb0f3 (diff)
downloadcatch3-782c2b58913fa8d95ba2c7155ca2a40cbad3ee6b.tar.gz
Added ability to load names of tests to run from a file
- use -f to specify filename. Blank lines and lines starting with # are ignored - also added --list-test-names-only to list test names out to file in a form that can be immediate read in by -f
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_commandline.hpp41
-rw-r--r--include/internal/catch_config.hpp3
-rw-r--r--include/internal/catch_list.hpp16
3 files changed, 52 insertions, 8 deletions
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 3b32f2b2..5b80761f 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -12,6 +12,8 @@
#include "catch_common.h"
#include "clara.h"
+#include <fstream>
+
namespace Catch {
inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
@@ -38,7 +40,18 @@ namespace Catch {
? ShowDurations::Always
: ShowDurations::Never;
}
-
+ inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
+ std::ifstream f( _filename.c_str() );
+ if( !f.is_open() )
+ throw std::domain_error( "Unable to load input file: " + _filename );
+
+ std::string line;
+ while( std::getline( f, line ) ) {
+ line = trim(line);
+ if( !line.empty() && !startsWith( line, "#" ) )
+ addTestOrTags( config, line );
+ }
+ }
inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
@@ -53,19 +66,15 @@ namespace Catch {
.longOpt( "help" );
cli.bind( &ConfigData::listTests )
- .describe( "list all (or matching) test cases" )
+ .describe( "list all/matching test cases" )
.shortOpt( "l")
.longOpt( "list-tests" );
cli.bind( &ConfigData::listTags )
- .describe( "list all (or matching) tags" )
+ .describe( "list all/matching tags" )
.shortOpt( "t")
.longOpt( "list-tags" );
- cli.bind( &ConfigData::listReporters )
- .describe( "list all reporters" )
- .longOpt( "list-reporters" );
-
cli.bind( &ConfigData::showSuccessfulTests )
.describe( "include successful tests in output" )
.shortOpt( "s")
@@ -88,7 +97,7 @@ namespace Catch {
.hint( "filename" );
cli.bind( &ConfigData::reporterName )
- .describe( "reporter to use - defaults to console" )
+ .describe( "reporter to use (defaults to console)" )
.shortOpt( "r")
.longOpt( "reporter" )
// .hint( "name[:filename]" );
@@ -133,6 +142,22 @@ namespace Catch {
.longOpt( "durations" )
.hint( "yes/no" );
+ cli.bind( &loadTestNamesFromFile )
+ .describe( "load test names to run from a file" )
+ .shortOpt( "f")
+ .longOpt( "input-file" )
+ .hint( "filename" );
+
+ // Less common commands which don't have a short form
+ cli.bind( &ConfigData::listTestNamesOnly )
+ .describe( "list all/matching test cases names only" )
+ .longOpt( "list-test-names-only" );
+
+ cli.bind( &ConfigData::listReporters )
+ .describe( "list all reporters" )
+ .longOpt( "list-reporters" );
+
+
return cli;
}
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index f561b260..51b5913a 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -30,6 +30,7 @@ namespace Catch {
: listTests( false ),
listTags( false ),
listReporters( false ),
+ listTestNamesOnly( false ),
showSuccessfulTests( false ),
shouldDebugBreak( false ),
noThrow( false ),
@@ -43,6 +44,7 @@ namespace Catch {
bool listTests;
bool listTags;
bool listReporters;
+ bool listTestNamesOnly;
bool showSuccessfulTests;
bool shouldDebugBreak;
@@ -112,6 +114,7 @@ namespace Catch {
}
bool listTests() const { return m_data.listTests; }
+ bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
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 a0b0ac4e..70d7668c 100644
--- a/include/internal/catch_list.hpp
+++ b/include/internal/catch_list.hpp
@@ -60,6 +60,20 @@ namespace Catch {
return matchedTests;
}
+ inline std::size_t listTestsNamesOnly( Config const& config ) {
+ std::size_t matchedTests = 0;
+ std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
+ for( std::vector<TestCase>::const_iterator it = allTests.begin(), itEnd = allTests.end();
+ it != itEnd;
+ ++it )
+ if( matchesFilters( config.filters(), *it ) ) {
+ matchedTests++;
+ TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
+ std::cout << testCaseInfo.name << std::endl;
+ }
+ return matchedTests;
+ }
+
inline std::size_t listTags( Config const& config ) {
if( config.filters().empty() )
std::cout << "All available tags:\n";
@@ -131,6 +145,8 @@ namespace Catch {
Option<std::size_t> listedCount;
if( config.listTests() )
listedCount = listedCount.valueOr(0) + listTests( config );
+ if( config.listTestNamesOnly() )
+ listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
if( config.listTags() )
listedCount = listedCount.valueOr(0) + listTags( config );
if( config.listReporters() )