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

Some Clara/ command line clean-up and tweaks

Commit
1870ca84551a29f234f0d366a29caba8e1f843f9
Author
Phil Nash ·
Parents
f41fad7e2010

Files · Download .tar.gz

Changes

 include/catch_runner.hpp               | 11 ++++++-----
 include/internal/catch_commandline.hpp | 18 +++++++++---------
 include/internal/clara.h               | 26 +++++++++++++-------------
 projects/SelfTest/CmdLineTests.cpp     | 14 +++++++-------
 4 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index 150387b9..97bddba3 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -150,11 +150,12 @@ namespace Catch {
                 m_config.reset();
             }
             catch( std::exception& ex ) {
-                std::cerr   << "\nError in input:\n"
-                            << Text( ex.what(), TextAttributes()
-                                                    .setInitialIndent(2)
-                                                    .setIndent(4) )
-                            << "\n\n";
+                {
+                    Colour colourGuard( Colour::Red );
+                    std::cerr   << "\nError in input:\n"
+                                << Text( ex.what(), TextAttributes().setIndent(2) )
+                                << "\n\n";
+                }
                 m_cli.usage( std::cout, m_configData.processName );
                 return (std::numeric_limits<int>::max)();
             }
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp
index b9617932..3b32f2b2 100644
--- a/include/internal/catch_commandline.hpp
+++ b/include/internal/catch_commandline.hpp
@@ -85,20 +85,20 @@ namespace Catch {
             .describe( "output filename" )
             .shortOpt( "o")
             .longOpt( "out" )
-            .argName( "filename" );
+            .hint( "filename" );
 
         cli.bind( &ConfigData::reporterName )
             .describe( "reporter to use - defaults to console" )
             .shortOpt( "r")
             .longOpt( "reporter" )
-//            .argName( "name[:filename]" );
-            .argName( "name" );
+//            .hint( "name[:filename]" );
+            .hint( "name" );
 
         cli.bind( &ConfigData::name )
             .describe( "suite name" )
             .shortOpt( "n")
             .longOpt( "name" )
-            .argName( "name" );
+            .hint( "name" );
 
         cli.bind( &abortAfterFirst )
             .describe( "abort at first failure" )
@@ -109,29 +109,29 @@ namespace Catch {
             .describe( "abort after x failures" )
             .shortOpt( "x")
             .longOpt( "abortx" )
-            .argName( "number of failures" );
+            .hint( "number of failures" );
 
         cli.bind( &addWarning )
             .describe( "enable warnings" )
             .shortOpt( "w")
             .longOpt( "warn" )
-            .argName( "warning name" );
+            .hint( "warning name" );
 
 //        cli.bind( &setVerbosity )
 //            .describe( "level of verbosity (0=no output)" )
 //            .shortOpt( "v")
 //            .longOpt( "verbosity" )
-//            .argName( "level" );
+//            .hint( "level" );
 
         cli.bind( &addTestOrTags )
             .describe( "which test or tests to use" )
-            .argName( "test name, pattern or tags" );
+            .hint( "test name, pattern or tags" );
 
         cli.bind( &setShowDurations )
             .describe( "show test durations" )
             .shortOpt( "d")
             .longOpt( "durations" )
-            .argName( "durations" );
+            .hint( "yes/no" );
 
         return cli;
     }
diff --git a/include/internal/clara.h b/include/internal/clara.h
index ed22bc6a..fa58da79 100644
--- a/include/internal/clara.h
+++ b/include/internal/clara.h
@@ -34,12 +34,12 @@ namespace Clara {
         inline void convertInto( std::string const& _source, bool& _dest ) {
             std::string sourceLC = _source;
             std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower );
-            if( sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
+            if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
                 _dest = true;
-            else if( sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
+            else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
                 _dest = false;
             else
-                throw std::runtime_error( "Expected a boolean value but did recognise: '" + _source + "'" );
+                throw std::runtime_error( "Expected a boolean value but did not recognise:\n  '" + _source + "'" );
         }
         inline void convertInto( bool _source, bool& _dest ) {
             _dest = _source;
@@ -257,7 +257,7 @@ namespace Clara {
                 return _longName == longName;
             }
             bool takesArg() const {
-                return !argName.empty();
+                return !hint.empty();
             }
             bool isFixedPositional() const {
                 return position != -1;
@@ -292,8 +292,8 @@ namespace Clara {
                         oss << ", ";
                     oss << "--" << longName;
                 }
-                if( !argName.empty() )
-                    oss << " <" << argName << ">";
+                if( !hint.empty() )
+                    oss << " <" << hint << ">";
                 return oss.str();
             }
 
@@ -301,7 +301,7 @@ namespace Clara {
             std::vector<std::string> shortNames;
             std::string longName;
             std::string description;
-            std::string argName;
+            std::string hint;
             int position;
         };
 
@@ -347,8 +347,8 @@ namespace Clara {
                 m_arg.description = description;
                 return *this;
             }
-            ArgBinder& argName( std::string const& argName ) {
-                m_arg.argName = argName;
+            ArgBinder& hint( std::string const& hint ) {
+                m_arg.hint = hint;
                 return *this;
             }
             ArgBinder& position( int position ) {
@@ -423,9 +423,9 @@ namespace Clara {
                     os << " ";
                 typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
                 if( it != m_positionalArgs.end() )
-                    os << "<" << it->second.argName << ">";
+                    os << "<" << it->second.hint << ">";
                 else if( m_arg.get() )
-                    os << "<" << m_arg->argName << ">";
+                    os << "<" << m_arg->hint << ">";
                 else
                     throw std::logic_error( "non consecutive positional arguments with no floating args" );
             }
@@ -433,7 +433,7 @@ namespace Clara {
             if( m_arg.get() ) {
                 if( m_highestSpecifiedArgPosition > 1 )
                     os << " ";
-                os << "[<" << m_arg->argName << "> ...]";
+                os << "[<" << m_arg->hint << "> ...]";
             }
         }
         std::string argSynopsis() const {
@@ -502,7 +502,7 @@ namespace Clara {
                         }
                     }
                     catch( std::exception& ex ) {
-                        throw std::runtime_error( std::string( ex.what() ) + " while parsing: (" + arg.commands() + ")" );
+                        throw std::runtime_error( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
                     }
                 }
                 if( it == itEnd )
diff --git a/projects/SelfTest/CmdLineTests.cpp b/projects/SelfTest/CmdLineTests.cpp
index 173b6412..968a1529 100644
--- a/projects/SelfTest/CmdLineTests.cpp
+++ b/projects/SelfTest/CmdLineTests.cpp
@@ -55,7 +55,7 @@ TEST_CASE( "cmdline" ) {
         .describe( "specifies output file" )
         .shortOpt( "o" )
         .longOpt( "output" )
-        .argName( "filename" );
+        .hint( "filename" );
 
     SECTION( "process name" ) {
         char const * argv[] = { "test", "-o filename.ext" };
@@ -90,7 +90,7 @@ TEST_CASE( "cmdline" ) {
     
     cli.bind( &TestOpt::number )
             .shortOpt( "n" )
-            .argName( "an integral value" );
+            .hint( "an integral value" );
     
     SECTION( "a number" ) {
         const char* argv[] = { "test", "-n 42" };
@@ -115,7 +115,7 @@ TEST_CASE( "cmdline" ) {
             .describe( "description" )
             .shortOpt( "d" )
             .longOpt( "description" )
-            .argName( "some text" );
+            .hint( "some text" );
         
         const char* argv[] = { "test", "-n 42", "-d some text" };
         std::vector<Clara::Parser::Token> unusedTokens = parseInto( cli, argv, config1 );
@@ -131,7 +131,7 @@ TEST_CASE( "cmdline" ) {
         cli.bind( &TestOpt::setValidIndex )
             .describe( "An index, which is an integer between 0 and 10, inclusive" )
             .shortOpt( "i" )
-            .argName( "index" );
+            .hint( "index" );
 
         SECTION( "in range" ) {
             const char* argv[] = { "test", "-i 3" };
@@ -167,14 +167,14 @@ TEST_CASE( "cmdline" ) {
     SECTION( "positional" ) {
         cli.bind( &TestOpt::secondPos )
             .describe( "Second position" )
-            .argName( "second arg" )
+            .hint( "second arg" )
             .position( 2 );
         cli.bind( &TestOpt::unpositional )
-            .argName( "any arg" )
+            .hint( "any arg" )
             .describe( "Unpositional" );
         cli.bind( &TestOpt::firstPos )
             .describe( "First position" )
-            .argName( "first arg" )
+            .hint( "first arg" )
             .position( 1 );
 
 //        std::cout << cli.usage( "testApp" ) << std::endl;