From fb90d38310d90184e139feacb80901c3190ca415 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 19 Dec 2013 08:07:33 +0000 Subject: [PATCH 1/6] Changed stdout/ stderr messages to be less misleading --- projects/SelfTest/Baselines/console.std.approved.txt | 4 ++-- projects/SelfTest/Baselines/console.sw.approved.txt | 4 ++-- projects/SelfTest/Baselines/junit.sw.approved.txt | 8 ++++---- projects/SelfTest/MiscTests.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 54d3ee6f..422f0fc2 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -569,8 +569,8 @@ with expansion: with message: Testing if fib[7] (21) is even -Some information -An error +A string sent directly to stdout +A string sent directly to stderr ------------------------------------------------------------------------------- checkedIf, failing ------------------------------------------------------------------------------- diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index e0c15c68..792004c9 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -3014,8 +3014,8 @@ with expansion: with message: Testing if fib[7] (21) is even -Some information -An error +A string sent directly to stdout +A string sent directly to stderr ------------------------------------------------------------------------------- Sends stuff to stdout and stderr ------------------------------------------------------------------------------- diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index b105e986..5dd37bd7 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -351,10 +351,10 @@ MiscTests.cpp: -Some information +A string sent directly to stdout -An error +A string sent directly to stderr @@ -550,12 +550,12 @@ TrickyTests.cpp: Message from section one Message from section two -Some information +A string sent directly to stdout hello hello -An error +A string sent directly to stderr diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index 33e84bc2..efcd4582 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -113,9 +113,9 @@ TEST_CASE( "looped tests", "[.][failing]" ) TEST_CASE( "Sends stuff to stdout and stderr", "" ) { - std::cout << "Some information" << std::endl; + std::cout << "A string sent directly to stdout" << std::endl; - std::cerr << "An error" << std::endl; + std::cerr << "A string sent directly to stderr" << std::endl; } inline const char* makeString( bool makeNull ) From 1aa60fada9c925068507f202d7ab63217c6275d1 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 19 Dec 2013 18:41:55 +0000 Subject: [PATCH 2/6] Changed Approx::toString() to be implemented in terms of toString( double ) (as proposed in #233) --- include/internal/catch_approx.hpp | 2 +- .../Baselines/console.std.approved.txt | 12 +++--- .../Baselines/console.sw.approved.txt | 40 ++++++++++--------- .../Baselines/console.swa4.approved.txt | 20 ++++++---- .../SelfTest/Baselines/junit.sw.approved.txt | 12 +++--- .../SelfTest/Baselines/xml.sw.approved.txt | 40 +++++++++---------- 6 files changed, 67 insertions(+), 59 deletions(-) diff --git a/include/internal/catch_approx.hpp b/include/internal/catch_approx.hpp index 67dba619..4370ab3e 100644 --- a/include/internal/catch_approx.hpp +++ b/include/internal/catch_approx.hpp @@ -70,7 +70,7 @@ namespace Detail { std::string toString() const { std::ostringstream oss; - oss << "Approx( " << m_value << " )"; + oss << "Approx( " << Catch::toString( m_value ) << " )"; return oss.str(); } diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 422f0fc2..52b4db55 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -49,22 +49,22 @@ with expansion: ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 9.11f ) ) with expansion: - 9.1 == Approx( 9.11 ) + 9.1 == Approx( 9.1099996567 ) ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 9.0f ) ) with expansion: - 9.1 == Approx( 9 ) + 9.1 == Approx( 9.0 ) ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 1 ) ) with expansion: - 9.1 == Approx( 1 ) + 9.1 == Approx( 1.0 ) ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 0 ) ) with expansion: - 9.1 == Approx( 0 ) + 9.1 == Approx( 0.0 ) ConditionTests.cpp:: FAILED: CHECK( data.double_pi == Approx( 3.1415 ) ) @@ -110,12 +110,12 @@ with expansion: ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one != Approx( 9.1f ) ) with expansion: - 9.1 != Approx( 9.1 ) + 9.1 != Approx( 9.1000003815 ) ConditionTests.cpp:: FAILED: CHECK( data.double_pi != Approx( 3.1415926535 ) ) with expansion: - 3.1415926535 != Approx( 3.14159 ) + 3.1415926535 != Approx( 3.1415926535 ) ConditionTests.cpp:: FAILED: CHECK( data.str_hello != "hello" ) diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 792004c9..81ee03db 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -73,13 +73,13 @@ ApproxTests.cpp:: PASSED: REQUIRE( 1.23f == Approx( 1.23f ) ) with expansion: - 1.23 == Approx( 1.23 ) + 1.23 == Approx( 1.2300000191 ) ApproxTests.cpp:: PASSED: REQUIRE( 0.0f == Approx( 0.0f ) ) with expansion: - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) ------------------------------------------------------------------------------- Approximate comparisons with ints @@ -90,10 +90,14 @@ ApproxTests.cpp: ApproxTests.cpp:: PASSED: REQUIRE( 1 == Approx( 1 ) ) +with expansion: + 1 == Approx( 1.0 ) ApproxTests.cpp:: PASSED: REQUIRE( 0 == Approx( 0 ) ) +with expansion: + 0 == Approx( 0.0 ) ------------------------------------------------------------------------------- Approximate comparisons with mixed numeric types @@ -105,19 +109,19 @@ ApproxTests.cpp:: PASSED: REQUIRE( 1.0f == Approx( 1 ) ) with expansion: - 1 == Approx( 1 ) + 1 == Approx( 1.0 ) ApproxTests.cpp:: PASSED: REQUIRE( 0 == Approx( dZero) ) with expansion: - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) ApproxTests.cpp:: PASSED: REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) ) with expansion: - 0 == Approx( 1e-05 ) + 0 == Approx( 0.00001 ) ApproxTests.cpp:: PASSED: @@ -129,7 +133,7 @@ ApproxTests.cpp:: PASSED: REQUIRE( dMedium == Approx( 1.234f ) ) with expansion: - 1.234 == Approx( 1.234 ) + 1.234 == Approx( 1.2339999676 ) ------------------------------------------------------------------------------- Use a custom approx @@ -265,13 +269,13 @@ ConditionTests.cpp:: PASSED: REQUIRE( data.float_nine_point_one == Approx( 9.1f ) ) with expansion: - 9.1 == Approx( 9.1 ) + 9.1 == Approx( 9.1000003815 ) ConditionTests.cpp:: PASSED: REQUIRE( data.double_pi == Approx( 3.1415926535 ) ) with expansion: - 3.1415926535 == Approx( 3.14159 ) + 3.1415926535 == Approx( 3.1415926535 ) ConditionTests.cpp:: PASSED: @@ -321,22 +325,22 @@ with expansion: ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 9.11f ) ) with expansion: - 9.1 == Approx( 9.11 ) + 9.1 == Approx( 9.1099996567 ) ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 9.0f ) ) with expansion: - 9.1 == Approx( 9 ) + 9.1 == Approx( 9.0 ) ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 1 ) ) with expansion: - 9.1 == Approx( 1 ) + 9.1 == Approx( 1.0 ) ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one == Approx( 0 ) ) with expansion: - 9.1 == Approx( 0 ) + 9.1 == Approx( 0.0 ) ConditionTests.cpp:: FAILED: CHECK( data.double_pi == Approx( 3.1415 ) ) @@ -390,25 +394,25 @@ ConditionTests.cpp:: PASSED: REQUIRE( data.float_nine_point_one != Approx( 9.11f ) ) with expansion: - 9.1 != Approx( 9.11 ) + 9.1 != Approx( 9.1099996567 ) ConditionTests.cpp:: PASSED: REQUIRE( data.float_nine_point_one != Approx( 9.0f ) ) with expansion: - 9.1 != Approx( 9 ) + 9.1 != Approx( 9.0 ) ConditionTests.cpp:: PASSED: REQUIRE( data.float_nine_point_one != Approx( 1 ) ) with expansion: - 9.1 != Approx( 1 ) + 9.1 != Approx( 1.0 ) ConditionTests.cpp:: PASSED: REQUIRE( data.float_nine_point_one != Approx( 0 ) ) with expansion: - 9.1 != Approx( 0 ) + 9.1 != Approx( 0.0 ) ConditionTests.cpp:: PASSED: @@ -454,12 +458,12 @@ with expansion: ConditionTests.cpp:: FAILED: CHECK( data.float_nine_point_one != Approx( 9.1f ) ) with expansion: - 9.1 != Approx( 9.1 ) + 9.1 != Approx( 9.1000003815 ) ConditionTests.cpp:: FAILED: CHECK( data.double_pi != Approx( 3.1415926535 ) ) with expansion: - 3.1415926535 != Approx( 3.14159 ) + 3.1415926535 != Approx( 3.1415926535 ) ConditionTests.cpp:: FAILED: CHECK( data.str_hello != "hello" ) diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index 65a96d7d..e701d91a 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -73,13 +73,13 @@ ApproxTests.cpp:: PASSED: REQUIRE( 1.23f == Approx( 1.23f ) ) with expansion: - 1.23 == Approx( 1.23 ) + 1.23 == Approx( 1.2300000191 ) ApproxTests.cpp:: PASSED: REQUIRE( 0.0f == Approx( 0.0f ) ) with expansion: - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) ------------------------------------------------------------------------------- Approximate comparisons with ints @@ -90,10 +90,14 @@ ApproxTests.cpp: ApproxTests.cpp:: PASSED: REQUIRE( 1 == Approx( 1 ) ) +with expansion: + 1 == Approx( 1.0 ) ApproxTests.cpp:: PASSED: REQUIRE( 0 == Approx( 0 ) ) +with expansion: + 0 == Approx( 0.0 ) ------------------------------------------------------------------------------- Approximate comparisons with mixed numeric types @@ -105,19 +109,19 @@ ApproxTests.cpp:: PASSED: REQUIRE( 1.0f == Approx( 1 ) ) with expansion: - 1 == Approx( 1 ) + 1 == Approx( 1.0 ) ApproxTests.cpp:: PASSED: REQUIRE( 0 == Approx( dZero) ) with expansion: - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) ApproxTests.cpp:: PASSED: REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) ) with expansion: - 0 == Approx( 1e-05 ) + 0 == Approx( 0.00001 ) ApproxTests.cpp:: PASSED: @@ -129,7 +133,7 @@ ApproxTests.cpp:: PASSED: REQUIRE( dMedium == Approx( 1.234f ) ) with expansion: - 1.234 == Approx( 1.234 ) + 1.234 == Approx( 1.2339999676 ) ------------------------------------------------------------------------------- Use a custom approx @@ -265,13 +269,13 @@ ConditionTests.cpp:: PASSED: REQUIRE( data.float_nine_point_one == Approx( 9.1f ) ) with expansion: - 9.1 == Approx( 9.1 ) + 9.1 == Approx( 9.1000003815 ) ConditionTests.cpp:: PASSED: REQUIRE( data.double_pi == Approx( 3.1415926535 ) ) with expansion: - 3.1415926535 == Approx( 3.14159 ) + 3.1415926535 == Approx( 3.1415926535 ) ConditionTests.cpp:: PASSED: diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 5dd37bd7..e28449ca 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -30,16 +30,16 @@ ConditionTests.cpp: ConditionTests.cpp: - + ConditionTests.cpp: - + ConditionTests.cpp: - + ConditionTests.cpp: - + ConditionTests.cpp: @@ -66,10 +66,10 @@ ConditionTests.cpp: ConditionTests.cpp: - + ConditionTests.cpp: - + ConditionTests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index dda010b1..9bebc628 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -76,7 +76,7 @@ 1.23f == Approx( 1.23f ) - 1.23 == Approx( 1.23 ) + 1.23 == Approx( 1.2300000191 ) @@ -84,7 +84,7 @@ 0.0f == Approx( 0.0f ) - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) @@ -95,7 +95,7 @@ 1 == Approx( 1 ) - 1 == Approx( 1 ) + 1 == Approx( 1.0 ) @@ -103,7 +103,7 @@ 0 == Approx( 0 ) - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) @@ -114,7 +114,7 @@ 1.0f == Approx( 1 ) - 1 == Approx( 1 ) + 1 == Approx( 1.0 ) @@ -122,7 +122,7 @@ 0 == Approx( dZero) - 0 == Approx( 0 ) + 0 == Approx( 0.0 ) @@ -130,7 +130,7 @@ 0 == Approx( dSmall ).epsilon( 0.001 ) - 0 == Approx( 1e-05 ) + 0 == Approx( 0.00001 ) @@ -146,7 +146,7 @@ dMedium == Approx( 1.234f ) - 1.234 == Approx( 1.234 ) + 1.234 == Approx( 1.2339999676 ) @@ -295,7 +295,7 @@ data.float_nine_point_one == Approx( 9.1f ) - 9.1 == Approx( 9.1 ) + 9.1 == Approx( 9.1000003815 ) @@ -303,7 +303,7 @@ data.double_pi == Approx( 3.1415926535 ) - 3.1415926535 == Approx( 3.14159 ) + 3.1415926535 == Approx( 3.1415926535 ) @@ -370,7 +370,7 @@ data.float_nine_point_one == Approx( 9.11f ) - 9.1 == Approx( 9.11 ) + 9.1 == Approx( 9.1099996567 ) @@ -378,7 +378,7 @@ data.float_nine_point_one == Approx( 9.0f ) - 9.1 == Approx( 9 ) + 9.1 == Approx( 9.0 ) @@ -386,7 +386,7 @@ data.float_nine_point_one == Approx( 1 ) - 9.1 == Approx( 1 ) + 9.1 == Approx( 1.0 ) @@ -394,7 +394,7 @@ data.float_nine_point_one == Approx( 0 ) - 9.1 == Approx( 0 ) + 9.1 == Approx( 0.0 ) @@ -469,7 +469,7 @@ data.float_nine_point_one != Approx( 9.11f ) - 9.1 != Approx( 9.11 ) + 9.1 != Approx( 9.1099996567 ) @@ -477,7 +477,7 @@ data.float_nine_point_one != Approx( 9.0f ) - 9.1 != Approx( 9 ) + 9.1 != Approx( 9.0 ) @@ -485,7 +485,7 @@ data.float_nine_point_one != Approx( 1 ) - 9.1 != Approx( 1 ) + 9.1 != Approx( 1.0 ) @@ -493,7 +493,7 @@ data.float_nine_point_one != Approx( 0 ) - 9.1 != Approx( 0 ) + 9.1 != Approx( 0.0 ) @@ -552,7 +552,7 @@ data.float_nine_point_one != Approx( 9.1f ) - 9.1 != Approx( 9.1 ) + 9.1 != Approx( 9.1000003815 ) @@ -560,7 +560,7 @@ data.double_pi != Approx( 3.1415926535 ) - 3.1415926535 != Approx( 3.14159 ) + 3.1415926535 != Approx( 3.1415926535 ) From f385a0b13dc65c78242fbd9ccb336f25b6d9cbae Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 19 Dec 2013 18:42:25 +0000 Subject: [PATCH 3/6] build 21 --- README.md | 2 +- include/internal/catch_version.hpp | 2 +- single_include/catch.hpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 59325a4e..6b72eb2f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 20 (master branch)* +*v1.0 build 21 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index ab86363b..de3ea90f 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 20, "master" ); + Version libraryVersion( 1, 0, 21, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/single_include/catch.hpp b/single_include/catch.hpp index eb20e5de..e9b5374b 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 20 (master branch) - * Generated: 2013-12-18 08:38:15.171445 + * CATCH v1.0 build 21 (master branch) + * Generated: 2013-12-19 18:42:03.734896 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -2096,7 +2096,7 @@ namespace Detail { std::string toString() const { std::ostringstream oss; - oss << "Approx( " << m_value << " )"; + oss << "Approx( " << Catch::toString( m_value ) << " )"; return oss.str(); } @@ -6166,7 +6166,7 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 20, "master" ); + Version libraryVersion( 1, 0, 21, "master" ); } // #included from: catch_text.hpp From 886d9d397c33c47109f6e748010c7337b98ebc1f Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 20 Dec 2013 19:06:02 +0000 Subject: [PATCH 4/6] =?UTF-8?q?Reporter=20command=20line=20parser=20errors?= =?UTF-8?q?=20more=20eagerly=20-=20show=20all=20=E2=80=9Cunrecognised=20op?= =?UTF-8?q?tion=E2=80=9D=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/catch_runner.hpp | 17 ++----------- include/internal/clara.h | 39 ++++++++++++++++++++++++------ projects/SelfTest/CmdLineTests.cpp | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index 97bddba3..57e5aa99 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -142,9 +142,8 @@ namespace Catch { int applyCommandLine( int argc, char* const argv[], OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) { try { + m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail ); m_unusedTokens = m_cli.parseInto( argc, argv, m_configData ); - if( unusedOptionBehaviour == OnUnusedOptions::Fail ) - enforceNoUsedTokens(); if( m_configData.showHelp ) showHelp( m_configData.processName ); m_config.reset(); @@ -152,7 +151,7 @@ namespace Catch { catch( std::exception& ex ) { { Colour colourGuard( Colour::Red ); - std::cerr << "\nError in input:\n" + std::cerr << "\nError(s) in input:\n" << Text( ex.what(), TextAttributes().setIndent(2) ) << "\n\n"; } @@ -167,18 +166,6 @@ namespace Catch { m_config.reset(); } - void enforceNoUsedTokens() const { - if( !m_unusedTokens.empty() ) { - std::vector::const_iterator - it = m_unusedTokens.begin(), - itEnd = m_unusedTokens.end(); - std::string msg; - for(; it != itEnd; ++it ) - msg += " unrecognised option: " + it->data + "\n"; - throw std::runtime_error( msg.substr( 0, msg.size()-1 ) ); - } - } - int run( int argc, char* const argv[] ) { int returnCode = applyCommandLine( argc, argv ); diff --git a/include/internal/clara.h b/include/internal/clara.h index a401edd8..9f736e99 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -371,18 +371,25 @@ namespace Clara { CommandLine() : m_boundProcessName( new Detail::NullBinder() ), - m_highestSpecifiedArgPosition( 0 ) + m_highestSpecifiedArgPosition( 0 ), + m_throwOnUnrecognisedTokens( false ) {} CommandLine( CommandLine const& other ) : m_boundProcessName( other.m_boundProcessName ), m_options ( other.m_options ), m_positionalArgs( other.m_positionalArgs ), - m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ) + m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ), + m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens ) { if( other.m_arg.get() ) m_arg = ArgAutoPtr( new Arg( *other.m_arg ) ); } + CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) { + m_throwOnUnrecognisedTokens = shouldThrow; + return *this; + } + template ArgBinder bind( F f ) { ArgBinder binder( this, f ); @@ -488,6 +495,7 @@ namespace Clara { std::vector populateOptions( std::vector const& tokens, ConfigT& config ) const { std::vector unusedTokens; + std::vector errors; for( std::size_t i = 0; i < tokens.size(); ++i ) { Parser::Token const& token = tokens[i]; typename std::vector::const_iterator it = m_options.begin(), itEnd = m_options.end(); @@ -499,8 +507,9 @@ namespace Clara { ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) { if( arg.takesArg() ) { if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional ) - throw std::domain_error( "Expected argument to option " + token.data ); - arg.boundField.set( config, tokens[++i].data ); + errors.push_back( "Expected argument to option: " + token.data ); + else + arg.boundField.set( config, tokens[++i].data ); } else { arg.boundField.setFlag( config ); @@ -509,11 +518,26 @@ namespace Clara { } } catch( std::exception& ex ) { - throw std::runtime_error( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); + errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); } } - if( it == itEnd ) - unusedTokens.push_back( token ); + if( it == itEnd ) { + if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) + unusedTokens.push_back( token ); + else if( m_throwOnUnrecognisedTokens ) + errors.push_back( "unrecognised option: " + token.data ); + } + } + if( !errors.empty() ) { + std::ostringstream oss; + for( std::vector::const_iterator it = errors.begin(), itEnd = errors.end(); + it != itEnd; + ++it ) { + if( it != errors.begin() ) + oss << "\n"; + oss << *it; + } + throw std::runtime_error( oss.str() ); } return unusedTokens; } @@ -552,6 +576,7 @@ namespace Clara { std::map m_positionalArgs; ArgAutoPtr m_arg; int m_highestSpecifiedArgPosition; + bool m_throwOnUnrecognisedTokens; }; } // end namespace Clara diff --git a/projects/SelfTest/CmdLineTests.cpp b/projects/SelfTest/CmdLineTests.cpp index 968a1529..3eb54d2f 100644 --- a/projects/SelfTest/CmdLineTests.cpp +++ b/projects/SelfTest/CmdLineTests.cpp @@ -116,7 +116,7 @@ TEST_CASE( "cmdline" ) { .shortOpt( "d" ) .longOpt( "description" ) .hint( "some text" ); - + const char* argv[] = { "test", "-n 42", "-d some text" }; std::vector unusedTokens = parseInto( cli, argv, config1 ); From 91ef5f7d4024ea96b5bb8d0295443475527ea014 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 20 Dec 2013 19:06:26 +0000 Subject: [PATCH 5/6] build 22 --- README.md | 2 +- include/internal/catch_version.hpp | 2 +- single_include/catch.hpp | 62 ++++++++++++++++++------------ 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6b72eb2f..8852fd7a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 21 (master branch)* +*v1.0 build 22 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index de3ea90f..8b232e99 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 21, "master" ); + Version libraryVersion( 1, 0, 22, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/single_include/catch.hpp b/single_include/catch.hpp index e9b5374b..1acc3beb 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 21 (master branch) - * Generated: 2013-12-19 18:42:03.734896 + * CATCH v1.0 build 22 (master branch) + * Generated: 2013-12-20 19:06:10.591489 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -3389,18 +3389,25 @@ namespace Clara { CommandLine() : m_boundProcessName( new Detail::NullBinder() ), - m_highestSpecifiedArgPosition( 0 ) + m_highestSpecifiedArgPosition( 0 ), + m_throwOnUnrecognisedTokens( false ) {} CommandLine( CommandLine const& other ) : m_boundProcessName( other.m_boundProcessName ), m_options ( other.m_options ), m_positionalArgs( other.m_positionalArgs ), - m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ) + m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ), + m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens ) { if( other.m_arg.get() ) m_arg = ArgAutoPtr( new Arg( *other.m_arg ) ); } + CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) { + m_throwOnUnrecognisedTokens = shouldThrow; + return *this; + } + template ArgBinder bind( F f ) { ArgBinder binder( this, f ); @@ -3506,6 +3513,7 @@ namespace Clara { std::vector populateOptions( std::vector const& tokens, ConfigT& config ) const { std::vector unusedTokens; + std::vector errors; for( std::size_t i = 0; i < tokens.size(); ++i ) { Parser::Token const& token = tokens[i]; typename std::vector::const_iterator it = m_options.begin(), itEnd = m_options.end(); @@ -3517,8 +3525,9 @@ namespace Clara { ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) { if( arg.takesArg() ) { if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional ) - throw std::domain_error( "Expected argument to option " + token.data ); - arg.boundField.set( config, tokens[++i].data ); + errors.push_back( "Expected argument to option: " + token.data ); + else + arg.boundField.set( config, tokens[++i].data ); } else { arg.boundField.setFlag( config ); @@ -3527,11 +3536,26 @@ namespace Clara { } } catch( std::exception& ex ) { - throw std::runtime_error( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); + errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); } } - if( it == itEnd ) - unusedTokens.push_back( token ); + if( it == itEnd ) { + if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) + unusedTokens.push_back( token ); + else if( m_throwOnUnrecognisedTokens ) + errors.push_back( "unrecognised option: " + token.data ); + } + } + if( !errors.empty() ) { + std::ostringstream oss; + for( std::vector::const_iterator it = errors.begin(), itEnd = errors.end(); + it != itEnd; + ++it ) { + if( it != errors.begin() ) + oss << "\n"; + oss << *it; + } + throw std::runtime_error( oss.str() ); } return unusedTokens; } @@ -3570,6 +3594,7 @@ namespace Clara { std::map m_positionalArgs; ArgAutoPtr m_arg; int m_highestSpecifiedArgPosition; + bool m_throwOnUnrecognisedTokens; }; } // end namespace Clara @@ -4812,9 +4837,8 @@ namespace Catch { int applyCommandLine( int argc, char* const argv[], OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) { try { + m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail ); m_unusedTokens = m_cli.parseInto( argc, argv, m_configData ); - if( unusedOptionBehaviour == OnUnusedOptions::Fail ) - enforceNoUsedTokens(); if( m_configData.showHelp ) showHelp( m_configData.processName ); m_config.reset(); @@ -4822,7 +4846,7 @@ namespace Catch { catch( std::exception& ex ) { { Colour colourGuard( Colour::Red ); - std::cerr << "\nError in input:\n" + std::cerr << "\nError(s) in input:\n" << Text( ex.what(), TextAttributes().setIndent(2) ) << "\n\n"; } @@ -4837,18 +4861,6 @@ namespace Catch { m_config.reset(); } - void enforceNoUsedTokens() const { - if( !m_unusedTokens.empty() ) { - std::vector::const_iterator - it = m_unusedTokens.begin(), - itEnd = m_unusedTokens.end(); - std::string msg; - for(; it != itEnd; ++it ) - msg += " unrecognised option: " + it->data + "\n"; - throw std::runtime_error( msg.substr( 0, msg.size()-1 ) ); - } - } - int run( int argc, char* const argv[] ) { int returnCode = applyCommandLine( argc, argv ); @@ -6166,7 +6178,7 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 21, "master" ); + Version libraryVersion( 1, 0, 22, "master" ); } // #included from: catch_text.hpp From e45e3a139ad46de2a38549d877e2ec0b2be5bdab Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Mon, 23 Dec 2013 10:24:06 +0000 Subject: [PATCH 6/6] =?UTF-8?q?Clara=20ignores=20anything=20after=20a=20lo?= =?UTF-8?q?ne=20=E2=80=94=20(double=20dash)=20-=20this=20allows=20use=20wi?= =?UTF-8?q?thin=20an=20environment=20that=20appends=20additional=20argumen?= =?UTF-8?q?ts=20that=20Clara=20will=20otherwise=20reject=20-=20generated?= =?UTF-8?q?=20build=2023?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- include/internal/catch_version.hpp | 2 +- include/internal/clara.h | 3 ++- single_include/catch.hpp | 9 +++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8852fd7a..dba8e0c2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![catch logo](catch-logo-small.png) -*v1.0 build 22 (master branch)* +*v1.0 build 23 (master branch)* Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch) diff --git a/include/internal/catch_version.hpp b/include/internal/catch_version.hpp index 8b232e99..f615b3ea 100644 --- a/include/internal/catch_version.hpp +++ b/include/internal/catch_version.hpp @@ -13,7 +13,7 @@ namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 22, "master" ); + Version libraryVersion( 1, 0, 23, "master" ); } #endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED diff --git a/include/internal/clara.h b/include/internal/clara.h index 9f736e99..b44d129a 100644 --- a/include/internal/clara.h +++ b/include/internal/clara.h @@ -206,7 +206,8 @@ namespace Clara { }; void parseIntoTokens( int argc, char const * const * argv, std::vector& tokens ) const { - for( int i = 1; i < argc; ++i ) + const std::string doubleDash = "--"; + for( int i = 1; i < argc && argv[i] != doubleDash; ++i ) parseIntoTokens( argv[i] , tokens); } void parseIntoTokens( std::string arg, std::vector& tokens ) const { diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 1acc3beb..770b3537 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * CATCH v1.0 build 22 (master branch) - * Generated: 2013-12-20 19:06:10.591489 + * CATCH v1.0 build 23 (master branch) + * Generated: 2013-12-23 10:22:45.547645 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -3224,7 +3224,8 @@ namespace Clara { }; void parseIntoTokens( int argc, char const * const * argv, std::vector& tokens ) const { - for( int i = 1; i < argc; ++i ) + const std::string doubleDash = "--"; + for( int i = 1; i < argc && argv[i] != doubleDash; ++i ) parseIntoTokens( argv[i] , tokens); } void parseIntoTokens( std::string arg, std::vector& tokens ) const { @@ -6178,7 +6179,7 @@ namespace Catch { namespace Catch { // These numbers are maintained by a script - Version libraryVersion( 1, 0, 22, "master" ); + Version libraryVersion( 1, 0, 23, "master" ); } // #included from: catch_text.hpp