From 200b8b6fc05934149d9d4fa56eefbfd613ee73ea Mon Sep 17 00:00:00 2001 From: Tristan Stenner Date: Sat, 15 Feb 2020 20:42:57 +0100 Subject: [PATCH] Add command line option 'never' to --wait-for-keypress (#1866) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Martin Hořeňovský --- docs/command-line.md | 2 +- include/internal/catch_commandline.cpp | 8 +- .../Baselines/compact.sw.approved.txt | 10 ++ .../Baselines/console.std.approved.txt | 2 +- .../Baselines/console.sw.approved.txt | 98 ++++++++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 4 +- .../Baselines/sonarqube.sw.approved.txt | 2 + .../SelfTest/Baselines/xml.sw.approved.txt | 129 +++++++++++++++++- .../IntrospectiveTests/CmdLine.tests.cpp | 24 ++++ 9 files changed, 270 insertions(+), 9 deletions(-) diff --git a/docs/command-line.md b/docs/command-line.md index 7ec2fbb3..dcc6a79a 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -271,7 +271,7 @@ See [The LibIdentify repo for more information and examples](https://github.com/ ## Wait for key before continuing -
--wait-for-keypress <start|exit|both>
+
--wait-for-keypress <never|start|exit|both>
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing - either before running any tests, after running all tests - or both, depending on the argument. diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp index b0412d50..a4010850 100644 --- a/include/internal/catch_commandline.cpp +++ b/include/internal/catch_commandline.cpp @@ -91,14 +91,16 @@ namespace Catch { }; auto const setWaitForKeypress = [&]( std::string const& keypress ) { auto keypressLc = toLower( keypress ); - if( keypressLc == "start" ) + if (keypressLc == "never") + config.waitForKeypress = WaitForKeypress::Never; + else if( keypressLc == "start" ) config.waitForKeypress = WaitForKeypress::BeforeStart; else if( keypressLc == "exit" ) config.waitForKeypress = WaitForKeypress::BeforeExit; else if( keypressLc == "both" ) config.waitForKeypress = WaitForKeypress::BeforeStartAndExit; else - return ParserResult::runtimeError( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" ); + return ParserResult::runtimeError( "keypress argument must be one of: never, start, exit or both. '" + keypress + "' not recognised" ); return ParserResult::ok( ParseResultType::Matched ); }; auto const setVerbosity = [&]( std::string const& verbosity ) { @@ -198,7 +200,7 @@ namespace Catch { | Opt( config.libIdentify ) ["--libidentify"] ( "report name and version according to libidentify standard" ) - | Opt( setWaitForKeypress, "start|exit|both" ) + | Opt( setWaitForKeypress, "never|start|exit|both" ) ["--wait-for-keypress"] ( "waits for a keypress before exiting" ) | Opt( config.benchmarkSamples, "samples" ) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index c12ce081..c61028a2 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1088,6 +1088,16 @@ CmdLine.tests.cpp:: passed: cli.parse({"test", "-x", "2"}) for: {?} CmdLine.tests.cpp:: passed: config.abortAfter == 2 for: 2 == 2 CmdLine.tests.cpp:: passed: !result for: true CmdLine.tests.cpp:: passed: result.errorMessage(), Contains("convert") && Contains("oops") for: "Unable to convert 'oops' to destination type" ( contains: "convert" and contains: "oops" ) +CmdLine.tests.cpp:: passed: cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) for: {?} +CmdLine.tests.cpp:: passed: config.waitForKeypress == std::get<1>(input) for: 0 == 0 +CmdLine.tests.cpp:: passed: cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) for: {?} +CmdLine.tests.cpp:: passed: config.waitForKeypress == std::get<1>(input) for: 1 == 1 +CmdLine.tests.cpp:: passed: cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) for: {?} +CmdLine.tests.cpp:: passed: config.waitForKeypress == std::get<1>(input) for: 2 == 2 +CmdLine.tests.cpp:: passed: cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) for: {?} +CmdLine.tests.cpp:: passed: config.waitForKeypress == std::get<1>(input) for: 3 == 3 +CmdLine.tests.cpp:: passed: !result for: true +CmdLine.tests.cpp:: passed: result.errorMessage(), Contains("never") && Contains("both") for: "keypress argument must be one of: never, start, exit or both. 'sometimes' not recognised" ( contains: "never" and contains: "both" ) CmdLine.tests.cpp:: passed: cli.parse({"test", "-e"}) for: {?} CmdLine.tests.cpp:: passed: config.noThrow for: true CmdLine.tests.cpp:: passed: cli.parse({"test", "--nothrow"}) for: {?} diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index f62b2e48..ba4f79d7 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 306 | 232 passed | 70 failed | 4 failed as expected -assertions: 1666 | 1514 passed | 131 failed | 21 failed as expected +assertions: 1676 | 1524 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 68357ef0..e06366c4 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -7834,6 +7834,102 @@ with expansion: "Unable to convert 'oops' to destination type" ( contains: "convert" and contains: "oops" ) +------------------------------------------------------------------------------- +Process can be configured on command line + abort + wait-for-keypress + Accepted options +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) ) +with expansion: + {?} + +CmdLine.tests.cpp:: PASSED: + REQUIRE( config.waitForKeypress == std::get<1>(input) ) +with expansion: + 0 == 0 + +------------------------------------------------------------------------------- +Process can be configured on command line + abort + wait-for-keypress + Accepted options +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) ) +with expansion: + {?} + +CmdLine.tests.cpp:: PASSED: + REQUIRE( config.waitForKeypress == std::get<1>(input) ) +with expansion: + 1 == 1 + +------------------------------------------------------------------------------- +Process can be configured on command line + abort + wait-for-keypress + Accepted options +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) ) +with expansion: + {?} + +CmdLine.tests.cpp:: PASSED: + REQUIRE( config.waitForKeypress == std::get<1>(input) ) +with expansion: + 2 == 2 + +------------------------------------------------------------------------------- +Process can be configured on command line + abort + wait-for-keypress + Accepted options +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) ) +with expansion: + {?} + +CmdLine.tests.cpp:: PASSED: + REQUIRE( config.waitForKeypress == std::get<1>(input) ) +with expansion: + 3 == 3 + +------------------------------------------------------------------------------- +Process can be configured on command line + abort + wait-for-keypress + invalid options are reported +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + CHECK( !result ) +with expansion: + true + +CmdLine.tests.cpp:: PASSED: + REQUIRE_THAT( result.errorMessage(), Contains("never") && Contains("both") ) +with expansion: + "keypress argument must be one of: never, start, exit or both. 'sometimes' + not recognised" ( contains: "never" and contains: "both" ) + ------------------------------------------------------------------------------- Process can be configured on command line nothrow @@ -13321,5 +13417,5 @@ Misc.tests.cpp:: PASSED: =============================================================================== test cases: 306 | 216 passed | 86 failed | 4 failed as expected -assertions: 1683 | 1514 passed | 148 failed | 21 failed as expected +assertions: 1693 | 1524 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 59119a25..6dd03a98 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1004,6 +1004,8 @@ Message.tests.cpp: + + diff --git a/projects/SelfTest/Baselines/sonarqube.sw.approved.txt b/projects/SelfTest/Baselines/sonarqube.sw.approved.txt index 1d7e92bf..1f89e99c 100644 --- a/projects/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/projects/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -52,6 +52,8 @@ + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 1021e168..4eed7125 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -9878,6 +9878,131 @@ Nor would this +
+
+
+ + + cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) + + + {?} + + + + + config.waitForKeypress == std::get<1>(input) + + + 0 == 0 + + + +
+ +
+ +
+
+
+
+ + + cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) + + + {?} + + + + + config.waitForKeypress == std::get<1>(input) + + + 1 == 1 + + + +
+ +
+ +
+
+
+
+ + + cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) + + + {?} + + + + + config.waitForKeypress == std::get<1>(input) + + + 2 == 2 + + + +
+ +
+ +
+
+
+
+ + + cli.parse({"test", "--wait-for-keypress", std::get<0>(input)}) + + + {?} + + + + + config.waitForKeypress == std::get<1>(input) + + + 3 == 3 + + + +
+ +
+ +
+
+
+
+ + + !result + + + true + + + + + result.errorMessage(), Contains("never") && Contains("both") + + + "keypress argument must be one of: never, start, exit or both. 'sometimes' not recognised" ( contains: "never" and contains: "both" ) + + + +
+ +
+ +
@@ -15912,7 +16037,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 641f1b29..6e590326 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -412,9 +412,33 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" #ifndef CATCH_CONFIG_DISABLE_MATCHERS REQUIRE_THAT(result.errorMessage(), Contains("convert") && Contains("oops")); +#endif + } + + SECTION("wait-for-keypress") { + SECTION("Accepted options") { + using tuple_type = std::tuple; + auto input = GENERATE(table({ + tuple_type{"never", Catch::WaitForKeypress::Never}, + tuple_type{"start", Catch::WaitForKeypress::BeforeStart}, + tuple_type{"exit", Catch::WaitForKeypress::BeforeExit}, + tuple_type{"both", Catch::WaitForKeypress::BeforeStartAndExit}, + })); + CHECK(cli.parse({"test", "--wait-for-keypress", std::get<0>(input)})); + + REQUIRE(config.waitForKeypress == std::get<1>(input)); + } + + SECTION("invalid options are reported") { + auto result = cli.parse({"test", "--wait-for-keypress", "sometimes"}); + CHECK(!result); + +#ifndef CATCH_CONFIG_DISABLE_MATCHERS + REQUIRE_THAT(result.errorMessage(), Contains("never") && Contains("both")); #endif } } + } SECTION("nothrow") { SECTION("-e") {