mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 12:17:11 +01:00 
			
		
		
		
	Arg::parse accepts plain Args as argument
This commit is contained in:
		| @@ -50,7 +50,7 @@ namespace Catch { | ||||
|                         analysis.outlier_variance, | ||||
|                     }; | ||||
|                 } else { | ||||
|                     std::vector<Duration> samples;  | ||||
|                     std::vector<Duration> samples; | ||||
|                     samples.reserve(last - first); | ||||
|  | ||||
|                     Duration mean = Duration(0); | ||||
|   | ||||
| @@ -494,6 +494,7 @@ namespace Catch { | ||||
|         class Arg : public Detail::ParserRefImpl<Arg> { | ||||
|         public: | ||||
|             using ParserRefImpl::ParserRefImpl; | ||||
|             using ParserBase::parse; | ||||
|  | ||||
|             Detail::InternalParseResult | ||||
|                 parse(std::string const&, | ||||
|   | ||||
| @@ -11,7 +11,7 @@ | ||||
| #include <iosfwd> | ||||
|  | ||||
| namespace Catch { | ||||
|          | ||||
|  | ||||
|     struct ITransientExpression; | ||||
|  | ||||
|     class LazyExpression { | ||||
|   | ||||
| @@ -16,6 +16,7 @@ endif(MSVC) #Temporary workaround | ||||
| # Please keep these ordered alphabetically | ||||
| set(TEST_SOURCES | ||||
|         ${SELF_TEST_DIR}/TestRegistrations.cpp | ||||
|         ${SELF_TEST_DIR}/IntrospectiveTests/Clara.tests.cpp | ||||
|         ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp | ||||
|         ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp | ||||
|         ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp | ||||
|   | ||||
| @@ -99,6 +99,7 @@ Nor would this | ||||
| :test-result: PASS CAPTURE parses string and character constants | ||||
| :test-result: PASS Capture and info messages | ||||
| :test-result: PASS Character pretty printing | ||||
| :test-result: PASS Clara::Arg supports single-arg parse the way Opt does | ||||
| :test-result: PASS Combining MatchAllOfGeneric does not nest | ||||
| :test-result: PASS Combining MatchAnyOfGeneric does not nest | ||||
| :test-result: PASS Combining MatchNotOfGeneric does not nest | ||||
|   | ||||
| @@ -344,6 +344,8 @@ ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 2 == 2 | ||||
| ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 3 == 3 | ||||
| ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 4 == 4 | ||||
| ToStringGeneral.tests.cpp:<line number>: passed: c == i for: 5 == 5 | ||||
| Clara.tests.cpp:<line number>: passed: name.empty() for: true | ||||
| Clara.tests.cpp:<line number>: passed: name == "foo" for: "foo" == "foo" | ||||
| Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC> >::value' | ||||
| Matchers.tests.cpp:<line number>: passed: 1, (MatcherA() && MatcherB()) && MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) | ||||
| Matchers.tests.cpp:<line number>: passed: with 1 message: 'std::is_same< decltype(MatcherA() && (MatcherB() && MatcherC())), Catch::Matchers::Detail::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC> >::value' | ||||
|   | ||||
| @@ -1380,6 +1380,6 @@ due to unexpected exception with message: | ||||
|   Why would you throw a std::string? | ||||
|  | ||||
| =============================================================================== | ||||
| test cases:  350 |  276 passed |  70 failed |  4 failed as expected | ||||
| assertions: 1990 | 1838 passed | 131 failed | 21 failed as expected | ||||
| test cases:  351 |  277 passed |  70 failed |  4 failed as expected | ||||
| assertions: 1992 | 1840 passed | 131 failed | 21 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -2857,6 +2857,22 @@ ToStringGeneral.tests.cpp:<line number>: PASSED: | ||||
| with expansion: | ||||
|   5 == 5 | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Clara::Arg supports single-arg parse the way Opt does | ||||
| ------------------------------------------------------------------------------- | ||||
| Clara.tests.cpp:<line number> | ||||
| ............................................................................... | ||||
|  | ||||
| Clara.tests.cpp:<line number>: PASSED: | ||||
|   CHECK( name.empty() ) | ||||
| with expansion: | ||||
|   true | ||||
|  | ||||
| Clara.tests.cpp:<line number>: PASSED: | ||||
|   REQUIRE( name == "foo" ) | ||||
| with expansion: | ||||
|   "foo" == "foo" | ||||
|  | ||||
| ------------------------------------------------------------------------------- | ||||
| Combining MatchAllOfGeneric does not nest | ||||
| ------------------------------------------------------------------------------- | ||||
| @@ -15665,6 +15681,6 @@ Misc.tests.cpp:<line number> | ||||
| Misc.tests.cpp:<line number>: PASSED: | ||||
|  | ||||
| =============================================================================== | ||||
| test cases:  350 |  260 passed |  86 failed |  4 failed as expected | ||||
| assertions: 2007 | 1838 passed | 148 failed | 21 failed as expected | ||||
| test cases:  351 |  261 passed |  86 failed |  4 failed as expected | ||||
| assertions: 2009 | 1840 passed | 148 failed | 21 failed as expected | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <testsuitesloose text artifact | ||||
| > | ||||
|   <testsuite name="<exe-name>" errors="17" failures="132" tests="2008" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> | ||||
|   <testsuite name="<exe-name>" errors="17" failures="132" tests="2010" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> | ||||
|     <properties> | ||||
|       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> | ||||
|       <property name="random-seed" value="1"/> | ||||
| @@ -376,6 +376,7 @@ Exception.tests.cpp:<line number> | ||||
|     <testcase classname="<exe-name>.global" name="Character pretty printing/Specifically escaped" time="{duration}" status="run"/> | ||||
|     <testcase classname="<exe-name>.global" name="Character pretty printing/General chars" time="{duration}" status="run"/> | ||||
|     <testcase classname="<exe-name>.global" name="Character pretty printing/Low ASCII" time="{duration}" status="run"/> | ||||
|     <testcase classname="<exe-name>.global" name="Clara::Arg supports single-arg parse the way Opt does" time="{duration}" status="run"/> | ||||
|     <testcase classname="<exe-name>.global" name="Combining MatchAllOfGeneric does not nest" time="{duration}" status="run"/> | ||||
|     <testcase classname="<exe-name>.global" name="Combining MatchAnyOfGeneric does not nest" time="{duration}" status="run"/> | ||||
|     <testcase classname="<exe-name>.global" name="Combining MatchNotOfGeneric does not nest" time="{duration}" status="run"/> | ||||
|   | ||||
| @@ -1,6 +1,9 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <testExecutions version="1"loose text artifact | ||||
| > | ||||
|   <file path="tests/<exe-name>/IntrospectiveTests/Clara.tests.cpp"> | ||||
|     <testCase name="Clara::Arg supports single-arg parse the way Opt does" duration="{duration}"/> | ||||
|   </file> | ||||
|   <file path="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp"> | ||||
|     <testCase name="#1905 -- test spec parser properly clears internal state between compound tests" duration="{duration}"/> | ||||
|     <testCase name="#1912 -- test spec parser handles escaping/Various parentheses" duration="{duration}"/> | ||||
|   | ||||
| @@ -686,6 +686,10 @@ ok {test-number} - c == i for: 3 == 3 | ||||
| ok {test-number} - c == i for: 4 == 4 | ||||
| # Character pretty printing | ||||
| ok {test-number} - c == i for: 5 == 5 | ||||
| # Clara::Arg supports single-arg parse the way Opt does | ||||
| ok {test-number} - name.empty() for: true | ||||
| # Clara::Arg supports single-arg parse the way Opt does | ||||
| ok {test-number} - name == "foo" for: "foo" == "foo" | ||||
| # Combining MatchAllOfGeneric does not nest | ||||
| ok {test-number} - with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric<MatcherA, MatcherB, MatcherC> >::value' | ||||
| # Combining MatchAllOfGeneric does not nest | ||||
| @@ -4006,5 +4010,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 | ||||
| ok {test-number} - | ||||
| # xmlentitycheck | ||||
| ok {test-number} - | ||||
| 1..2007 | ||||
| 1..2009 | ||||
|  | ||||
|   | ||||
| @@ -231,6 +231,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n  "unexpe | ||||
| ##teamcity[testFinished name='Capture and info messages' duration="{duration}"] | ||||
| ##teamcity[testStarted name='Character pretty printing'] | ||||
| ##teamcity[testFinished name='Character pretty printing' duration="{duration}"] | ||||
| ##teamcity[testStarted name='Clara::Arg supports single-arg parse the way Opt does'] | ||||
| ##teamcity[testFinished name='Clara::Arg supports single-arg parse the way Opt does' duration="{duration}"] | ||||
| ##teamcity[testStarted name='Combining MatchAllOfGeneric does not nest'] | ||||
| ##teamcity[testFinished name='Combining MatchAllOfGeneric does not nest' duration="{duration}"] | ||||
| ##teamcity[testStarted name='Combining MatchAnyOfGeneric does not nest'] | ||||
|   | ||||
| @@ -3101,6 +3101,25 @@ Nor would this | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Clara::Arg supports single-arg parse the way Opt does" tags="[arg][clara]" filename="tests/<exe-name>/IntrospectiveTests/Clara.tests.cpp" > | ||||
|       <Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/Clara.tests.cpp" > | ||||
|         <Original> | ||||
|           name.empty() | ||||
|         </Original> | ||||
|         <Expanded> | ||||
|           true | ||||
|         </Expanded> | ||||
|       </Expression> | ||||
|       <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/Clara.tests.cpp" > | ||||
|         <Original> | ||||
|           name == "foo" | ||||
|         </Original> | ||||
|         <Expanded> | ||||
|           "foo" == "foo" | ||||
|         </Expanded> | ||||
|       </Expression> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <TestCase name="Combining MatchAllOfGeneric does not nest" tags="[matchers][templated]" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > | ||||
|       <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/Matchers.tests.cpp" > | ||||
|         <Original> | ||||
| @@ -18579,9 +18598,9 @@ loose text artifact | ||||
|       </Section> | ||||
|       <OverallResult success="true"/> | ||||
|     </TestCase> | ||||
|     <OverallResults successes="1838" failures="149" expectedFailures="21"/> | ||||
|     <OverallResultsCases successes="260" failures="86" expectedFailures="4"/> | ||||
|     <OverallResults successes="1840" failures="149" expectedFailures="21"/> | ||||
|     <OverallResultsCases successes="261" failures="86" expectedFailures="4"/> | ||||
|   </Group> | ||||
|   <OverallResults successes="1838" failures="148" expectedFailures="21"/> | ||||
|   <OverallResultsCases successes="260" failures="86" expectedFailures="4"/> | ||||
|   <OverallResults successes="1840" failures="148" expectedFailures="21"/> | ||||
|   <OverallResultsCases successes="261" failures="86" expectedFailures="4"/> | ||||
| </Catch> | ||||
|   | ||||
							
								
								
									
										22
									
								
								tests/SelfTest/IntrospectiveTests/Clara.tests.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								tests/SelfTest/IntrospectiveTests/Clara.tests.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| //              Copyright Catch2 Authors | ||||
| // Distributed under the Boost Software License, Version 1.0. | ||||
| //   (See accompanying file LICENSE_1_0.txt or copy at | ||||
| //        https://www.boost.org/LICENSE_1_0.txt) | ||||
|  | ||||
| // SPDX-License-Identifier: BSL-1.0 | ||||
|      | ||||
| #include <catch2/catch_test_macros.hpp> | ||||
| #include <catch2/internal/catch_clara.hpp> | ||||
|  | ||||
|  | ||||
| #include <string> | ||||
|  | ||||
| TEST_CASE("Clara::Arg supports single-arg parse the way Opt does", "[clara][arg][compilation]") { | ||||
|     std::string name; | ||||
|     auto p = Catch::Clara::Arg(name, "just one arg"); | ||||
|      | ||||
|     CHECK(name.empty()); | ||||
|      | ||||
|     p.parse( Catch::Clara::Args{ "UnitTest", "foo" } ); | ||||
|     REQUIRE(name == "foo"); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský