Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Added libidentify support, including option for waiting for keypress on exit (and/ or start)

Commit
917a51da6b9923d385c2e441bef1ebedb96cd123
Author
Phil Nash ·
Parents
f06ed856d86c

Files · Download .tar.gz

Changes

 include/catch_session.hpp                  | 56 +++++++++++++++++++++---------
 include/internal/catch_commandline.cpp     | 18 ++++++++++
 include/internal/catch_config.hpp          |  2 ++
 include/internal/catch_interfaces_config.h |  6 ++++
 4 files changed, 65 insertions(+), 17 deletions(-)

diff --git a/include/catch_session.hpp b/include/catch_session.hpp
index 61b99049..fb1eb8a5 100644
--- a/include/catch_session.hpp
+++ b/include/catch_session.hpp
@@ -22,6 +22,7 @@
 #include <fstream>
 #include <cstdlib>
 #include <limits>
+#include <iomanip>
 
 namespace Catch {
 
@@ -121,6 +122,13 @@ namespace Catch {
                     << m_cli << std::endl
                     << "For more detailed usage please see the project docs\n" << std::endl;
         }
+        void libIdentify() {
+            Catch::cout()
+                    << std::left << std::setw(16) << "description: " << "A Catch test executable\n"
+                    << std::left << std::setw(16) << "category: " << "testframework\n"
+                    << std::left << std::setw(16) << "framework: " << "Catch Test\n"
+                    << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
+        }
 
         int applyCommandLine( int argc, char* argv[] ) {
             auto result = m_cli.parse( clara::Args( argc, argv ) );
@@ -137,6 +145,8 @@ namespace Catch {
 
             if( m_configData.showHelp )
                 showHelp();
+            if( m_configData.libIdentify )
+                libIdentify();
             m_config.reset();
             return 0;
         }
@@ -189,9 +199,36 @@ namespace Catch {
             return returnCode;
         }
     #endif
-
         int run() {
-            if( m_configData.showHelp )
+            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::Parser const& cli() const {
+            return m_cli;
+        }
+        void cli( clara::Parser const& newParser ) {
+            m_cli = newParser;
+        }
+        ConfigData& configData() {
+            return m_configData;
+        }
+        Config& config() {
+            if( !m_config )
+                m_config = std::make_shared<Config>( m_configData );
+            return *m_config;
+        }
+    private:
+        int runInternal() {
+            if( m_configData.showHelp || m_configData.libIdentify )
                 return 0;
 
             try
@@ -215,21 +252,6 @@ namespace Catch {
             }
         }
 
-        clara::Parser const& cli() const {
-            return m_cli;
-        }
-        void cli( clara::Parser const& newParser ) {
-            m_cli = newParser;
-        }
-        ConfigData& configData() {
-            return m_configData;
-        }
-        Config& config() {
-            if( !m_config )
-                m_config = std::make_shared<Config>( m_configData );
-            return *m_config;
-        }
-    private:
         clara::Parser m_cli;
         ConfigData m_configData;
         std::shared_ptr<Config> m_config;
diff --git a/include/internal/catch_commandline.cpp b/include/internal/catch_commandline.cpp
index 7342ac42..d92a1c39 100644
--- a/include/internal/catch_commandline.cpp
+++ b/include/internal/catch_commandline.cpp
@@ -71,6 +71,18 @@ namespace Catch {
                         return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
                 return ParserResult::ok( ParseResultType::Matched );
             };
+        auto const setWaitForKeypress = [&]( 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
+                    return ParserResult::runtimeError( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" );
+            return ParserResult::ok( ParseResultType::Matched );
+            };
         auto const setVerbosity = [&]( std::string const& verbosity ) {
             auto lcVerbosity = toLower( verbosity );
             if( lcVerbosity == "quiet" )
@@ -153,6 +165,12 @@ namespace Catch {
             + Opt( setColourUsage, "yes|no" )
                 ["--use-colour"]
                 ( "should output be colourised" )
+            + Opt( config.libIdentify )
+                ["--libidentify"]
+                ( "report name and version according to libidentify standard" )
+            + Opt( setWaitForKeypress, "start|exit|both" )
+                ["--wait-for-keypress"]
+                ( "waits for a keypress before exiting" )
             + Opt( config.benchmarkResolutionMultiple, "multiplier" )
                 ["--benchmark-resolution-multiple"]
                 ( "multiple of clock resolution to run benchmarks" )
diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp
index 6bf792b0..61669897 100644
--- a/include/internal/catch_config.hpp
+++ b/include/internal/catch_config.hpp
@@ -35,6 +35,7 @@ namespace Catch {
         bool showHelp = false;
         bool showInvisibles = false;
         bool filenamesAsTags = false;
+        bool libIdentify = false;
 
         int abortAfter = -1;
         unsigned int rngSeed = 0;
@@ -45,6 +46,7 @@ namespace Catch {
         ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
         RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
         UseColour::YesOrNo useColour = UseColour::Auto;
+        WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
 
         std::string outputFilename;
         std::string name;
diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h
index 436b80eb..2584ccc0 100644
--- a/include/internal/catch_interfaces_config.h
+++ b/include/internal/catch_interfaces_config.h
@@ -43,6 +43,12 @@ namespace Catch {
         Yes,
         No
     }; };
+    struct WaitForKeypress { enum When {
+        Never,
+        BeforeStart = 1,
+        BeforeExit = 2,
+        BeforeStartAndExit = BeforeStart | BeforeExit
+    }; };
 
     class TestSpec;