From 135103bacf917330dbc6217e9228f8c6a65313cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 7 Nov 2020 17:51:50 +0100 Subject: [PATCH] Arg::parse accepts plain Args as argument --- src/catch2/benchmark/detail/catch_analyse.hpp | 2 +- src/catch2/internal/catch_clara.hpp | 1 + src/catch2/internal/catch_lazy_expr.hpp | 2 +- tests/CMakeLists.txt | 1 + .../Baselines/automake.sw.approved.txt | 1 + .../Baselines/compact.sw.approved.txt | 2 ++ .../Baselines/console.std.approved.txt | 4 +-- .../Baselines/console.sw.approved.txt | 20 ++++++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 ++- .../Baselines/sonarqube.sw.approved.txt | 3 +++ tests/SelfTest/Baselines/tap.sw.approved.txt | 6 ++++- .../Baselines/teamcity.sw.approved.txt | 2 ++ tests/SelfTest/Baselines/xml.sw.approved.txt | 27 ++++++++++++++++--- .../IntrospectiveTests/Clara.tests.cpp | 22 +++++++++++++++ 14 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 tests/SelfTest/IntrospectiveTests/Clara.tests.cpp diff --git a/src/catch2/benchmark/detail/catch_analyse.hpp b/src/catch2/benchmark/detail/catch_analyse.hpp index 57739b98..0a52a845 100644 --- a/src/catch2/benchmark/detail/catch_analyse.hpp +++ b/src/catch2/benchmark/detail/catch_analyse.hpp @@ -50,7 +50,7 @@ namespace Catch { analysis.outlier_variance, }; } else { - std::vector samples; + std::vector samples; samples.reserve(last - first); Duration mean = Duration(0); diff --git a/src/catch2/internal/catch_clara.hpp b/src/catch2/internal/catch_clara.hpp index 92244293..2da6919a 100644 --- a/src/catch2/internal/catch_clara.hpp +++ b/src/catch2/internal/catch_clara.hpp @@ -494,6 +494,7 @@ namespace Catch { class Arg : public Detail::ParserRefImpl { public: using ParserRefImpl::ParserRefImpl; + using ParserBase::parse; Detail::InternalParseResult parse(std::string const&, diff --git a/src/catch2/internal/catch_lazy_expr.hpp b/src/catch2/internal/catch_lazy_expr.hpp index 9ebb2f4d..e69a72ef 100644 --- a/src/catch2/internal/catch_lazy_expr.hpp +++ b/src/catch2/internal/catch_lazy_expr.hpp @@ -11,7 +11,7 @@ #include namespace Catch { - + struct ITransientExpression; class LazyExpression { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a7651a03..7a3c6deb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 4d599486..45e62ac5 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -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 diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index a7fb6780..bbb50a93 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -344,6 +344,8 @@ ToStringGeneral.tests.cpp:: passed: c == i for: 2 == 2 ToStringGeneral.tests.cpp:: passed: c == i for: 3 == 3 ToStringGeneral.tests.cpp:: passed: c == i for: 4 == 4 ToStringGeneral.tests.cpp:: passed: c == i for: 5 == 5 +Clara.tests.cpp:: passed: name.empty() for: true +Clara.tests.cpp:: passed: name == "foo" for: "foo" == "foo" Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype((MatcherA() && MatcherB()) && MatcherC()), Catch::Matchers::Detail::MatchAllOfGeneric >::value' Matchers.tests.cpp:: 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:: passed: with 1 message: 'std::is_same< decltype(MatcherA() && (MatcherB() && MatcherC())), Catch::Matchers::Detail::MatchAllOfGeneric >::value' diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 727cdda5..2440a763 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -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 diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 9442de74..d8a60b83 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -2857,6 +2857,22 @@ ToStringGeneral.tests.cpp:: PASSED: with expansion: 5 == 5 +------------------------------------------------------------------------------- +Clara::Arg supports single-arg parse the way Opt does +------------------------------------------------------------------------------- +Clara.tests.cpp: +............................................................................... + +Clara.tests.cpp:: PASSED: + CHECK( name.empty() ) +with expansion: + true + +Clara.tests.cpp:: PASSED: + REQUIRE( name == "foo" ) +with expansion: + "foo" == "foo" + ------------------------------------------------------------------------------- Combining MatchAllOfGeneric does not nest ------------------------------------------------------------------------------- @@ -15665,6 +15681,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 0d5804c4..21464c62 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -376,6 +376,7 @@ Exception.tests.cpp: + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index ff0a3d28..96ebb9a0 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -1,6 +1,9 @@ + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 52ea17cc..c07c22bd 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -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 >::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 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index e63b1502..b9da3591 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -231,6 +231,8 @@ Exception.tests.cpp:|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'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index bc92435e..74c1c1a4 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -3101,6 +3101,25 @@ Nor would this + + + + name.empty() + + + true + + + + + name == "foo" + + + "foo" == "foo" + + + + @@ -18579,9 +18598,9 @@ loose text artifact - - + + - - + + diff --git a/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp b/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp new file mode 100644 index 00000000..1259e7ff --- /dev/null +++ b/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp @@ -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 +#include + + +#include + +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"); +}