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

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/CmdLineTests.cpp
diff options
context:
space:
mode:
authorPhil Nash2014-03-06 08:16:06 +0000
committerPhil Nash2014-03-06 08:16:06 +0000
commitb9fea75109c4d4c372067b651a2df9733b748879 (patch)
tree7ed05dd15a8aca402492b31a90314e51e266fd1b /projects/SelfTest/CmdLineTests.cpp
parent1f1ee3c63d9bc97cb6e0ede26e22019fd867e643 (diff)
downloadcatch3-b9fea75109c4d4c372067b651a2df9733b748879.tar.gz
New version of Clara.
- updated command line setup with new API - updated STITCH macros - force embedded Clara to use Catch’s console width (but restore it after) - remove command line tests (as these have now moved into the Clara project)
Diffstat (limited to 'projects/SelfTest/CmdLineTests.cpp')
-rw-r--r--projects/SelfTest/CmdLineTests.cpp192
1 files changed, 0 insertions, 192 deletions
diff --git a/projects/SelfTest/CmdLineTests.cpp b/projects/SelfTest/CmdLineTests.cpp
deleted file mode 100644
index 8d003fed..00000000
--- a/projects/SelfTest/CmdLineTests.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Created by Phil on 22/10/2010.
- * Copyright 2010 Two Blue Cubes Ltd
- *
- * Distributed under the Boost Software License, Version 1.0. (See accompanying
- * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- */
-#ifdef __clang__
-#pragma clang diagnostic ignored "-Wpadded"
-#endif
-
-#include "internal/clara.h" // This will does not declare Clara within the Catch namespace
-
-#include "catch.hpp"
-
-
-// Helper to deduce size from array literals and pass on to parser
-template<size_t size, typename ConfigT>
-std::vector<Clara::Parser::Token> parseInto( Clara::CommandLine<ConfigT>& cli, char const * (&argv)[size], ConfigT& config ) {
- return cli.parseInto( size, argv, config );
-}
-
-
-struct TestOpt {
- TestOpt() : number( 0 ), index( 0 ), flag( false ) {}
-
- std::string processName;
- std::string fileName;
- int number;
- int index;
- bool flag;
- std::string firstPos;
- std::string secondPos;
- std::string unpositional;
-
- void setValidIndex( int i ) {
- if( i < 0 || i > 10 )
- throw std::domain_error( "index must be between 0 and 10" );
- index = i;
- }
-};
-
-struct TestOpt2 {
- std::string description;
-};
-
-#ifdef CATCH_CONFIG_VARIADIC_MACROS
-
-TEST_CASE( "cmdline" ) {
-
- TestOpt config;
- Clara::CommandLine<TestOpt> cli;
- cli.bindProcessName( &TestOpt::processName );
- cli.bind( &TestOpt::fileName )
- .describe( "specifies output file" )
- .shortOpt( "o" )
- .longOpt( "output" )
- .hint( "filename" );
-
- SECTION( "process name" ) {
- char const * argv[] = { "test", "-o filename.ext" };
- parseInto( cli, argv, config );
-
- CHECK( config.processName == "test" );
- }
- SECTION( "arg separated by spaces" ) {
- char const * argv[] = { "test", "-o filename.ext" };
- parseInto( cli, argv, config );
-
- CHECK( config.fileName == "filename.ext" );
- }
- SECTION( "arg separated by colon" ) {
- const char* argv[] = { "test", "-o:filename.ext" };
- parseInto( cli, argv, config );
-
- CHECK( config.fileName == "filename.ext" );
- }
- SECTION( "arg separated by =" ) {
- const char* argv[] = { "test", "-o=filename.ext" };
- parseInto( cli, argv, config );
-
- CHECK( config.fileName == "filename.ext" );
- }
- SECTION( "long opt" ) {
- const char* argv[] = { "test", "--output %stdout" };
- parseInto( cli, argv, config );
-
- CHECK( config.fileName == "%stdout" );
- }
-
- cli.bind( &TestOpt::number )
- .shortOpt( "n" )
- .hint( "an integral value" );
-
- SECTION( "a number" ) {
- const char* argv[] = { "test", "-n 42" };
- parseInto( cli, argv, config );
-
- CHECK( config.number == 42 );
- }
- SECTION( "not a number" ) {
- const char* argv[] = { "test", "-n forty-two" };
- CHECK_THROWS( parseInto( cli, argv, config ) );
-
- CHECK( config.number == 0 );
- }
-
- SECTION( "two parsers" ) {
-
- TestOpt config1;
- TestOpt2 config2;
- Clara::CommandLine<TestOpt2> cli2;
-
- cli2.bind( &TestOpt2::description )
- .describe( "description" )
- .shortOpt( "d" )
- .longOpt( "description" )
- .hint( "some text" );
-
- const char* argv[] = { "test", "-n 42", "-d some text" };
- std::vector<Clara::Parser::Token> unusedTokens = parseInto( cli, argv, config1 );
-
- CHECK( config1.number == 42 );
-
- REQUIRE_FALSE( unusedTokens.empty() );
- cli2.populate( unusedTokens, config2 );
- CHECK( config2.description == "some text" );
- }
-
- SECTION( "methods" ) {
- cli.bind( &TestOpt::setValidIndex )
- .describe( "An index, which is an integer between 0 and 10, inclusive" )
- .shortOpt( "i" )
- .hint( "index" );
-
- SECTION( "in range" ) {
- const char* argv[] = { "test", "-i 3" };
- parseInto( cli, argv, config );
-
- REQUIRE( config.index == 3 );
- }
- SECTION( "out of range" ) {
- const char* argv[] = { "test", "-i 42" };
-
- REQUIRE_THROWS( parseInto( cli, argv, config ) );
- }
- }
-
- SECTION( "flags" ) {
- cli.bind( &TestOpt::flag )
- .describe( "A flag" )
- .shortOpt( "f" );
-
- SECTION( "set" ) {
- const char* argv[] = { "test", "-f" };
- parseInto( cli, argv, config );
-
- REQUIRE( config.flag );
- }
- SECTION( "not set" ) {
- const char* argv[] = { "test" };
- parseInto( cli, argv, config );
-
- REQUIRE( config.flag == false );
- }
- }
- SECTION( "positional" ) {
- cli.bind( &TestOpt::secondPos )
- .describe( "Second position" )
- .hint( "second arg" )
- .position( 2 );
- cli.bind( &TestOpt::unpositional )
- .hint( "any arg" )
- .describe( "Unpositional" );
- cli.bind( &TestOpt::firstPos )
- .describe( "First position" )
- .hint( "first arg" )
- .position( 1 );
-
-// std::cout << cli.usage( "testApp" ) << std::endl;
-
- const char* argv[] = { "test", "-f", "1st", "-o", "filename", "2nd", "3rd" };
- parseInto( cli, argv, config );
-
- REQUIRE( config.firstPos == "1st" );
- REQUIRE( config.secondPos == "2nd" );
- REQUIRE( config.unpositional == "3rd" );
- }
-}
-
-
-#endif