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

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2017-08-15 14:12:11 +0100
committerPhil Nash2017-08-15 14:12:11 +0100
commit70e4af9d444dd9ef074ce74bc2d0ea418db56ac4 (patch)
tree66487b978fc7fbb1fd99d497701e5c7c890eb74a /include
parent8f41bdb92d74ebb817bc326228fc624ca4ea6b59 (diff)
downloadcatch3-70e4af9d444dd9ef074ce74bc2d0ea418db56ac4.tar.gz
Implemented wait-for-keypress option
Diffstat (limited to 'include')
-rw-r--r--include/catch_session.hpp45
-rw-r--r--include/internal/catch_commandline.hpp17
-rw-r--r--include/internal/catch_config.hpp4
-rw-r--r--include/internal/catch_interfaces_config.h6
4 files changed, 55 insertions, 17 deletions
diff --git a/include/catch_session.hpp b/include/catch_session.hpp
index 550f9142..ec3ce7cc 100644
--- a/include/catch_session.hpp
+++ b/include/catch_session.hpp
@@ -142,7 +142,6 @@ namespace Catch {
<< std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
}
-
int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
try {
m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
@@ -207,6 +206,35 @@ namespace Catch {
#endif
int run() {
+ if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
+ Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
+ std::getchar();
+ }
+ int exitCode = runInternal();
+ if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
+ Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
+ std::getchar();
+ }
+ return exitCode;
+ }
+
+ Clara::CommandLine<ConfigData> const& cli() const {
+ return m_cli;
+ }
+ std::vector<Clara::Parser::Token> const& unusedTokens() const {
+ return m_unusedTokens;
+ }
+ ConfigData& configData() {
+ return m_configData;
+ }
+ Config& config() {
+ if( !m_config )
+ m_config = new Config( m_configData );
+ return *m_config;
+ }
+ private:
+
+ int runInternal() {
if( m_configData.showHelp || m_configData.libIdentify )
return 0;
@@ -231,21 +259,6 @@ namespace Catch {
}
}
- Clara::CommandLine<ConfigData> const& cli() const {
- return m_cli;
- }
- std::vector<Clara::Parser::Token> const& unusedTokens() const {
- return m_unusedTokens;
- }
- ConfigData& configData() {
- return m_configData;
- }
- Config& config() {
- if( !m_config )
- m_config = new Config( m_configData );
- return *m_config;
- }
- private:
Clara::CommandLine<ConfigData> m_cli;
std::vector<Clara::Parser::Token> m_unusedTokens;
ConfigData m_configData;
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index 2ea41a00..a5b09695 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -76,6 +76,19 @@ namespace Catch {
else
throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
}
+ inline void setWaitForKeypress( ConfigData& config, std::string const& keypress ) {
+ auto keypressLc = toLower( keypress );
+ if( keypressLc == "start" )
+ config.waitForKeypress = WaitForKeypress::BeforeStart;
+ else if( keypressLc == "exit" )
+ config.waitForKeypress = WaitForKeypress::BeforeExit;
+ else if( keypressLc == "both" )
+ config.waitForKeypress = WaitForKeypress::BeforeStartAndExit;
+ else
+ throw std::runtime_error( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" );
+ };
+
+
inline void forceColour( ConfigData& config ) {
config.useColour = UseColour::Yes;
}
@@ -219,6 +232,10 @@ namespace Catch {
.describe( "report name and version according to libidentify standard" )
.bind( &ConfigData::libIdentify );
+ cli["--wait-for-keypress"]
+ .describe( "waits for a keypress before exiting" )
+ .bind( &setWaitForKeypress, "start|exit|both" );
+
return cli;
}
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index b1275e08..b7f64bf1 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -45,7 +45,8 @@ namespace Catch {
warnings( WarnAbout::Nothing ),
showDurations( ShowDurations::DefaultForReporter ),
runOrder( RunTests::InDeclarationOrder ),
- useColour( UseColour::Auto )
+ useColour( UseColour::Auto ),
+ waitForKeypress( WaitForKeypress::Never )
{}
bool listTests;
@@ -70,6 +71,7 @@ namespace Catch {
ShowDurations::OrNot showDurations;
RunTests::InWhatOrder runOrder;
UseColour::YesOrNo useColour;
+ WaitForKeypress::When waitForKeypress;
std::string outputFilename;
std::string name;
diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h
index 5730a8cd..f65515d1 100644
--- a/include/internal/catch_interfaces_config.h
+++ b/include/internal/catch_interfaces_config.h
@@ -42,6 +42,12 @@ namespace Catch {
Yes,
No
}; };
+ struct WaitForKeypress { enum When {
+ Never,
+ BeforeStart = 1,
+ BeforeExit = 2,
+ BeforeStartAndExit = BeforeStart | BeforeExit
+ }; };
class TestSpec;