mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-01-15 22:58:02 +00:00
Compare commits
7 Commits
34c4310d99
...
97f5460fbe
Author | SHA1 | Date | |
---|---|---|---|
|
97f5460fbe | ||
|
51ea7ebeb0 | ||
|
3eb5e1eedd | ||
|
fa423c4558 | ||
|
fdedfb6426 | ||
|
5d12e11d8a | ||
|
b00b56061a |
16
.github/actions/cmake_config/Dockerfile
vendored
16
.github/actions/cmake_config/Dockerfile
vendored
@ -1,16 +0,0 @@
|
||||
FROM ubuntu:18.04
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
g++=4:7.4.0-1ubuntu2.3 \
|
||||
wget=1.19.4-1ubuntu2.2 \
|
||||
libidn11=1.33-2.1ubuntu1.2 \
|
||||
ca-certificates=20180409 \
|
||||
make=4.1-9.1ubuntu1 \
|
||||
git=1:2.17.1-1ubuntu0.7 \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
16
.github/actions/cmake_config/action.yml
vendored
16
.github/actions/cmake_config/action.yml
vendored
@ -1,16 +0,0 @@
|
||||
description: 'Test out a bare bones configuration with a CMake version'
|
||||
inputs:
|
||||
version:
|
||||
description: 'The full version of CMake to check'
|
||||
required: true
|
||||
options:
|
||||
description: 'The CMake configuration options'
|
||||
required: false
|
||||
default: ""
|
||||
name: 'Configure with CMake'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.version }}
|
||||
- ${{ inputs.options }}
|
23
.github/actions/cmake_config/entrypoint.sh
vendored
23
.github/actions/cmake_config/entrypoint.sh
vendored
@ -1,23 +0,0 @@
|
||||
#!/bin/bash -l
|
||||
|
||||
set -ex
|
||||
|
||||
mkdir -p cmake_dir
|
||||
mkdir -p build_tmp
|
||||
mkdir -p cmake_sources
|
||||
rm -rf cmake_dir/* build_tmp/*
|
||||
|
||||
v=$1
|
||||
fn=cmake-$v-Linux-x86_64.tar.gz
|
||||
|
||||
if [ ! -f cmake_sources/$fn ]; then
|
||||
wget -qO cmake_sources/$fn "https://cmake.org/files/v${v%.*}/$fn"
|
||||
fi
|
||||
|
||||
tar -xzf cmake_sources/$fn --strip-components=1 -C $PWD/cmake_dir
|
||||
|
||||
export PATH=$PWD/cmake_dir/bin:$PATH
|
||||
|
||||
cmake --version
|
||||
|
||||
cd build_tmp && cmake .. $2
|
18
.github/actions/quick_cmake/action.yml
vendored
Normal file
18
.github/actions/quick_cmake/action.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: Quick CMake config
|
||||
description: 'Runs CMake 3.4+ (if already setup)'
|
||||
inputs:
|
||||
args:
|
||||
description: 'Other arguments'
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- run: |
|
||||
mkdir -p build-tmp
|
||||
touch build-tmp/tmp
|
||||
rm -r build-tmp/*
|
||||
(cd build-tmp && cmake .. ${{ inputs.args}})
|
||||
rm -r build-tmp
|
||||
shell: bash
|
135
.github/workflows/tests.yml
vendored
135
.github/workflows/tests.yml
vendored
@ -39,81 +39,144 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: CMake 3.4
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.4.3
|
||||
cmake-version: "3.4"
|
||||
- name: Check CMake 3.4
|
||||
uses: ./.github/actions/quick_cmake
|
||||
|
||||
- name: CMake 3.5
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.5.2
|
||||
cmake-version: "3.5"
|
||||
- name: Check CMake 3.5
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.6
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.6.3
|
||||
cmake-version: "3.6"
|
||||
- name: Check CMake 3.6
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.7
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.7.2
|
||||
cmake-version: "3.7"
|
||||
- name: Check CMake 3.7
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.8
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.8.2
|
||||
cmake-version: "3.8"
|
||||
- name: Check CMake 3.8
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.9
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.9.6
|
||||
cmake-version: "3.9"
|
||||
- name: Check CMake 3.9
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.10
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.10.3
|
||||
cmake-version: "3.10"
|
||||
- name: Check CMake 3.10
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
- name: CMake 3.11 (full)
|
||||
uses: ./.github/actions/cmake_config
|
||||
|
||||
- name: CMake 3.11
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.11.4
|
||||
options: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
|
||||
cmake-version: "3.11"
|
||||
- name: Check CMake 3.11 (full)
|
||||
uses: ./.github/actions/quick_cmake
|
||||
with:
|
||||
args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.12
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.12.4
|
||||
cmake-version: "3.12"
|
||||
- name: Check CMake 3.12
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.13
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.13.5
|
||||
cmake-version: "3.13"
|
||||
- name: Check CMake 3.13
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.14
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.14.7
|
||||
cmake-version: "3.14"
|
||||
- name: Check CMake 3.14
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.15
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.15.6
|
||||
cmake-version: "3.15"
|
||||
- name: Check CMake 3.15
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.16
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.16.8
|
||||
cmake-version: "3.16"
|
||||
- name: Check CMake 3.16
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.17
|
||||
uses: ./.github/actions/cmake_config
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.17.3
|
||||
cmake-version: "3.17"
|
||||
- name: Check CMake 3.17
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
- name: CMake 3.18 (full)
|
||||
uses: ./.github/actions/cmake_config
|
||||
|
||||
- name: CMake 3.18
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
version: 3.18.0
|
||||
options: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
|
||||
cmake-version: "3.18"
|
||||
- name: Check CMake 3.18
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.19
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
cmake-version: "3.19"
|
||||
- name: Check CMake 3.19 (full)
|
||||
uses: ./.github/actions/quick_cmake
|
||||
with:
|
||||
args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
|
||||
if: success() || failure()
|
||||
|
||||
- name: CMake 3.20
|
||||
uses: jwlawson/actions-setup-cmake@v1.8
|
||||
with:
|
||||
cmake-version: "3.20"
|
||||
- name: Check CMake 3.20
|
||||
uses: ./.github/actions/quick_cmake
|
||||
if: success() || failure()
|
||||
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ a.out*
|
||||
/node_modules/*
|
||||
/package.json
|
||||
/yarn.lock
|
||||
/CLI11.hpp
|
||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "extern/googletest"]
|
||||
path = extern/googletest
|
||||
url = ../../google/googletest.git
|
36
CHANGELOG.md
36
CHANGELOG.md
@ -1,14 +1,42 @@
|
||||
## Version 2.0: In progress
|
||||
|
||||
* Built-in config format is TOML compliant now [#435]
|
||||
* Config updates [#442]
|
||||
* More powerful containers, `%%` separator [#423]
|
||||
* Add a version flag easily [#452]
|
||||
* Built-in config format is TOML compliant now [#435][]
|
||||
* Support multiline TOML [#528][]
|
||||
* Support short/positional options in config mode [#443][]
|
||||
* More powerful containers, `%%` separator [#423][]
|
||||
* Add a version flag easily [#452][]
|
||||
* Support atomic types [#520][]
|
||||
* Add a type validator `CLI::TypeValidator<TYPE>` [#526][]
|
||||
* Support `->silent()` on subcommands. [#529][]
|
||||
* Add alias section to help for subcommands [#545][]
|
||||
* Redesigned MakeSingleFiles to have a higher level of manual control, to support future features. [#546][]
|
||||
* Moved testing from GTest to Catch2 [#574][]
|
||||
|
||||
* Bugfix: avoid listing helpall as a required flag [#530][]
|
||||
* Bugfix: avoid a clash with WINDOWS define [#563][]
|
||||
|
||||
* Removed deprecated set commands, use validators instead. [#565][]
|
||||
|
||||
* Build: support pkg-config [#523][]
|
||||
|
||||
|
||||
[#435]: https://github.com/CLIUtils/CLI11/pull/435
|
||||
[#443]: https://github.com/CLIUtils/CLI11/pull/443
|
||||
[#423]: https://github.com/CLIUtils/CLI11/pull/423
|
||||
[#452]: https://github.com/CLIUtils/CLI11/pull/452
|
||||
[#520]: https://github.com/CLIUtils/CLI11/pull/520
|
||||
[#523]: https://github.com/CLIUtils/CLI11/pull/523
|
||||
[#526]: https://github.com/CLIUtils/CLI11/pull/526
|
||||
[#528]: https://github.com/CLIUtils/CLI11/pull/528
|
||||
[#529]: https://github.com/CLIUtils/CLI11/pull/529
|
||||
[#530]: https://github.com/CLIUtils/CLI11/pull/530
|
||||
[#545]: https://github.com/CLIUtils/CLI11/pull/545
|
||||
[#546]: https://github.com/CLIUtils/CLI11/pull/546
|
||||
[#563]: https://github.com/CLIUtils/CLI11/pull/563
|
||||
[#565]: https://github.com/CLIUtils/CLI11/pull/565
|
||||
[#574]: https://github.com/CLIUtils/CLI11/pull/574
|
||||
|
||||
|
||||
|
||||
|
||||
### Version 1.9.1: Backporting fixes
|
||||
|
@ -5,6 +5,8 @@ linelength=120 # As in .clang-format
|
||||
filter=-build/c++11 # Reports e.g. chrono and thread, which overlap with Chromium's API. Not applicable to general C++ projects.
|
||||
filter=-build/include_order # Requires unusual include order that encourages creating not self-contained headers
|
||||
filter=-readability/nolint # Conflicts with clang-tidy
|
||||
filter=-readability/check # Catch uses CHECK(a == b) (Tests only)
|
||||
filter=-build/namespaces # Currently using it for one test (Tests only)
|
||||
filter=-runtime/references # Requires fundamental change of API, don't see need for this
|
||||
filter=-whitespace/blank_line # Unnecessarily strict with blank lines that otherwise help with readability
|
||||
filter=-whitespace/indent # Requires strange 3-space indent of private/protected/public markers
|
||||
|
@ -224,7 +224,7 @@ While all options internally are the same type, there are several ways to add an
|
||||
app.add_option(option_name, help_str="")
|
||||
|
||||
app.add_option(option_name,
|
||||
variable_to_bind_to, // bool, char(see note)🚧, int, float, vector, enum, or string-like, or anything with a defined conversion from a string or that takes an int 🆕, double 🆕, or string in a constructor. Also allowed are tuples 🆕, std::array 🆕 or std::pair 🆕. Also supported are complex numbers🚧, wrapper types🚧, and containers besides vector🚧 of any other supported type.
|
||||
variable_to_bind_to, // bool, char(see note)🚧, int, float, vector, enum, std::atomic 🚧, or string-like, or anything with a defined conversion from a string or that takes an int 🆕, double 🆕, or string in a constructor. Also allowed are tuples 🆕, std::array 🆕 or std::pair 🆕. Also supported are complex numbers🚧, wrapper types🚧, and containers besides vector🚧 of any other supported type.
|
||||
help_string="")
|
||||
|
||||
app.add_option_function<type>(option_name,
|
||||
@ -245,7 +245,7 @@ app.add_flag(option_name,
|
||||
help_string="")
|
||||
|
||||
app.add_flag(option_name,
|
||||
variable_to_bind_to, // bool, int, float, complex, containers, enum, or string-like, or any singular object with a defined conversion from a string like add_option
|
||||
variable_to_bind_to, // bool, int, float, complex, containers, enum, std::atomic 🚧, or string-like, or any singular object with a defined conversion from a string like add_option
|
||||
help_string="")
|
||||
|
||||
app.add_flag_function(option_name,
|
||||
|
@ -121,7 +121,7 @@ jobs:
|
||||
cli11.std: 17
|
||||
cli11.options: -DCLI11_FORCE_LIBCXX=ON
|
||||
clang10_20:
|
||||
containerImage: helics/buildenv:clang10-builder
|
||||
containerImage: silkeh/clang:10
|
||||
cli11.std: 20
|
||||
cli11.options: -DCLI11_FORCE_LIBCXX=ON -DCMAKE_CXX_FLAGS=-std=c++20
|
||||
container: $[ variables['containerImage'] ]
|
||||
|
@ -1,49 +0,0 @@
|
||||
#
|
||||
#
|
||||
# Includes GTest and provides a helper macro to add tests. Add make check, as well, which
|
||||
# gives output on failed tests without having to set an environment variable.
|
||||
#
|
||||
#
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
add_subdirectory("${CLI11_SOURCE_DIR}/extern/googletest" "${CLI11_BINARY_DIR}/extern/googletest" EXCLUDE_FROM_ALL)
|
||||
|
||||
|
||||
if(GOOGLE_TEST_INDIVIDUAL)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
|
||||
include(GoogleTest)
|
||||
else()
|
||||
set(GOOGLE_TEST_INDIVIDUAL OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Target must already exist
|
||||
macro(add_gtest TESTNAME)
|
||||
target_link_libraries(${TESTNAME} PUBLIC gtest gmock gtest_main)
|
||||
|
||||
if(GOOGLE_TEST_INDIVIDUAL)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.10)
|
||||
gtest_add_tests(TARGET ${TESTNAME}
|
||||
TEST_PREFIX "${TESTNAME}."
|
||||
TEST_LIST TmpTestList)
|
||||
set_tests_properties(${TmpTestList} PROPERTIES FOLDER "Tests")
|
||||
else()
|
||||
gtest_discover_tests(${TESTNAME}
|
||||
TEST_PREFIX "${TESTNAME}."
|
||||
PROPERTIES FOLDER "Tests")
|
||||
|
||||
endif()
|
||||
else()
|
||||
add_test(${TESTNAME} ${TESTNAME})
|
||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
||||
if (CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET ${T} APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
set_target_properties(gtest gtest_main gmock gmock_main
|
||||
PROPERTIES FOLDER "Extern")
|
1
extern/googletest
vendored
1
extern/googletest
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 859bfe8981d6724c4ea06e73d29accd8588f3230
|
@ -44,7 +44,7 @@ namespace CLI {
|
||||
#endif
|
||||
|
||||
namespace detail {
|
||||
enum class Classifier { NONE, POSITIONAL_MARK, SHORT, LONG, WINDOWS, SUBCOMMAND, SUBCOMMAND_TERMINATOR };
|
||||
enum class Classifier { NONE, POSITIONAL_MARK, SHORT, LONG, WINDOWS_STYLE, SUBCOMMAND, SUBCOMMAND_TERMINATOR };
|
||||
struct AppFriend;
|
||||
} // namespace detail
|
||||
|
||||
@ -897,56 +897,6 @@ class App {
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Add set of options (No default, temp reference, such as an inline set) DEPRECATED
|
||||
template <typename T>
|
||||
Option *add_set(std::string option_name,
|
||||
T &member, ///< The selected member of the set
|
||||
std::set<T> options, ///< The set of possibilities
|
||||
std::string option_description = "") {
|
||||
|
||||
Option *opt = add_option(option_name, member, std::move(option_description));
|
||||
opt->check(IsMember{options});
|
||||
return opt;
|
||||
}
|
||||
|
||||
/// Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED
|
||||
template <typename T>
|
||||
Option *add_mutable_set(std::string option_name,
|
||||
T &member, ///< The selected member of the set
|
||||
const std::set<T> &options, ///< The set of possibilities
|
||||
std::string option_description = "") {
|
||||
|
||||
Option *opt = add_option(option_name, member, std::move(option_description));
|
||||
opt->check(IsMember{&options});
|
||||
return opt;
|
||||
}
|
||||
|
||||
/// Add set of options (with default, static set, such as an inline set) DEPRECATED
|
||||
template <typename T>
|
||||
Option *add_set(std::string option_name,
|
||||
T &member, ///< The selected member of the set
|
||||
std::set<T> options, ///< The set of possibilities
|
||||
std::string option_description,
|
||||
bool defaulted) {
|
||||
|
||||
Option *opt = add_option(option_name, member, std::move(option_description), defaulted);
|
||||
opt->check(IsMember{options});
|
||||
return opt;
|
||||
}
|
||||
|
||||
/// Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED
|
||||
template <typename T>
|
||||
Option *add_mutable_set(std::string option_name,
|
||||
T &member, ///< The selected member of the set
|
||||
const std::set<T> &options, ///< The set of possibilities
|
||||
std::string option_description,
|
||||
bool defaulted) {
|
||||
|
||||
Option *opt = add_option(option_name, member, std::move(option_description), defaulted);
|
||||
opt->check(IsMember{&options});
|
||||
return opt;
|
||||
}
|
||||
|
||||
/// Add a complex number DEPRECATED --use add_option instead
|
||||
template <typename T, typename XC = double>
|
||||
Option *add_complex(std::string option_name,
|
||||
@ -2072,7 +2022,7 @@ class App {
|
||||
return detail::Classifier::SHORT;
|
||||
}
|
||||
if((allow_windows_style_options_) && (detail::split_windows_style(current, dummy1, dummy2)))
|
||||
return detail::Classifier::WINDOWS;
|
||||
return detail::Classifier::WINDOWS_STYLE;
|
||||
if((current == "++") && !name_.empty() && parent_ != nullptr)
|
||||
return detail::Classifier::SUBCOMMAND_TERMINATOR;
|
||||
return detail::Classifier::NONE;
|
||||
@ -2525,7 +2475,7 @@ class App {
|
||||
break;
|
||||
case detail::Classifier::LONG:
|
||||
case detail::Classifier::SHORT:
|
||||
case detail::Classifier::WINDOWS:
|
||||
case detail::Classifier::WINDOWS_STYLE:
|
||||
// If already parsed a subcommand, don't accept options_
|
||||
_parse_arg(args, classifier);
|
||||
break;
|
||||
@ -2742,7 +2692,7 @@ class App {
|
||||
if(!detail::split_short(current, arg_name, rest))
|
||||
throw HorribleError("Short parsed but missing! You should not see this");
|
||||
break;
|
||||
case detail::Classifier::WINDOWS:
|
||||
case detail::Classifier::WINDOWS_STYLE:
|
||||
if(!detail::split_windows_style(current, arg_name, value))
|
||||
throw HorribleError("windows option parsed but missing! You should not see this");
|
||||
break;
|
||||
@ -2760,7 +2710,7 @@ class App {
|
||||
return opt->check_lname(arg_name);
|
||||
if(current_type == detail::Classifier::SHORT)
|
||||
return opt->check_sname(arg_name);
|
||||
// this will only get called for detail::Classifier::WINDOWS
|
||||
// this will only get called for detail::Classifier::WINDOWS_STYLE
|
||||
return opt->check_lname(arg_name) || opt->check_sname(arg_name);
|
||||
});
|
||||
|
||||
|
1217
tests/AppTest.cpp
1217
tests/AppTest.cpp
File diff suppressed because it is too large
Load Diff
@ -15,137 +15,112 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
using namespace boost::container;
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
TEMPLATE_TEST_CASE("Boost container single",
|
||||
"[boost][optional]",
|
||||
(small_vector<int, 2>),
|
||||
(small_vector<int, 3>),
|
||||
flat_set<int>,
|
||||
stable_vector<int>,
|
||||
slist<int>) {
|
||||
TApp tapp;
|
||||
TestType cv;
|
||||
CLI::Option *opt = tapp.app.add_option("-v", cv);
|
||||
|
||||
template <class T> class TApp_container_single_boost : public TApp {
|
||||
public:
|
||||
using container_type = T;
|
||||
container_type cval{};
|
||||
TApp_container_single_boost() : TApp() {}
|
||||
};
|
||||
|
||||
using containerTypes_single_boost =
|
||||
::testing::Types<small_vector<int, 2>, small_vector<int, 3>, flat_set<int>, stable_vector<int>, slist<int>>;
|
||||
|
||||
TYPED_TEST_SUITE(TApp_container_single_boost, containerTypes_single_boost, );
|
||||
|
||||
TYPED_TEST(TApp_container_single_boost, containerInt_boost) {
|
||||
|
||||
auto &cv = TApp_container_single_boost<TypeParam>::cval;
|
||||
CLI::Option *opt = (TApp::app).add_option("-v", cv);
|
||||
|
||||
TApp::args = {"-v", "1", "-1", "-v", "3", "-v", "-976"};
|
||||
TApp::run();
|
||||
EXPECT_EQ(4u, (TApp::app).count("-v"));
|
||||
EXPECT_EQ(4u, cv.size());
|
||||
tapp.args = {"-v", "1", "-1", "-v", "3", "-v", "-976"};
|
||||
tapp.run();
|
||||
CHECK(tapp.app.count("-v") == 4u);
|
||||
CHECK(cv.size() == 4u);
|
||||
opt->check(CLI::PositiveNumber.application_index(0));
|
||||
opt->check((!CLI::PositiveNumber).application_index(1));
|
||||
EXPECT_NO_THROW(TApp::run());
|
||||
EXPECT_EQ(4u, cv.size());
|
||||
CHECK_NOTHROW(tapp.run());
|
||||
CHECK(cv.size() == 4u);
|
||||
// v[3] would be negative
|
||||
opt->check(CLI::PositiveNumber.application_index(3));
|
||||
EXPECT_THROW(TApp::run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(tapp.run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
template <class T> class TApp_container_pair_boost : public TApp {
|
||||
public:
|
||||
using container_type = T;
|
||||
container_type cval{};
|
||||
TApp_container_pair_boost() : TApp() {}
|
||||
};
|
||||
|
||||
using isp = std::pair<int, std::string>;
|
||||
using containerTypes_pair_boost = ::testing::
|
||||
Types<stable_vector<isp>, small_vector<isp, 2>, flat_set<isp>, slist<isp>, vector<isp>, flat_map<int, std::string>>;
|
||||
|
||||
TYPED_TEST_SUITE(TApp_container_pair_boost, containerTypes_pair_boost, );
|
||||
TEMPLATE_TEST_CASE("Boost container pair",
|
||||
"[boost][optional]",
|
||||
stable_vector<isp>,
|
||||
(small_vector<isp, 2>),
|
||||
flat_set<isp>,
|
||||
slist<isp>,
|
||||
vector<isp>,
|
||||
(flat_map<int, std::string>)) {
|
||||
|
||||
TYPED_TEST(TApp_container_pair_boost, containerPair_boost) {
|
||||
TApp tapp;
|
||||
TestType cv;
|
||||
|
||||
auto &cv = TApp_container_pair_boost<TypeParam>::cval;
|
||||
(TApp::app).add_option("--dict", cv);
|
||||
tapp.app.add_option("--dict", cv);
|
||||
|
||||
TApp::args = {"--dict", "1", "str1", "--dict", "3", "str3"};
|
||||
tapp.args = {"--dict", "1", "str1", "--dict", "3", "str3"};
|
||||
|
||||
TApp::run();
|
||||
EXPECT_EQ(cv.size(), 2u);
|
||||
tapp.run();
|
||||
CHECK(2u == cv.size());
|
||||
|
||||
TApp::args = {"--dict", "1", "str1", "--dict", "3", "--dict", "-1", "str4"};
|
||||
TApp::run();
|
||||
EXPECT_EQ(cv.size(), 3u);
|
||||
tapp.args = {"--dict", "1", "str1", "--dict", "3", "--dict", "-1", "str4"};
|
||||
tapp.run();
|
||||
CHECK(3u == cv.size());
|
||||
}
|
||||
|
||||
template <class T> class TApp_container_tuple_boost : public TApp {
|
||||
public:
|
||||
using container_type = T;
|
||||
container_type cval{};
|
||||
TApp_container_tuple_boost() : TApp() {}
|
||||
};
|
||||
|
||||
using tup_obj = std::tuple<int, std::string, double>;
|
||||
using containerTypes_tuple_boost =
|
||||
::testing::Types<small_vector<tup_obj, 3>, stable_vector<tup_obj>, flat_set<tup_obj>, slist<tup_obj>>;
|
||||
|
||||
TYPED_TEST_SUITE(TApp_container_tuple_boost, containerTypes_tuple_boost, );
|
||||
TEMPLATE_TEST_CASE("Boost container tuple",
|
||||
"[boost][optional]",
|
||||
(small_vector<tup_obj, 3>),
|
||||
stable_vector<tup_obj>,
|
||||
flat_set<tup_obj>,
|
||||
slist<tup_obj>) {
|
||||
TApp tapp;
|
||||
TestType cv;
|
||||
|
||||
TYPED_TEST(TApp_container_tuple_boost, containerTuple_boost) {
|
||||
tapp.app.add_option("--dict", cv);
|
||||
|
||||
auto &cv = TApp_container_tuple_boost<TypeParam>::cval;
|
||||
(TApp::app).add_option("--dict", cv);
|
||||
tapp.args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7"};
|
||||
|
||||
TApp::args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7"};
|
||||
tapp.run();
|
||||
CHECK(2u == cv.size());
|
||||
|
||||
TApp::run();
|
||||
EXPECT_EQ(cv.size(), 2u);
|
||||
|
||||
TApp::args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7", "--dict", "-1", "str4", "-1.87"};
|
||||
TApp::run();
|
||||
EXPECT_EQ(cv.size(), 3u);
|
||||
tapp.args = {"--dict", "1", "str1", "4.3", "--dict", "3", "str3", "2.7", "--dict", "-1", "str4", "-1.87"};
|
||||
tapp.run();
|
||||
CHECK(3u == cv.size());
|
||||
}
|
||||
|
||||
using icontainer1 = vector<int>;
|
||||
using icontainer2 = flat_set<int>;
|
||||
using icontainer3 = slist<int>;
|
||||
using containerTypes_container_boost = ::testing::Types<std::vector<icontainer1>,
|
||||
slist<icontainer1>,
|
||||
flat_set<icontainer1>,
|
||||
small_vector<icontainer1, 2>,
|
||||
std::vector<icontainer2>,
|
||||
slist<icontainer2>,
|
||||
flat_set<icontainer2>,
|
||||
stable_vector<icontainer2>,
|
||||
static_vector<icontainer3, 10>,
|
||||
slist<icontainer3>,
|
||||
flat_set<icontainer3>,
|
||||
static_vector<icontainer3, 10>>;
|
||||
|
||||
template <class T> class TApp_container_container_boost : public TApp {
|
||||
public:
|
||||
using container_type = T;
|
||||
container_type cval{};
|
||||
TApp_container_container_boost() : TApp() {}
|
||||
};
|
||||
TEMPLATE_TEST_CASE("Boost container container",
|
||||
"[boost][optional]",
|
||||
std::vector<icontainer1>,
|
||||
slist<icontainer1>,
|
||||
flat_set<icontainer1>,
|
||||
(small_vector<icontainer1, 2>),
|
||||
std::vector<icontainer2>,
|
||||
slist<icontainer2>,
|
||||
flat_set<icontainer2>,
|
||||
stable_vector<icontainer2>,
|
||||
(static_vector<icontainer2, 10>),
|
||||
slist<icontainer3>,
|
||||
flat_set<icontainer3>,
|
||||
(static_vector<icontainer3, 10>)) {
|
||||
|
||||
TYPED_TEST_SUITE(TApp_container_container_boost, containerTypes_container_boost, );
|
||||
TApp tapp;
|
||||
TestType cv;
|
||||
|
||||
TYPED_TEST(TApp_container_container_boost, containerContainer_boost) {
|
||||
tapp.app.add_option("--dict", cv);
|
||||
|
||||
auto &cv = TApp_container_container_boost<TypeParam>::cval;
|
||||
(TApp::app).add_option("--dict", cv);
|
||||
tapp.args = {"--dict", "1", "2", "4", "--dict", "3", "1"};
|
||||
|
||||
TApp::args = {"--dict", "1", "2", "4", "--dict", "3", "1"};
|
||||
tapp.run();
|
||||
CHECK(2u == cv.size());
|
||||
|
||||
TApp::run();
|
||||
EXPECT_EQ(cv.size(), 2u);
|
||||
|
||||
TApp::args = {"--dict", "1", "2", "4", "--dict", "3", "1", "--dict", "3", "--dict",
|
||||
"3", "3", "3", "3", "3", "3", "3", "3", "3", "-3"};
|
||||
TApp::run();
|
||||
EXPECT_EQ(cv.size(), 4u);
|
||||
tapp.args = {"--dict", "1", "2", "4", "--dict", "3", "1", "--dict", "3", "--dict",
|
||||
"3", "3", "3", "3", "3", "3", "3", "3", "3", "-3"};
|
||||
tapp.run();
|
||||
CHECK(4u == cv.size());
|
||||
}
|
||||
|
||||
} // namespace container
|
||||
} // namespace boost
|
||||
|
@ -1,8 +1,3 @@
|
||||
if(NOT EXISTS "${CLI11_SOURCE_DIR}/extern/googletest/CMakeLists.txt")
|
||||
message(FATAL_ERROR "You have requested tests be built, but googletest is not downloaded. Please run:
|
||||
git submodule update --init")
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake")
|
||||
|
||||
if(CLI11_SANITIZERS)
|
||||
@ -29,8 +24,6 @@ else()
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
set(GOOGLE_TEST_INDIVIDUAL OFF)
|
||||
include(AddGoogletest)
|
||||
|
||||
# Add boost to test boost::optional (currently explicitly requested)"
|
||||
option(CLI11_BOOST "Turn on boost test (currently may fail with Boost 1.70)" OFF)
|
||||
@ -70,8 +63,32 @@ endif()
|
||||
|
||||
set(CLI11_MULTIONLY_TESTS TimerTest)
|
||||
|
||||
# Only affects current directory, so safe
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(catch_main main.cpp)
|
||||
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
# Currently a required download; could be make to look for existing Catch2, but
|
||||
# that would require changing the includes. FetchContent would be better, but
|
||||
# requires newer CMake.
|
||||
|
||||
set(url https://github.com/philsquared/Catch/releases/download/v2.13.4/catch.hpp)
|
||||
file(DOWNLOAD ${url} "${CMAKE_CURRENT_BINARY_DIR}/catch.hpp" STATUS status EXPECTED_HASH SHA256=6e0fa3dd160891a01c1f3b34e8bcd6e0140abe08eca022e390027f27dec2050b)
|
||||
list(GET status 0 error)
|
||||
if(error)
|
||||
message(FATAL_ERROR "Could not download ${url}")
|
||||
endif()
|
||||
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# Target must already exist
|
||||
macro(add_catch_test TESTNAME)
|
||||
target_link_libraries(${TESTNAME} PUBLIC catch_main)
|
||||
|
||||
add_test(${TESTNAME} ${TESTNAME})
|
||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
||||
if (CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET ${T} APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
foreach(T IN LISTS CLI11_TESTS)
|
||||
if(CLI11_CUDA_TESTS)
|
||||
@ -86,12 +103,12 @@ foreach(T IN LISTS CLI11_TESTS)
|
||||
target_link_libraries(${T} PRIVATE CLI11_warnings)
|
||||
endif()
|
||||
target_link_libraries(${T} PRIVATE CLI11)
|
||||
add_gtest(${T})
|
||||
add_catch_test(${T})
|
||||
|
||||
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
|
||||
add_executable(${T}_Single ${T}.cpp)
|
||||
target_link_libraries(${T}_Single PRIVATE CLI11_SINGLE)
|
||||
add_gtest(${T}_Single)
|
||||
add_catch_test(${T}_Single)
|
||||
set_property(TARGET ${T}_Single PROPERTY FOLDER "Tests Single File")
|
||||
endif()
|
||||
endforeach()
|
||||
@ -100,7 +117,7 @@ foreach(T IN LISTS CLI11_MULTIONLY_TESTS)
|
||||
add_executable(${T} ${T}.cpp ${CLI11_headers})
|
||||
add_sanitizers(${T})
|
||||
target_link_libraries(${T} PUBLIC CLI11)
|
||||
add_gtest(${T})
|
||||
add_catch_test(${T})
|
||||
endforeach()
|
||||
|
||||
# Add -Wno-deprecated-declarations to DeprecatedTest
|
||||
@ -123,7 +140,7 @@ target_link_libraries(link_test_1 PUBLIC CLI11)
|
||||
set_target_properties(link_test_1 PROPERTIES FOLDER "Tests")
|
||||
add_executable(link_test_2 link_test_2.cpp)
|
||||
target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1)
|
||||
add_gtest(link_test_2)
|
||||
add_catch_test(link_test_2)
|
||||
if(CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET link_test_1 APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
|
@ -5,11 +5,11 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#include "app_helper.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <complex>
|
||||
#include <cstdint>
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using cx = std::complex<double>;
|
||||
|
||||
@ -33,7 +33,7 @@ add_option(CLI::App &app, std::string name, cx &variable, std::string descriptio
|
||||
return opt;
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingComplexParser) {
|
||||
TEST_CASE_METHOD(TApp, "AddingComplexParser", "[complex]") {
|
||||
|
||||
cx comp{0, 0};
|
||||
add_option(app, "-c,--complex", comp);
|
||||
@ -41,27 +41,27 @@ TEST_F(TApp, AddingComplexParser) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.5, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2.5, comp.imag());
|
||||
CHECK(comp.real() == Approx(1.5));
|
||||
CHECK(comp.imag() == Approx(2.5));
|
||||
}
|
||||
|
||||
TEST_F(TApp, DefaultedComplex) {
|
||||
TEST_CASE_METHOD(TApp, "DefaultedComplex", "[complex]") {
|
||||
|
||||
cx comp{1, 2};
|
||||
add_option(app, "-c,--complex", comp, "", true);
|
||||
args = {"-c", "4", "3"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
|
||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
// an example of custom complex number converter that can be used to add new parsing options
|
||||
@ -117,7 +117,7 @@ template <> bool lexical_cast<std::complex<double>>(const std::string &input, st
|
||||
} // namespace detail
|
||||
} // namespace CLI
|
||||
|
||||
TEST_F(TApp, AddingComplexParserDetail) {
|
||||
TEST_CASE_METHOD(TApp, "AddingComplexParserDetail", "[complex]") {
|
||||
|
||||
bool skip_tests = false;
|
||||
try { // check if the library actually supports regex, it is possible to link against a non working regex in the
|
||||
@ -131,7 +131,7 @@ TEST_F(TApp, AddingComplexParserDetail) {
|
||||
if(!rsearch) {
|
||||
skip_tests = true;
|
||||
} else {
|
||||
EXPECT_EQ(m.size(), 9u);
|
||||
CHECK(9u == m.size());
|
||||
}
|
||||
|
||||
} catch(...) {
|
||||
@ -146,14 +146,14 @@ TEST_F(TApp, AddingComplexParserDetail) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.5, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2.5, comp.imag());
|
||||
CHECK(comp.real() == Approx(1.5));
|
||||
CHECK(comp.imag() == Approx(2.5));
|
||||
args = {"-c", "1.5-2.5j"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.5, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2.5, comp.imag());
|
||||
CHECK(comp.real() == Approx(1.5));
|
||||
CHECK(comp.imag() == Approx(-2.5));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -170,7 +170,7 @@ class complex_new {
|
||||
double val2_{0.0};
|
||||
};
|
||||
|
||||
TEST_F(TApp, newComplex) {
|
||||
TEST_CASE_METHOD(TApp, "newComplex", "[complex]") {
|
||||
complex_new cval;
|
||||
static_assert(CLI::detail::is_complex<complex_new>::value, "complex new does not register as a complex type");
|
||||
static_assert(CLI::detail::classify_object<complex_new>::value == CLI::detail::object_category::complex_number,
|
||||
@ -180,12 +180,12 @@ TEST_F(TApp, newComplex) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.5, cval.real());
|
||||
EXPECT_DOUBLE_EQ(2.5, cval.imag());
|
||||
CHECK(cval.real() == Approx(1.5));
|
||||
CHECK(cval.imag() == Approx(2.5));
|
||||
args = {"-c", "1.5-2.5j"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(1.5, cval.real());
|
||||
EXPECT_DOUBLE_EQ(-2.5, cval.imag());
|
||||
CHECK(cval.real() == Approx(1.5));
|
||||
CHECK(cval.imag() == Approx(-2.5));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,221 +7,224 @@
|
||||
#include "app_helper.hpp"
|
||||
#include <cstdlib>
|
||||
|
||||
TEST_F(TApp, AddingExistingShort) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingShort", "[creation]") {
|
||||
CLI::Option *opt = app.add_flag("-c,--count");
|
||||
EXPECT_EQ(opt->get_lnames(), std::vector<std::string>({"count"}));
|
||||
EXPECT_EQ(opt->get_snames(), std::vector<std::string>({"c"}));
|
||||
CHECK(std::vector<std::string>({"count"}) == opt->get_lnames());
|
||||
CHECK(std::vector<std::string>({"c"}) == opt->get_snames());
|
||||
|
||||
EXPECT_THROW(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingLong) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingLong", "[creation]") {
|
||||
app.add_flag("-q,--count");
|
||||
EXPECT_THROW(app.add_flag("--count,-c"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_flag("--count,-c"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingShortNoCase) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingShortNoCase", "[creation]") {
|
||||
app.add_flag("-C,--count")->ignore_case();
|
||||
EXPECT_THROW(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_flag("--cat,-c"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingLongNoCase) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingLongNoCase", "[creation]") {
|
||||
app.add_flag("-q,--count")->ignore_case();
|
||||
EXPECT_THROW(app.add_flag("--Count,-c"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_flag("--Count,-c"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingNoCaseReversed) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingNoCaseReversed", "[creation]") {
|
||||
app.add_flag("-c,--count")->ignore_case();
|
||||
EXPECT_THROW(app.add_flag("--cat,-C"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_flag("--cat,-C"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingWithCase) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingWithCase", "[creation]") {
|
||||
app.add_flag("-c,--count");
|
||||
EXPECT_NO_THROW(app.add_flag("--Cat,-C"));
|
||||
CHECK_NOTHROW(app.add_flag("--Cat,-C"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingWithCaseAfter) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter", "[creation]") {
|
||||
auto count = app.add_flag("-c,--count");
|
||||
app.add_flag("--Cat,-C");
|
||||
|
||||
EXPECT_THROW(count->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(count->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingWithCaseAfter2) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingWithCaseAfter2", "[creation]") {
|
||||
app.add_flag("-c,--count");
|
||||
auto cat = app.add_flag("--Cat,-C");
|
||||
|
||||
EXPECT_THROW(cat->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(cat->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingWithUnderscoreAfter) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingWithUnderscoreAfter", "[creation]") {
|
||||
auto count = app.add_flag("--underscore");
|
||||
app.add_flag("--under_score");
|
||||
|
||||
EXPECT_THROW(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingExistingWithUnderscoreAfter2) {
|
||||
TEST_CASE_METHOD(TApp, "AddingExistingWithUnderscoreAfter2", "[creation]") {
|
||||
auto count = app.add_flag("--under_score");
|
||||
app.add_flag("--underscore");
|
||||
|
||||
EXPECT_THROW(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(count->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingMultipleInfPositionals) {
|
||||
TEST_CASE_METHOD(TApp, "AddingMultipleInfPositionals", "[creation]") {
|
||||
std::vector<std::string> one, two;
|
||||
app.add_option("one", one);
|
||||
app.add_option("two", two);
|
||||
|
||||
EXPECT_THROW(run(), CLI::InvalidError);
|
||||
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddingMultipleInfPositionalsSubcom) {
|
||||
TEST_CASE_METHOD(TApp, "AddingMultipleInfPositionalsSubcom", "[creation]") {
|
||||
std::vector<std::string> one, two;
|
||||
CLI::App *below = app.add_subcommand("below");
|
||||
below->add_option("one", one);
|
||||
below->add_option("two", two);
|
||||
|
||||
EXPECT_THROW(run(), CLI::InvalidError);
|
||||
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatching) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatching", "[creation]") {
|
||||
app.add_subcommand("first");
|
||||
app.add_subcommand("second");
|
||||
app.add_subcommand("Second");
|
||||
EXPECT_THROW(app.add_subcommand("first"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_subcommand("first"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, RecoverSubcommands) {
|
||||
TEST_CASE_METHOD(TApp, "RecoverSubcommands", "[creation]") {
|
||||
CLI::App *app1 = app.add_subcommand("app1");
|
||||
CLI::App *app2 = app.add_subcommand("app2");
|
||||
CLI::App *app3 = app.add_subcommand("app3");
|
||||
CLI::App *app4 = app.add_subcommand("app4");
|
||||
|
||||
EXPECT_EQ(app.get_subcommands({}), std::vector<CLI::App *>({app1, app2, app3, app4}));
|
||||
CHECK(std::vector<CLI::App *>({app1, app2, app3, app4}) == app.get_subcommands({}));
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithCase) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCase", "[creation]") {
|
||||
app.add_subcommand("first")->ignore_case();
|
||||
EXPECT_THROW(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithCaseFirst) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseFirst", "[creation]") {
|
||||
app.ignore_case();
|
||||
app.add_subcommand("first");
|
||||
EXPECT_THROW(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_subcommand("fIrst"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscore) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscore", "[creation]") {
|
||||
app.add_subcommand("first_option")->ignore_underscore();
|
||||
EXPECT_THROW(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscoreFirst) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreFirst", "[creation]") {
|
||||
app.ignore_underscore();
|
||||
app.add_subcommand("first_option");
|
||||
EXPECT_THROW(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(app.add_subcommand("firstoption"), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace", "[creation]") {
|
||||
app.add_subcommand("first");
|
||||
auto first = app.add_subcommand("fIrst");
|
||||
|
||||
EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(first->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithCaseInplace2) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithCaseInplace2", "[creation]") {
|
||||
auto first = app.add_subcommand("first");
|
||||
app.add_subcommand("fIrst");
|
||||
|
||||
EXPECT_THROW(first->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(first->ignore_case(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscoreInplace) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreInplace", "[creation]") {
|
||||
app.add_subcommand("first_option");
|
||||
auto first = app.add_subcommand("firstoption");
|
||||
|
||||
EXPECT_THROW(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomMatchingWithUnderscoreInplace2) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomMatchingWithUnderscoreInplace2", "[creation]") {
|
||||
auto first = app.add_subcommand("firstoption");
|
||||
app.add_subcommand("first_option");
|
||||
|
||||
EXPECT_THROW(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(first->ignore_underscore(), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomNoMatchingInplace2) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomNoMatchingInplace2", "[creation]") {
|
||||
auto first = app.add_subcommand("first");
|
||||
auto second = app.add_subcommand("second");
|
||||
|
||||
EXPECT_NO_THROW(first->ignore_case());
|
||||
EXPECT_NO_THROW(second->ignore_case());
|
||||
CHECK_NOTHROW(first->ignore_case());
|
||||
CHECK_NOTHROW(second->ignore_case());
|
||||
}
|
||||
|
||||
TEST_F(TApp, MultipleSubcomNoMatchingInplaceUnderscore2) {
|
||||
TEST_CASE_METHOD(TApp, "MultipleSubcomNoMatchingInplaceUnderscore2", "[creation]") {
|
||||
auto first = app.add_subcommand("first_option");
|
||||
auto second = app.add_subcommand("second_option");
|
||||
|
||||
EXPECT_NO_THROW(first->ignore_underscore());
|
||||
EXPECT_NO_THROW(second->ignore_underscore());
|
||||
CHECK_NOTHROW(first->ignore_underscore());
|
||||
CHECK_NOTHROW(second->ignore_underscore());
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagPositional1) { EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction); }
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional1", "[creation]") {
|
||||
// This wants to be one line with clang-format
|
||||
CHECK_THROWS_AS(app.add_flag("cat"), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagPositional2) {
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional2", "[creation]") {
|
||||
int x{0};
|
||||
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||
CHECK_THROWS_AS(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagPositional3) {
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionFlagPositional3", "[creation]") {
|
||||
bool x{false};
|
||||
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||
CHECK_THROWS_AS(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionNeedsCannotFind) {
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionNeedsCannotFind", "[creation]") {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->needs("--nothing"), CLI::IncorrectConstruction);
|
||||
CHECK_THROWS_AS(cat->needs("--nothing"), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionExcludesCannotFind) {
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionExcludesCannotFind", "[creation]") {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
||||
CHECK_THROWS_AS(cat->excludes("--nothing"), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionDuplicateNeeds) {
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeeds", "[creation]") {
|
||||
auto cat = app.add_flag("--cat");
|
||||
auto other = app.add_flag("--other");
|
||||
ASSERT_NO_THROW(cat->needs(other));
|
||||
REQUIRE_NOTHROW(cat->needs(other));
|
||||
// duplicated needs is redundant but not an error
|
||||
EXPECT_NO_THROW(cat->needs(other));
|
||||
CHECK_NOTHROW(cat->needs(other));
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionDuplicateNeedsTxt) {
|
||||
TEST_CASE_METHOD(TApp, "IncorrectConstructionDuplicateNeedsTxt", "[creation]") {
|
||||
auto cat = app.add_flag("--cat");
|
||||
app.add_flag("--other");
|
||||
ASSERT_NO_THROW(cat->needs("--other"));
|
||||
REQUIRE_NOTHROW(cat->needs("--other"));
|
||||
// duplicate needs is redundant but not an error
|
||||
EXPECT_NO_THROW(cat->needs("--other"));
|
||||
CHECK_NOTHROW(cat->needs("--other"));
|
||||
}
|
||||
|
||||
// Now allowed
|
||||
TEST_F(TApp, CorrectConstructionDuplicateExcludes) {
|
||||
TEST_CASE_METHOD(TApp, "CorrectConstructionDuplicateExcludes", "[creation]") {
|
||||
auto cat = app.add_flag("--cat");
|
||||
auto other = app.add_flag("--other");
|
||||
ASSERT_NO_THROW(cat->excludes(other));
|
||||
ASSERT_NO_THROW(other->excludes(cat));
|
||||
REQUIRE_NOTHROW(cat->excludes(other));
|
||||
REQUIRE_NOTHROW(other->excludes(cat));
|
||||
}
|
||||
|
||||
// Now allowed
|
||||
TEST_F(TApp, CorrectConstructionDuplicateExcludesTxt) {
|
||||
TEST_CASE_METHOD(TApp, "CorrectConstructionDuplicateExcludesTxt", "[creation]") {
|
||||
auto cat = app.add_flag("--cat");
|
||||
auto other = app.add_flag("--other");
|
||||
ASSERT_NO_THROW(cat->excludes("--other"));
|
||||
ASSERT_NO_THROW(other->excludes("--cat"));
|
||||
REQUIRE_NOTHROW(cat->excludes("--other"));
|
||||
REQUIRE_NOTHROW(other->excludes("--cat"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, CheckName) {
|
||||
TEST_CASE_METHOD(TApp, "CheckName", "[creation]") {
|
||||
auto long1 = app.add_flag("--long1");
|
||||
auto long2 = app.add_flag("--Long2");
|
||||
auto short1 = app.add_flag("-a");
|
||||
@ -230,26 +233,26 @@ TEST_F(TApp, CheckName) {
|
||||
auto pos1 = app.add_option("pos1", x);
|
||||
auto pos2 = app.add_option("pOs2", y);
|
||||
|
||||
EXPECT_TRUE(long1->check_name("--long1"));
|
||||
EXPECT_FALSE(long1->check_name("--lonG1"));
|
||||
CHECK(long1->check_name("--long1"));
|
||||
CHECK(!long1->check_name("--lonG1"));
|
||||
|
||||
EXPECT_TRUE(long2->check_name("--Long2"));
|
||||
EXPECT_FALSE(long2->check_name("--long2"));
|
||||
CHECK(long2->check_name("--Long2"));
|
||||
CHECK(!long2->check_name("--long2"));
|
||||
|
||||
EXPECT_TRUE(short1->check_name("-a"));
|
||||
EXPECT_FALSE(short1->check_name("-A"));
|
||||
CHECK(short1->check_name("-a"));
|
||||
CHECK(!short1->check_name("-A"));
|
||||
|
||||
EXPECT_TRUE(short2->check_name("-B"));
|
||||
EXPECT_FALSE(short2->check_name("-b"));
|
||||
CHECK(short2->check_name("-B"));
|
||||
CHECK(!short2->check_name("-b"));
|
||||
|
||||
EXPECT_TRUE(pos1->check_name("pos1"));
|
||||
EXPECT_FALSE(pos1->check_name("poS1"));
|
||||
CHECK(pos1->check_name("pos1"));
|
||||
CHECK(!pos1->check_name("poS1"));
|
||||
|
||||
EXPECT_TRUE(pos2->check_name("pOs2"));
|
||||
EXPECT_FALSE(pos2->check_name("pos2"));
|
||||
CHECK(pos2->check_name("pOs2"));
|
||||
CHECK(!pos2->check_name("pos2"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, CheckNameNoCase) {
|
||||
TEST_CASE_METHOD(TApp, "CheckNameNoCase", "[creation]") {
|
||||
auto long1 = app.add_flag("--long1")->ignore_case();
|
||||
auto long2 = app.add_flag("--Long2")->ignore_case();
|
||||
auto short1 = app.add_flag("-a")->ignore_case();
|
||||
@ -258,26 +261,26 @@ TEST_F(TApp, CheckNameNoCase) {
|
||||
auto pos1 = app.add_option("pos1", x)->ignore_case();
|
||||
auto pos2 = app.add_option("pOs2", y)->ignore_case();
|
||||
|
||||
EXPECT_TRUE(long1->check_name("--long1"));
|
||||
EXPECT_TRUE(long1->check_name("--lonG1"));
|
||||
CHECK(long1->check_name("--long1"));
|
||||
CHECK(long1->check_name("--lonG1"));
|
||||
|
||||
EXPECT_TRUE(long2->check_name("--Long2"));
|
||||
EXPECT_TRUE(long2->check_name("--long2"));
|
||||
CHECK(long2->check_name("--Long2"));
|
||||
CHECK(long2->check_name("--long2"));
|
||||
|
||||
EXPECT_TRUE(short1->check_name("-a"));
|
||||
EXPECT_TRUE(short1->check_name("-A"));
|
||||
CHECK(short1->check_name("-a"));
|
||||
CHECK(short1->check_name("-A"));
|
||||
|
||||
EXPECT_TRUE(short2->check_name("-B"));
|
||||
EXPECT_TRUE(short2->check_name("-b"));
|
||||
CHECK(short2->check_name("-B"));
|
||||
CHECK(short2->check_name("-b"));
|
||||
|
||||
EXPECT_TRUE(pos1->check_name("pos1"));
|
||||
EXPECT_TRUE(pos1->check_name("poS1"));
|
||||
CHECK(pos1->check_name("pos1"));
|
||||
CHECK(pos1->check_name("poS1"));
|
||||
|
||||
EXPECT_TRUE(pos2->check_name("pOs2"));
|
||||
EXPECT_TRUE(pos2->check_name("pos2"));
|
||||
CHECK(pos2->check_name("pOs2"));
|
||||
CHECK(pos2->check_name("pos2"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, CheckNameNoUnderscore) {
|
||||
TEST_CASE_METHOD(TApp, "CheckNameNoUnderscore", "[creation]") {
|
||||
auto long1 = app.add_flag("--longoption1")->ignore_underscore();
|
||||
auto long2 = app.add_flag("--long_option2")->ignore_underscore();
|
||||
|
||||
@ -285,30 +288,30 @@ TEST_F(TApp, CheckNameNoUnderscore) {
|
||||
auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore();
|
||||
auto pos2 = app.add_option("posoption2", y)->ignore_underscore();
|
||||
|
||||
EXPECT_TRUE(long1->check_name("--long_option1"));
|
||||
EXPECT_TRUE(long1->check_name("--longoption_1"));
|
||||
EXPECT_TRUE(long1->check_name("--longoption1"));
|
||||
EXPECT_TRUE(long1->check_name("--long__opt_ion__1"));
|
||||
EXPECT_TRUE(long1->check_name("--__l_o_n_g_o_p_t_i_o_n_1"));
|
||||
CHECK(long1->check_name("--long_option1"));
|
||||
CHECK(long1->check_name("--longoption_1"));
|
||||
CHECK(long1->check_name("--longoption1"));
|
||||
CHECK(long1->check_name("--long__opt_ion__1"));
|
||||
CHECK(long1->check_name("--__l_o_n_g_o_p_t_i_o_n_1"));
|
||||
|
||||
EXPECT_TRUE(long2->check_name("--long_option2"));
|
||||
EXPECT_TRUE(long2->check_name("--longoption2"));
|
||||
EXPECT_TRUE(long2->check_name("--longoption_2"));
|
||||
EXPECT_TRUE(long2->check_name("--long__opt_ion__2"));
|
||||
EXPECT_TRUE(long2->check_name("--__l_o_n_go_p_t_i_o_n_2__"));
|
||||
CHECK(long2->check_name("--long_option2"));
|
||||
CHECK(long2->check_name("--longoption2"));
|
||||
CHECK(long2->check_name("--longoption_2"));
|
||||
CHECK(long2->check_name("--long__opt_ion__2"));
|
||||
CHECK(long2->check_name("--__l_o_n_go_p_t_i_o_n_2__"));
|
||||
|
||||
EXPECT_TRUE(pos1->check_name("pos_option1"));
|
||||
EXPECT_TRUE(pos1->check_name("pos_option_1"));
|
||||
EXPECT_TRUE(pos1->check_name("pos_o_p_t_i_on_1"));
|
||||
EXPECT_TRUE(pos1->check_name("posoption1"));
|
||||
CHECK(pos1->check_name("pos_option1"));
|
||||
CHECK(pos1->check_name("pos_option_1"));
|
||||
CHECK(pos1->check_name("pos_o_p_t_i_on_1"));
|
||||
CHECK(pos1->check_name("posoption1"));
|
||||
|
||||
EXPECT_TRUE(pos2->check_name("pos_option2"));
|
||||
EXPECT_TRUE(pos2->check_name("pos_option_2"));
|
||||
EXPECT_TRUE(pos2->check_name("pos_o_p_t_i_on_2"));
|
||||
EXPECT_TRUE(pos2->check_name("posoption2"));
|
||||
CHECK(pos2->check_name("pos_option2"));
|
||||
CHECK(pos2->check_name("pos_option_2"));
|
||||
CHECK(pos2->check_name("pos_o_p_t_i_on_2"));
|
||||
CHECK(pos2->check_name("posoption2"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
|
||||
TEST_CASE_METHOD(TApp, "CheckNameNoCaseNoUnderscore", "[creation]") {
|
||||
auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case();
|
||||
auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore();
|
||||
|
||||
@ -316,85 +319,85 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
|
||||
auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case();
|
||||
auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore();
|
||||
|
||||
EXPECT_TRUE(long1->check_name("--Long_Option1"));
|
||||
EXPECT_TRUE(long1->check_name("--lONgoption_1"));
|
||||
EXPECT_TRUE(long1->check_name("--LongOption1"));
|
||||
EXPECT_TRUE(long1->check_name("--long__Opt_ion__1"));
|
||||
EXPECT_TRUE(long1->check_name("--__l_o_N_g_o_P_t_i_O_n_1"));
|
||||
CHECK(long1->check_name("--Long_Option1"));
|
||||
CHECK(long1->check_name("--lONgoption_1"));
|
||||
CHECK(long1->check_name("--LongOption1"));
|
||||
CHECK(long1->check_name("--long__Opt_ion__1"));
|
||||
CHECK(long1->check_name("--__l_o_N_g_o_P_t_i_O_n_1"));
|
||||
|
||||
EXPECT_TRUE(long2->check_name("--long_Option2"));
|
||||
EXPECT_TRUE(long2->check_name("--LongOption2"));
|
||||
EXPECT_TRUE(long2->check_name("--longOPTION_2"));
|
||||
EXPECT_TRUE(long2->check_name("--long__OPT_ion__2"));
|
||||
EXPECT_TRUE(long2->check_name("--__l_o_n_GO_p_t_i_o_n_2__"));
|
||||
CHECK(long2->check_name("--long_Option2"));
|
||||
CHECK(long2->check_name("--LongOption2"));
|
||||
CHECK(long2->check_name("--longOPTION_2"));
|
||||
CHECK(long2->check_name("--long__OPT_ion__2"));
|
||||
CHECK(long2->check_name("--__l_o_n_GO_p_t_i_o_n_2__"));
|
||||
|
||||
EXPECT_TRUE(pos1->check_name("POS_Option1"));
|
||||
EXPECT_TRUE(pos1->check_name("pos_option_1"));
|
||||
EXPECT_TRUE(pos1->check_name("pos_o_p_t_i_on_1"));
|
||||
EXPECT_TRUE(pos1->check_name("posoption1"));
|
||||
CHECK(pos1->check_name("POS_Option1"));
|
||||
CHECK(pos1->check_name("pos_option_1"));
|
||||
CHECK(pos1->check_name("pos_o_p_t_i_on_1"));
|
||||
CHECK(pos1->check_name("posoption1"));
|
||||
|
||||
EXPECT_TRUE(pos2->check_name("pos_option2"));
|
||||
EXPECT_TRUE(pos2->check_name("pos_OPTION_2"));
|
||||
EXPECT_TRUE(pos2->check_name("poS_o_p_T_I_on_2"));
|
||||
EXPECT_TRUE(pos2->check_name("PosOption2"));
|
||||
CHECK(pos2->check_name("pos_option2"));
|
||||
CHECK(pos2->check_name("pos_OPTION_2"));
|
||||
CHECK(pos2->check_name("poS_o_p_T_I_on_2"));
|
||||
CHECK(pos2->check_name("PosOption2"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, PreSpaces) {
|
||||
TEST_CASE_METHOD(TApp, "PreSpaces", "[creation]") {
|
||||
int x{0};
|
||||
auto myapp = app.add_option(" -a, --long, other", x);
|
||||
|
||||
EXPECT_TRUE(myapp->check_lname("long"));
|
||||
EXPECT_TRUE(myapp->check_sname("a"));
|
||||
EXPECT_TRUE(myapp->check_name("other"));
|
||||
CHECK(myapp->check_lname("long"));
|
||||
CHECK(myapp->check_sname("a"));
|
||||
CHECK(myapp->check_name("other"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, AllSpaces) {
|
||||
TEST_CASE_METHOD(TApp, "AllSpaces", "[creation]") {
|
||||
int x{0};
|
||||
auto myapp = app.add_option(" -a , --long , other ", x);
|
||||
|
||||
EXPECT_TRUE(myapp->check_lname("long"));
|
||||
EXPECT_TRUE(myapp->check_sname("a"));
|
||||
EXPECT_TRUE(myapp->check_name("other"));
|
||||
CHECK(myapp->check_lname("long"));
|
||||
CHECK(myapp->check_sname("a"));
|
||||
CHECK(myapp->check_name("other"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, OptionFromDefaults) {
|
||||
TEST_CASE_METHOD(TApp, "OptionFromDefaults", "[creation]") {
|
||||
app.option_defaults()->required();
|
||||
|
||||
// Options should remember defaults
|
||||
int x{0};
|
||||
auto opt = app.add_option("--simple", x);
|
||||
EXPECT_TRUE(opt->get_required());
|
||||
CHECK(opt->get_required());
|
||||
|
||||
// Flags cannot be required
|
||||
auto flag = app.add_flag("--other");
|
||||
EXPECT_FALSE(flag->get_required());
|
||||
CHECK(!flag->get_required());
|
||||
|
||||
app.option_defaults()->required(false);
|
||||
auto opt2 = app.add_option("--simple2", x);
|
||||
EXPECT_FALSE(opt2->get_required());
|
||||
CHECK(!opt2->get_required());
|
||||
|
||||
app.option_defaults()->required()->ignore_case();
|
||||
|
||||
auto opt3 = app.add_option("--simple3", x);
|
||||
EXPECT_TRUE(opt3->get_required());
|
||||
EXPECT_TRUE(opt3->get_ignore_case());
|
||||
CHECK(opt3->get_required());
|
||||
CHECK(opt3->get_ignore_case());
|
||||
|
||||
app.option_defaults()->required()->ignore_underscore();
|
||||
|
||||
auto opt4 = app.add_option("--simple4", x);
|
||||
EXPECT_TRUE(opt4->get_required());
|
||||
EXPECT_TRUE(opt4->get_ignore_underscore());
|
||||
CHECK(opt4->get_required());
|
||||
CHECK(opt4->get_ignore_underscore());
|
||||
}
|
||||
|
||||
TEST_F(TApp, OptionFromDefaultsSubcommands) {
|
||||
TEST_CASE_METHOD(TApp, "OptionFromDefaultsSubcommands", "[creation]") {
|
||||
// Initial defaults
|
||||
EXPECT_FALSE(app.option_defaults()->get_required());
|
||||
EXPECT_EQ(app.option_defaults()->get_multi_option_policy(), CLI::MultiOptionPolicy::Throw);
|
||||
EXPECT_FALSE(app.option_defaults()->get_ignore_case());
|
||||
EXPECT_FALSE(app.option_defaults()->get_ignore_underscore());
|
||||
EXPECT_FALSE(app.option_defaults()->get_disable_flag_override());
|
||||
EXPECT_TRUE(app.option_defaults()->get_configurable());
|
||||
EXPECT_EQ(app.option_defaults()->get_group(), "Options");
|
||||
CHECK(!app.option_defaults()->get_required());
|
||||
CHECK(CLI::MultiOptionPolicy::Throw == app.option_defaults()->get_multi_option_policy());
|
||||
CHECK(!app.option_defaults()->get_ignore_case());
|
||||
CHECK(!app.option_defaults()->get_ignore_underscore());
|
||||
CHECK(!app.option_defaults()->get_disable_flag_override());
|
||||
CHECK(app.option_defaults()->get_configurable());
|
||||
CHECK("Options" == app.option_defaults()->get_group());
|
||||
|
||||
app.option_defaults()
|
||||
->required()
|
||||
@ -407,55 +410,55 @@ TEST_F(TApp, OptionFromDefaultsSubcommands) {
|
||||
|
||||
auto app2 = app.add_subcommand("app2");
|
||||
|
||||
EXPECT_TRUE(app2->option_defaults()->get_required());
|
||||
EXPECT_EQ(app2->option_defaults()->get_multi_option_policy(), CLI::MultiOptionPolicy::TakeLast);
|
||||
EXPECT_TRUE(app2->option_defaults()->get_ignore_case());
|
||||
EXPECT_TRUE(app2->option_defaults()->get_ignore_underscore());
|
||||
EXPECT_FALSE(app2->option_defaults()->get_configurable());
|
||||
EXPECT_TRUE(app.option_defaults()->get_disable_flag_override());
|
||||
EXPECT_EQ(app2->option_defaults()->get_group(), "Something");
|
||||
CHECK(app2->option_defaults()->get_required());
|
||||
CHECK(CLI::MultiOptionPolicy::TakeLast == app2->option_defaults()->get_multi_option_policy());
|
||||
CHECK(app2->option_defaults()->get_ignore_case());
|
||||
CHECK(app2->option_defaults()->get_ignore_underscore());
|
||||
CHECK(!app2->option_defaults()->get_configurable());
|
||||
CHECK(app.option_defaults()->get_disable_flag_override());
|
||||
CHECK("Something" == app2->option_defaults()->get_group());
|
||||
}
|
||||
|
||||
TEST_F(TApp, GetNameCheck) {
|
||||
TEST_CASE_METHOD(TApp, "GetNameCheck", "[creation]") {
|
||||
int x{0};
|
||||
auto a = app.add_flag("--that");
|
||||
auto b = app.add_flag("-x");
|
||||
auto c = app.add_option("pos", x);
|
||||
auto d = app.add_option("one,-o,--other", x);
|
||||
|
||||
EXPECT_EQ(a->get_name(false, true), "--that");
|
||||
EXPECT_EQ(b->get_name(false, true), "-x");
|
||||
EXPECT_EQ(c->get_name(false, true), "pos");
|
||||
CHECK("--that" == a->get_name(false, true));
|
||||
CHECK("-x" == b->get_name(false, true));
|
||||
CHECK("pos" == c->get_name(false, true));
|
||||
|
||||
EXPECT_EQ(d->get_name(), "--other");
|
||||
EXPECT_EQ(d->get_name(false, false), "--other");
|
||||
EXPECT_EQ(d->get_name(false, true), "-o,--other");
|
||||
EXPECT_EQ(d->get_name(true, true), "one,-o,--other");
|
||||
EXPECT_EQ(d->get_name(true, false), "one");
|
||||
CHECK("--other" == d->get_name());
|
||||
CHECK("--other" == d->get_name(false, false));
|
||||
CHECK("-o,--other" == d->get_name(false, true));
|
||||
CHECK("one,-o,--other" == d->get_name(true, true));
|
||||
CHECK("one" == d->get_name(true, false));
|
||||
}
|
||||
|
||||
TEST_F(TApp, SubcommandDefaults) {
|
||||
TEST_CASE_METHOD(TApp, "SubcommandDefaults", "[creation]") {
|
||||
// allow_extras, prefix_command, ignore_case, fallthrough, group, min/max subcommand, validate_positionals
|
||||
|
||||
// Initial defaults
|
||||
EXPECT_FALSE(app.get_allow_extras());
|
||||
EXPECT_FALSE(app.get_prefix_command());
|
||||
EXPECT_FALSE(app.get_immediate_callback());
|
||||
EXPECT_FALSE(app.get_ignore_case());
|
||||
EXPECT_FALSE(app.get_ignore_underscore());
|
||||
CHECK(!app.get_allow_extras());
|
||||
CHECK(!app.get_prefix_command());
|
||||
CHECK(!app.get_immediate_callback());
|
||||
CHECK(!app.get_ignore_case());
|
||||
CHECK(!app.get_ignore_underscore());
|
||||
#ifdef _WIN32
|
||||
EXPECT_TRUE(app.get_allow_windows_style_options());
|
||||
CHECK(app.get_allow_windows_style_options());
|
||||
#else
|
||||
EXPECT_FALSE(app.get_allow_windows_style_options());
|
||||
CHECK(!app.get_allow_windows_style_options());
|
||||
#endif
|
||||
EXPECT_FALSE(app.get_fallthrough());
|
||||
EXPECT_FALSE(app.get_configurable());
|
||||
EXPECT_FALSE(app.get_validate_positionals());
|
||||
CHECK(!app.get_fallthrough());
|
||||
CHECK(!app.get_configurable());
|
||||
CHECK(!app.get_validate_positionals());
|
||||
|
||||
EXPECT_EQ(app.get_footer(), "");
|
||||
EXPECT_EQ(app.get_group(), "Subcommands");
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
||||
CHECK("" == app.get_footer());
|
||||
CHECK("Subcommands" == app.get_group());
|
||||
CHECK(0u == app.get_require_subcommand_min());
|
||||
CHECK(0u == app.get_require_subcommand_max());
|
||||
|
||||
app.allow_extras();
|
||||
app.prefix_command();
|
||||
@ -478,57 +481,57 @@ TEST_F(TApp, SubcommandDefaults) {
|
||||
auto app2 = app.add_subcommand("app2");
|
||||
|
||||
// Initial defaults
|
||||
EXPECT_TRUE(app2->get_allow_extras());
|
||||
EXPECT_TRUE(app2->get_prefix_command());
|
||||
EXPECT_TRUE(app2->get_immediate_callback());
|
||||
EXPECT_TRUE(app2->get_ignore_case());
|
||||
EXPECT_TRUE(app2->get_ignore_underscore());
|
||||
CHECK(app2->get_allow_extras());
|
||||
CHECK(app2->get_prefix_command());
|
||||
CHECK(app2->get_immediate_callback());
|
||||
CHECK(app2->get_ignore_case());
|
||||
CHECK(app2->get_ignore_underscore());
|
||||
#ifdef _WIN32
|
||||
EXPECT_FALSE(app2->get_allow_windows_style_options());
|
||||
CHECK(!app2->get_allow_windows_style_options());
|
||||
#else
|
||||
EXPECT_TRUE(app2->get_allow_windows_style_options());
|
||||
CHECK(app2->get_allow_windows_style_options());
|
||||
#endif
|
||||
EXPECT_TRUE(app2->get_fallthrough());
|
||||
EXPECT_TRUE(app2->get_validate_positionals());
|
||||
EXPECT_TRUE(app2->get_configurable());
|
||||
EXPECT_EQ(app2->get_footer(), "footy");
|
||||
EXPECT_EQ(app2->get_group(), "Stuff");
|
||||
EXPECT_EQ(app2->get_require_subcommand_min(), 0u);
|
||||
EXPECT_EQ(app2->get_require_subcommand_max(), 3u);
|
||||
CHECK(app2->get_fallthrough());
|
||||
CHECK(app2->get_validate_positionals());
|
||||
CHECK(app2->get_configurable());
|
||||
CHECK("footy" == app2->get_footer());
|
||||
CHECK("Stuff" == app2->get_group());
|
||||
CHECK(0u == app2->get_require_subcommand_min());
|
||||
CHECK(3u == app2->get_require_subcommand_max());
|
||||
}
|
||||
|
||||
TEST_F(TApp, SubcommandMinMax) {
|
||||
TEST_CASE_METHOD(TApp, "SubcommandMinMax", "[creation]") {
|
||||
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
||||
CHECK(0u == app.get_require_subcommand_min());
|
||||
CHECK(0u == app.get_require_subcommand_max());
|
||||
|
||||
app.require_subcommand();
|
||||
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 1u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
||||
CHECK(1u == app.get_require_subcommand_min());
|
||||
CHECK(0u == app.get_require_subcommand_max());
|
||||
|
||||
app.require_subcommand(2);
|
||||
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 2u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 2u);
|
||||
CHECK(2u == app.get_require_subcommand_min());
|
||||
CHECK(2u == app.get_require_subcommand_max());
|
||||
|
||||
app.require_subcommand(0);
|
||||
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 0u);
|
||||
CHECK(0u == app.get_require_subcommand_min());
|
||||
CHECK(0u == app.get_require_subcommand_max());
|
||||
|
||||
app.require_subcommand(-2);
|
||||
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 0u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 2u);
|
||||
CHECK(0u == app.get_require_subcommand_min());
|
||||
CHECK(2u == app.get_require_subcommand_max());
|
||||
|
||||
app.require_subcommand(3, 7);
|
||||
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), 3u);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), 7u);
|
||||
CHECK(3u == app.get_require_subcommand_min());
|
||||
CHECK(7u == app.get_require_subcommand_max());
|
||||
}
|
||||
|
||||
TEST_F(TApp, GetOptionList) {
|
||||
TEST_CASE_METHOD(TApp, "GetOptionList", "[creation]") {
|
||||
int two{0};
|
||||
auto flag = app.add_flag("--one");
|
||||
auto opt = app.add_option("--two", two);
|
||||
@ -536,36 +539,36 @@ TEST_F(TApp, GetOptionList) {
|
||||
const CLI::App &const_app = app; // const alias to force use of const-methods
|
||||
std::vector<const CLI::Option *> opt_list = const_app.get_options();
|
||||
|
||||
ASSERT_EQ(opt_list.size(), static_cast<std::size_t>(3));
|
||||
EXPECT_EQ(opt_list.at(1), flag);
|
||||
EXPECT_EQ(opt_list.at(2), opt);
|
||||
REQUIRE(static_cast<std::size_t>(3) == opt_list.size());
|
||||
CHECK(flag == opt_list.at(1));
|
||||
CHECK(opt == opt_list.at(2));
|
||||
|
||||
std::vector<CLI::Option *> nonconst_opt_list = app.get_options();
|
||||
for(std::size_t i = 0; i < opt_list.size(); ++i) {
|
||||
EXPECT_EQ(nonconst_opt_list.at(i), opt_list.at(i));
|
||||
CHECK(opt_list.at(i) == nonconst_opt_list.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ValidatorTests, TestValidatorCreation) {
|
||||
TEST_CASE("ValidatorTests: TestValidatorCreation", "[creation]") {
|
||||
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
||||
return (val.size() >= 5) ? std::string{} : val;
|
||||
};
|
||||
CLI::Validator V(op1, "", "size");
|
||||
|
||||
EXPECT_EQ(V.get_name(), "size");
|
||||
CHECK("size" == V.get_name());
|
||||
V.name("harry");
|
||||
EXPECT_EQ(V.get_name(), "harry");
|
||||
EXPECT_TRUE(V.get_active());
|
||||
CHECK("harry" == V.get_name());
|
||||
CHECK(V.get_active());
|
||||
|
||||
EXPECT_EQ(V("test"), "test");
|
||||
EXPECT_EQ(V("test5"), std::string{});
|
||||
CHECK("test" == V("test"));
|
||||
CHECK(std::string{} == V("test5"));
|
||||
|
||||
EXPECT_EQ(V.get_description(), std::string{});
|
||||
CHECK(std::string{} == V.get_description());
|
||||
V.description("this is a description");
|
||||
EXPECT_EQ(V.get_description(), "this is a description");
|
||||
CHECK("this is a description" == V.get_description());
|
||||
}
|
||||
|
||||
TEST(ValidatorTests, TestValidatorOps) {
|
||||
TEST_CASE("ValidatorTests: TestValidatorOps", "[creation]") {
|
||||
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
||||
return (val.size() >= 5) ? std::string{} : val;
|
||||
};
|
||||
@ -590,72 +593,72 @@ TEST(ValidatorTests, TestValidatorOps) {
|
||||
std::string eight(8, 'a');
|
||||
std::string nine(9, 'a');
|
||||
std::string ten(10, 'a');
|
||||
EXPECT_TRUE(V1(five).empty());
|
||||
EXPECT_FALSE(V1(four).empty());
|
||||
CHECK(V1(five).empty());
|
||||
CHECK(!V1(four).empty());
|
||||
|
||||
EXPECT_TRUE(V2(nine).empty());
|
||||
EXPECT_FALSE(V2(eight).empty());
|
||||
CHECK(V2(nine).empty());
|
||||
CHECK(!V2(eight).empty());
|
||||
|
||||
EXPECT_TRUE(V3(two).empty());
|
||||
EXPECT_FALSE(V3(four).empty());
|
||||
CHECK(V3(two).empty());
|
||||
CHECK(!V3(four).empty());
|
||||
|
||||
EXPECT_TRUE(V4(eight).empty());
|
||||
EXPECT_FALSE(V4(ten).empty());
|
||||
CHECK(V4(eight).empty());
|
||||
CHECK(!V4(ten).empty());
|
||||
|
||||
auto V1a2 = V1 & V2;
|
||||
EXPECT_EQ(V1a2.get_description(), "(SIZE >= 5) AND (SIZE >= 9)");
|
||||
EXPECT_FALSE(V1a2(five).empty());
|
||||
EXPECT_TRUE(V1a2(nine).empty());
|
||||
CHECK("(SIZE >= 5) AND (SIZE >= 9)" == V1a2.get_description());
|
||||
CHECK(!V1a2(five).empty());
|
||||
CHECK(V1a2(nine).empty());
|
||||
|
||||
auto V1a4 = V1 & V4;
|
||||
EXPECT_EQ(V1a4.get_description(), "(SIZE >= 5) AND (SIZE <= 9)");
|
||||
EXPECT_TRUE(V1a4(five).empty());
|
||||
EXPECT_TRUE(V1a4(eight).empty());
|
||||
EXPECT_FALSE(V1a4(ten).empty());
|
||||
EXPECT_FALSE(V1a4(four).empty());
|
||||
CHECK("(SIZE >= 5) AND (SIZE <= 9)" == V1a4.get_description());
|
||||
CHECK(V1a4(five).empty());
|
||||
CHECK(V1a4(eight).empty());
|
||||
CHECK(!V1a4(ten).empty());
|
||||
CHECK(!V1a4(four).empty());
|
||||
|
||||
auto V1o3 = V1 | V3;
|
||||
EXPECT_EQ(V1o3.get_description(), "(SIZE >= 5) OR (SIZE < 3)");
|
||||
EXPECT_TRUE(V1o3(two).empty());
|
||||
EXPECT_TRUE(V1o3(eight).empty());
|
||||
EXPECT_TRUE(V1o3(ten).empty());
|
||||
EXPECT_TRUE(V1o3(two).empty());
|
||||
EXPECT_FALSE(V1o3(four).empty());
|
||||
CHECK("(SIZE >= 5) OR (SIZE < 3)" == V1o3.get_description());
|
||||
CHECK(V1o3(two).empty());
|
||||
CHECK(V1o3(eight).empty());
|
||||
CHECK(V1o3(ten).empty());
|
||||
CHECK(V1o3(two).empty());
|
||||
CHECK(!V1o3(four).empty());
|
||||
|
||||
auto m1 = V1o3 & V4;
|
||||
EXPECT_EQ(m1.get_description(), "((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)");
|
||||
EXPECT_TRUE(m1(two).empty());
|
||||
EXPECT_TRUE(m1(eight).empty());
|
||||
EXPECT_FALSE(m1(ten).empty());
|
||||
EXPECT_TRUE(m1(two).empty());
|
||||
EXPECT_TRUE(m1(five).empty());
|
||||
EXPECT_FALSE(m1(four).empty());
|
||||
CHECK("((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)" == m1.get_description());
|
||||
CHECK(m1(two).empty());
|
||||
CHECK(m1(eight).empty());
|
||||
CHECK(!m1(ten).empty());
|
||||
CHECK(m1(two).empty());
|
||||
CHECK(m1(five).empty());
|
||||
CHECK(!m1(four).empty());
|
||||
|
||||
auto m2 = m1 & V2;
|
||||
EXPECT_EQ(m2.get_description(), "(((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)");
|
||||
EXPECT_FALSE(m2(two).empty());
|
||||
EXPECT_FALSE(m2(eight).empty());
|
||||
EXPECT_FALSE(m2(ten).empty());
|
||||
EXPECT_FALSE(m2(two).empty());
|
||||
EXPECT_TRUE(m2(nine).empty());
|
||||
EXPECT_FALSE(m2(four).empty());
|
||||
CHECK("(((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)" == m2.get_description());
|
||||
CHECK(!m2(two).empty());
|
||||
CHECK(!m2(eight).empty());
|
||||
CHECK(!m2(ten).empty());
|
||||
CHECK(!m2(two).empty());
|
||||
CHECK(m2(nine).empty());
|
||||
CHECK(!m2(four).empty());
|
||||
|
||||
auto m3 = m2 | V3;
|
||||
EXPECT_EQ(m3.get_description(), "((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)) OR (SIZE < 3)");
|
||||
EXPECT_TRUE(m3(two).empty());
|
||||
EXPECT_FALSE(m3(eight).empty());
|
||||
EXPECT_TRUE(m3(nine).empty());
|
||||
EXPECT_FALSE(m3(four).empty());
|
||||
CHECK("((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9)) OR (SIZE < 3)" == m3.get_description());
|
||||
CHECK(m3(two).empty());
|
||||
CHECK(!m3(eight).empty());
|
||||
CHECK(m3(nine).empty());
|
||||
CHECK(!m3(four).empty());
|
||||
|
||||
auto m4 = V3 | m2;
|
||||
EXPECT_EQ(m4.get_description(), "(SIZE < 3) OR ((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9))");
|
||||
EXPECT_TRUE(m4(two).empty());
|
||||
EXPECT_FALSE(m4(eight).empty());
|
||||
EXPECT_TRUE(m4(nine).empty());
|
||||
EXPECT_FALSE(m4(four).empty());
|
||||
CHECK("(SIZE < 3) OR ((((SIZE >= 5) OR (SIZE < 3)) AND (SIZE <= 9)) AND (SIZE >= 9))" == m4.get_description());
|
||||
CHECK(m4(two).empty());
|
||||
CHECK(!m4(eight).empty());
|
||||
CHECK(m4(nine).empty());
|
||||
CHECK(!m4(four).empty());
|
||||
}
|
||||
|
||||
TEST(ValidatorTests, TestValidatorNegation) {
|
||||
TEST_CASE("ValidatorTests: TestValidatorNegation", "[creation]") {
|
||||
|
||||
std::function<std::string(std::string &)> op1 = [](std::string &val) {
|
||||
return (val.size() >= 5) ? std::string{} : val;
|
||||
@ -666,21 +669,21 @@ TEST(ValidatorTests, TestValidatorNegation) {
|
||||
std::string four(4, 'a');
|
||||
std::string five(5, 'a');
|
||||
|
||||
EXPECT_TRUE(V1(five).empty());
|
||||
EXPECT_FALSE(V1(four).empty());
|
||||
CHECK(V1(five).empty());
|
||||
CHECK(!V1(four).empty());
|
||||
|
||||
auto V2 = !V1;
|
||||
EXPECT_FALSE(V2(five).empty());
|
||||
EXPECT_TRUE(V2(four).empty());
|
||||
EXPECT_EQ(V2.get_description(), "NOT SIZE >= 5");
|
||||
CHECK(!V2(five).empty());
|
||||
CHECK(V2(four).empty());
|
||||
CHECK("NOT SIZE >= 5" == V2.get_description());
|
||||
|
||||
V2.active(false);
|
||||
EXPECT_TRUE(V2(five).empty());
|
||||
EXPECT_TRUE(V2(four).empty());
|
||||
EXPECT_TRUE(V2.get_description().empty());
|
||||
CHECK(V2(five).empty());
|
||||
CHECK(V2(four).empty());
|
||||
CHECK(V2.get_description().empty());
|
||||
}
|
||||
|
||||
TEST(ValidatorTests, ValidatorDefaults) {
|
||||
TEST_CASE("ValidatorTests: ValidatorDefaults", "[creation]") {
|
||||
|
||||
CLI::Validator V1{};
|
||||
|
||||
@ -688,23 +691,23 @@ TEST(ValidatorTests, ValidatorDefaults) {
|
||||
std::string five(5, 'a');
|
||||
|
||||
// make sure this doesn't generate a seg fault or something
|
||||
EXPECT_TRUE(V1(five).empty());
|
||||
EXPECT_TRUE(V1(four).empty());
|
||||
CHECK(V1(five).empty());
|
||||
CHECK(V1(four).empty());
|
||||
|
||||
EXPECT_TRUE(V1.get_name().empty());
|
||||
EXPECT_TRUE(V1.get_description().empty());
|
||||
EXPECT_TRUE(V1.get_active());
|
||||
EXPECT_TRUE(V1.get_modifying());
|
||||
CHECK(V1.get_name().empty());
|
||||
CHECK(V1.get_description().empty());
|
||||
CHECK(V1.get_active());
|
||||
CHECK(V1.get_modifying());
|
||||
|
||||
CLI::Validator V2{"check"};
|
||||
// make sure this doesn't generate a seg fault or something
|
||||
EXPECT_TRUE(V2(five).empty());
|
||||
EXPECT_TRUE(V2(four).empty());
|
||||
CHECK(V2(five).empty());
|
||||
CHECK(V2(four).empty());
|
||||
|
||||
EXPECT_TRUE(V2.get_name().empty());
|
||||
EXPECT_EQ(V2.get_description(), "check");
|
||||
EXPECT_TRUE(V2.get_active());
|
||||
EXPECT_TRUE(V2.get_modifying());
|
||||
CHECK(V2.get_name().empty());
|
||||
CHECK("check" == V2.get_description());
|
||||
CHECK(V2.get_active());
|
||||
CHECK(V2.get_modifying());
|
||||
// This class only support streaming in, not out
|
||||
}
|
||||
|
||||
@ -731,7 +734,7 @@ std::istream &operator>>(std::istream &in, Unstreamable &value) {
|
||||
static_assert(CLI::detail::is_istreamable<Unstreamable>::value,
|
||||
"Unstreamable type is still unstreamable and it should be");
|
||||
|
||||
TEST_F(TApp, MakeUnstreamableOptions) {
|
||||
TEST_CASE_METHOD(TApp, "MakeUnstreamableOptions", "[creation]") {
|
||||
Unstreamable value;
|
||||
app.add_option("--value", value);
|
||||
|
||||
@ -746,10 +749,10 @@ TEST_F(TApp, MakeUnstreamableOptions) {
|
||||
|
||||
args = {"--value", "45"};
|
||||
run();
|
||||
EXPECT_EQ(value.get_x(), 45);
|
||||
CHECK(45 == value.get_x());
|
||||
|
||||
args = {"--values", "45", "27", "34"};
|
||||
run();
|
||||
EXPECT_EQ(values.size(), 3u);
|
||||
EXPECT_EQ(values[2].get_x(), 34);
|
||||
CHECK(3u == values.size());
|
||||
CHECK(34 == values[2].get_x());
|
||||
}
|
||||
|
@ -6,157 +6,16 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::Not;
|
||||
|
||||
TEST(Deprecated, Empty) {
|
||||
TEST_CASE("Deprecated: Empty", "[deprecated]") {
|
||||
// No deprecated features at this time.
|
||||
EXPECT_TRUE(true);
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
// Classic sets
|
||||
|
||||
TEST_F(TApp, SetWithDefaults) {
|
||||
int someint = 2;
|
||||
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);
|
||||
|
||||
args = {"-a1", "-a2"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SetWithDefaultsConversion) {
|
||||
int someint = 2;
|
||||
app.add_set("-a", someint, {1, 2, 3, 4}, "", true);
|
||||
|
||||
args = {"-a", "hi"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSet) {
|
||||
|
||||
std::string choice;
|
||||
app.add_set("-q,--quick", choice, {"one", "two", "three"});
|
||||
|
||||
args = {"--quick", "two"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ("two", choice);
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetWithDefault) {
|
||||
|
||||
std::string choice = "one";
|
||||
app.add_set("-q,--quick", choice, {"one", "two", "three"}, "", true);
|
||||
|
||||
run();
|
||||
EXPECT_EQ("one", choice);
|
||||
|
||||
args = {"--quick", "two"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ("two", choice);
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InIntSet) {
|
||||
|
||||
int choice;
|
||||
app.add_set("-q,--quick", choice, {1, 2, 3});
|
||||
|
||||
args = {"--quick", "2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(2, choice);
|
||||
|
||||
args = {"--quick", "4"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InIntSetWindows) {
|
||||
|
||||
int choice;
|
||||
app.add_set("-q,--quick", choice, {1, 2, 3});
|
||||
app.allow_windows_style_options();
|
||||
args = {"/q", "2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(2, choice);
|
||||
|
||||
args = {"/q", "4"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
|
||||
args = {"/q4"};
|
||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, FailSet) {
|
||||
|
||||
int choice;
|
||||
app.add_set("-q,--quick", choice, {1, 2, 3});
|
||||
|
||||
args = {"--quick", "3", "--quick=2"};
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
|
||||
args = {"--quick=hello"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, FailMutableSet) {
|
||||
|
||||
int choice;
|
||||
std::set<int> vals{1, 2, 3};
|
||||
app.add_mutable_set("-q,--quick", choice, vals);
|
||||
app.add_mutable_set("-s,--slow", choice, vals, "", true);
|
||||
|
||||
args = {"--quick=hello"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--slow=hello"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
// #113
|
||||
TEST_F(TApp, AddRemoveSetItems) {
|
||||
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
||||
|
||||
std::string type1, type2;
|
||||
app.add_mutable_set("--type1", type1, items);
|
||||
app.add_mutable_set("--type2", type2, items, "", true);
|
||||
|
||||
args = {"--type1", "TYPE1", "--type2", "TYPE2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(type1, "TYPE1");
|
||||
EXPECT_EQ(type2, "TYPE2");
|
||||
|
||||
items.insert("TYPE6");
|
||||
items.insert("TYPE7");
|
||||
|
||||
items.erase("TYPE1");
|
||||
items.erase("TYPE2");
|
||||
|
||||
args = {"--type1", "TYPE6", "--type2", "TYPE7"};
|
||||
run();
|
||||
EXPECT_EQ(type1, "TYPE6");
|
||||
EXPECT_EQ(type2, "TYPE7");
|
||||
|
||||
args = {"--type1", "TYPE1"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--type2", "TYPE2"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST(THelp, Defaults) {
|
||||
TEST_CASE("THelp: Defaults", "[deprecated]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
int one{1}, two{2};
|
||||
@ -165,24 +24,24 @@ TEST(THelp, Defaults) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("--one"));
|
||||
EXPECT_THAT(help, HasSubstr("--set"));
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("=2"));
|
||||
EXPECT_THAT(help, HasSubstr("2,3,4"));
|
||||
CHECK_THAT(help, Contains("--one"));
|
||||
CHECK_THAT(help, Contains("--set"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("=2"));
|
||||
CHECK_THAT(help, Contains("2,3,4"));
|
||||
}
|
||||
|
||||
TEST(THelp, VectorOpts) {
|
||||
TEST_CASE("THelp: VectorOpts", "[deprecated]") {
|
||||
CLI::App app{"My prog"};
|
||||
std::vector<int> x = {1, 2};
|
||||
app.add_option("-q,--quick", x, "", true);
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("INT=[1,2] ..."));
|
||||
CHECK_THAT(help, Contains("INT=[1,2] ..."));
|
||||
}
|
||||
|
||||
TEST(THelp, SetLower) {
|
||||
TEST_CASE("THelp: SetLower", "[deprecated]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
std::string def{"One"};
|
||||
@ -190,14 +49,14 @@ TEST(THelp, SetLower) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("--set"));
|
||||
EXPECT_THAT(help, HasSubstr("=One"));
|
||||
EXPECT_THAT(help, HasSubstr("oNe"));
|
||||
EXPECT_THAT(help, HasSubstr("twO"));
|
||||
EXPECT_THAT(help, HasSubstr("THREE"));
|
||||
CHECK_THAT(help, Contains("--set"));
|
||||
CHECK_THAT(help, Contains("=One"));
|
||||
CHECK_THAT(help, Contains("oNe"));
|
||||
CHECK_THAT(help, Contains("twO"));
|
||||
CHECK_THAT(help, Contains("THREE"));
|
||||
}
|
||||
|
||||
TEST(THelp, ChangingSetDefaulted) {
|
||||
TEST_CASE("THelp: ChangingSetDefaulted", "[deprecated]") {
|
||||
CLI::App app;
|
||||
|
||||
std::set<int> vals{1, 2, 3};
|
||||
@ -206,19 +65,19 @@ TEST(THelp, ChangingSetDefaulted) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, Not(HasSubstr("4")));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, !Contains("4"));
|
||||
|
||||
vals.insert(4);
|
||||
vals.erase(1);
|
||||
|
||||
help = app.help();
|
||||
|
||||
EXPECT_THAT(help, Not(HasSubstr("1")));
|
||||
EXPECT_THAT(help, HasSubstr("4"));
|
||||
CHECK_THAT(help, !Contains("1"));
|
||||
CHECK_THAT(help, Contains("4"));
|
||||
}
|
||||
|
||||
TEST(THelp, ChangingCaselessSetDefaulted) {
|
||||
TEST_CASE("THelp: ChangingCaselessSetDefaulted", "[deprecated]") {
|
||||
CLI::App app;
|
||||
|
||||
std::set<std::string> vals{"1", "2", "3"};
|
||||
@ -227,19 +86,19 @@ TEST(THelp, ChangingCaselessSetDefaulted) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, Not(HasSubstr("4")));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, !Contains("4"));
|
||||
|
||||
vals.insert("4");
|
||||
vals.erase("1");
|
||||
|
||||
help = app.help();
|
||||
|
||||
EXPECT_THAT(help, Not(HasSubstr("1")));
|
||||
EXPECT_THAT(help, HasSubstr("4"));
|
||||
CHECK_THAT(help, !Contains("1"));
|
||||
CHECK_THAT(help, Contains("4"));
|
||||
}
|
||||
|
||||
TEST_F(TApp, DefaultOpts) {
|
||||
TEST_CASE_METHOD(TApp, "DefaultOpts", "[deprecated]") {
|
||||
|
||||
int i = 3;
|
||||
std::string s = "HI";
|
||||
@ -251,116 +110,116 @@ TEST_F(TApp, DefaultOpts) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(1u, app.count("i"));
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(2, i);
|
||||
EXPECT_EQ("9", s);
|
||||
CHECK(app.count("i") == 1u);
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(i == 2);
|
||||
CHECK(s == "9");
|
||||
}
|
||||
|
||||
TEST_F(TApp, VectorDefaultedFixedString) {
|
||||
TEST_CASE_METHOD(TApp, "VectorDefaultedFixedString", "[deprecated]") {
|
||||
std::vector<std::string> strvec{"one"};
|
||||
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
|
||||
|
||||
CLI::Option *opt = app.add_option("-s,--string", strvec, "", true)->expected(3);
|
||||
EXPECT_EQ(3, opt->get_expected());
|
||||
CHECK(opt->get_expected() == 3);
|
||||
|
||||
args = {"--string", "mystring", "mystring2", "mystring3"};
|
||||
run();
|
||||
EXPECT_EQ(3u, app.count("--string"));
|
||||
EXPECT_EQ(answer, strvec);
|
||||
CHECK(app.count("--string") == 3u);
|
||||
CHECK(strvec == answer);
|
||||
}
|
||||
|
||||
TEST_F(TApp, DefaultedResult) {
|
||||
TEST_CASE_METHOD(TApp, "DefaultedResult", "[deprecated]") {
|
||||
std::string sval = "NA";
|
||||
int ival;
|
||||
auto opts = app.add_option("--string", sval, "", true);
|
||||
auto optv = app.add_option("--val", ival);
|
||||
args = {};
|
||||
run();
|
||||
EXPECT_EQ(sval, "NA");
|
||||
CHECK("NA" == sval);
|
||||
std::string nString;
|
||||
opts->results(nString);
|
||||
EXPECT_EQ(nString, "NA");
|
||||
CHECK("NA" == nString);
|
||||
int newIval;
|
||||
// EXPECT_THROW(optv->results(newIval), CLI::ConversionError);
|
||||
// CHECK_THROWS_AS (optv->results(newIval), CLI::ConversionError);
|
||||
optv->default_str("442");
|
||||
optv->results(newIval);
|
||||
EXPECT_EQ(newIval, 442);
|
||||
CHECK(442 == newIval);
|
||||
}
|
||||
|
||||
TEST_F(TApp, OptionWithDefaults) {
|
||||
TEST_CASE_METHOD(TApp, "OptionWithDefaults", "[deprecated]") {
|
||||
int someint = 2;
|
||||
app.add_option("-a", someint, "", true);
|
||||
|
||||
args = {"-a1", "-a2"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
// #209
|
||||
TEST_F(TApp, CustomUserSepParse) {
|
||||
TEST_CASE_METHOD(TApp, "CustomUserSepParse", "[deprecated]") {
|
||||
|
||||
std::vector<int> vals = {1, 2, 3};
|
||||
args = {"--idx", "1,2,3"};
|
||||
auto opt = app.add_option("--idx", vals)->delimiter(',');
|
||||
run();
|
||||
EXPECT_EQ(vals, std::vector<int>({1, 2, 3}));
|
||||
CHECK(std::vector<int>({1, 2, 3}) == vals);
|
||||
std::vector<int> vals2;
|
||||
// check that the results vector gets the results in the same way
|
||||
opt->results(vals2);
|
||||
EXPECT_EQ(vals2, vals);
|
||||
CHECK(vals == vals2);
|
||||
|
||||
app.remove_option(opt);
|
||||
|
||||
app.add_option("--idx", vals, "", true)->delimiter(',');
|
||||
run();
|
||||
EXPECT_EQ(vals, std::vector<int>({1, 2, 3}));
|
||||
CHECK(std::vector<int>({1, 2, 3}) == vals);
|
||||
}
|
||||
|
||||
// #209
|
||||
TEST_F(TApp, CustomUserSepParse2) {
|
||||
TEST_CASE_METHOD(TApp, "CustomUserSepParse2", "[deprecated]") {
|
||||
|
||||
std::vector<int> vals = {1, 2, 3};
|
||||
args = {"--idx", "1,2,"};
|
||||
auto opt = app.add_option("--idx", vals)->delimiter(',');
|
||||
run();
|
||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
||||
CHECK(std::vector<int>({1, 2}) == vals);
|
||||
|
||||
app.remove_option(opt);
|
||||
|
||||
app.add_option("--idx", vals, "", true)->delimiter(',');
|
||||
run();
|
||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
||||
CHECK(std::vector<int>({1, 2}) == vals);
|
||||
}
|
||||
//
|
||||
// #209
|
||||
TEST_F(TApp, CustomUserSepParse4) {
|
||||
TEST_CASE_METHOD(TApp, "CustomUserSepParse4", "[deprecated]") {
|
||||
|
||||
std::vector<int> vals;
|
||||
args = {"--idx", "1, 2"};
|
||||
auto opt = app.add_option("--idx", vals, "", true)->delimiter(',');
|
||||
run();
|
||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
||||
CHECK(std::vector<int>({1, 2}) == vals);
|
||||
|
||||
app.remove_option(opt);
|
||||
|
||||
app.add_option("--idx", vals)->delimiter(',');
|
||||
run();
|
||||
EXPECT_EQ(vals, std::vector<int>({1, 2}));
|
||||
CHECK(std::vector<int>({1, 2}) == vals);
|
||||
}
|
||||
|
||||
// #218
|
||||
TEST_F(TApp, CustomUserSepParse5) {
|
||||
TEST_CASE_METHOD(TApp, "CustomUserSepParse5", "[deprecated]") {
|
||||
|
||||
std::vector<std::string> bar;
|
||||
args = {"this", "is", "a", "test"};
|
||||
auto opt = app.add_option("bar", bar, "bar");
|
||||
run();
|
||||
EXPECT_EQ(bar, std::vector<std::string>({"this", "is", "a", "test"}));
|
||||
CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar);
|
||||
|
||||
app.remove_option(opt);
|
||||
args = {"this", "is", "a", "test"};
|
||||
app.add_option("bar", bar, "bar", true);
|
||||
run();
|
||||
EXPECT_EQ(bar, std::vector<std::string>({"this", "is", "a", "test"}));
|
||||
CHECK(std::vector<std::string>({"this", "is", "a", "test"}) == bar);
|
||||
}
|
||||
|
@ -10,12 +10,10 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#endif
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "catch.hpp"
|
||||
#include <fstream>
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::Not;
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
class SimpleFormatter : public CLI::FormatterBase {
|
||||
public:
|
||||
@ -26,17 +24,17 @@ class SimpleFormatter : public CLI::FormatterBase {
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Formatter, Nothing) {
|
||||
TEST_CASE("Formatter: Nothing", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
app.formatter(std::make_shared<SimpleFormatter>());
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_EQ(help, "This is really simple");
|
||||
CHECK("This is really simple" == help);
|
||||
}
|
||||
|
||||
TEST(Formatter, NothingLambda) {
|
||||
TEST_CASE("Formatter: NothingLambda", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
app.formatter_fn(
|
||||
@ -44,10 +42,10 @@ TEST(Formatter, NothingLambda) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_EQ(help, "This is really simple");
|
||||
CHECK("This is really simple" == help);
|
||||
}
|
||||
|
||||
TEST(Formatter, OptCustomize) {
|
||||
TEST_CASE("Formatter: OptCustomize", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
auto optfmt = std::make_shared<CLI::Formatter>();
|
||||
@ -60,16 +58,15 @@ TEST(Formatter, OptCustomize) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("(MUST HAVE)"));
|
||||
EXPECT_EQ(help,
|
||||
"My prog\n"
|
||||
"Usage: [OPTIONS]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n"
|
||||
" --opt INT (MUST HAVE) Something\n\n");
|
||||
CHECK_THAT(help, Contains("(MUST HAVE)"));
|
||||
CHECK(help == "My prog\n"
|
||||
"Usage: [OPTIONS]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n"
|
||||
" --opt INT (MUST HAVE) Something\n\n");
|
||||
}
|
||||
|
||||
TEST(Formatter, OptCustomizeSimple) {
|
||||
TEST_CASE("Formatter: OptCustomizeSimple", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
app.get_formatter()->column_width(25);
|
||||
@ -80,16 +77,15 @@ TEST(Formatter, OptCustomizeSimple) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("(MUST HAVE)"));
|
||||
EXPECT_EQ(help,
|
||||
"My prog\n"
|
||||
"Usage: [OPTIONS]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n"
|
||||
" --opt INT (MUST HAVE) Something\n\n");
|
||||
CHECK_THAT(help, Contains("(MUST HAVE)"));
|
||||
CHECK(help == "My prog\n"
|
||||
"Usage: [OPTIONS]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n"
|
||||
" --opt INT (MUST HAVE) Something\n\n");
|
||||
}
|
||||
|
||||
TEST(Formatter, OptCustomizeOptionText) {
|
||||
TEST_CASE("Formatter: OptCustomizeOptionText", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
app.get_formatter()->column_width(25);
|
||||
@ -99,16 +95,15 @@ TEST(Formatter, OptCustomizeOptionText) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("(ARG)"));
|
||||
EXPECT_EQ(help,
|
||||
"My prog\n"
|
||||
"Usage: [OPTIONS]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n"
|
||||
" --opt (ARG) Something\n\n");
|
||||
CHECK_THAT(help, Contains("(ARG)"));
|
||||
CHECK(help == "My prog\n"
|
||||
"Usage: [OPTIONS]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n"
|
||||
" --opt (ARG) Something\n\n");
|
||||
}
|
||||
|
||||
TEST(Formatter, FalseFlagExample) {
|
||||
TEST_CASE("Formatter: FalseFlagExample", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
app.get_formatter()->column_width(25);
|
||||
@ -122,12 +117,12 @@ TEST(Formatter, FalseFlagExample) {
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("--no_opt{false}"));
|
||||
EXPECT_THAT(help, HasSubstr("--no_opt2{false}"));
|
||||
EXPECT_THAT(help, HasSubstr("-O{false}"));
|
||||
CHECK_THAT(help, Contains("--no_opt{false}"));
|
||||
CHECK_THAT(help, Contains("--no_opt2{false}"));
|
||||
CHECK_THAT(help, Contains("-O{false}"));
|
||||
}
|
||||
|
||||
TEST(Formatter, AppCustomize) {
|
||||
TEST_CASE("Formatter: AppCustomize", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
app.add_subcommand("subcom1", "This");
|
||||
|
||||
@ -139,17 +134,16 @@ TEST(Formatter, AppCustomize) {
|
||||
app.add_subcommand("subcom2", "This");
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_EQ(help,
|
||||
"My prog\n"
|
||||
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n\n"
|
||||
"Subcommands:\n"
|
||||
" subcom1 This\n"
|
||||
" subcom2 This\n\n");
|
||||
CHECK(help == "My prog\n"
|
||||
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n\n"
|
||||
"Subcommands:\n"
|
||||
" subcom1 This\n"
|
||||
" subcom2 This\n\n");
|
||||
}
|
||||
|
||||
TEST(Formatter, AppCustomizeSimple) {
|
||||
TEST_CASE("Formatter: AppCustomizeSimple", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
app.add_subcommand("subcom1", "This");
|
||||
|
||||
@ -159,48 +153,47 @@ TEST(Formatter, AppCustomizeSimple) {
|
||||
app.add_subcommand("subcom2", "This");
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_EQ(help,
|
||||
"My prog\n"
|
||||
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n\n"
|
||||
"Subcommands:\n"
|
||||
" subcom1 This\n"
|
||||
" subcom2 This\n\n");
|
||||
CHECK(help == "My prog\n"
|
||||
"Run: [OPTIONS] [SUBCOMMAND]\n\n"
|
||||
"Options:\n"
|
||||
" -h,--help Print this help message and exit\n\n"
|
||||
"Subcommands:\n"
|
||||
" subcom1 This\n"
|
||||
" subcom2 This\n\n");
|
||||
}
|
||||
|
||||
TEST(Formatter, AllSub) {
|
||||
TEST_CASE("Formatter: AllSub", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
CLI::App *sub = app.add_subcommand("subcom", "This");
|
||||
sub->add_flag("--insub", "MyFlag");
|
||||
|
||||
std::string help = app.help("", CLI::AppFormatMode::All);
|
||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
||||
EXPECT_THAT(help, HasSubstr("subcom"));
|
||||
CHECK_THAT(help, Contains("--insub"));
|
||||
CHECK_THAT(help, Contains("subcom"));
|
||||
}
|
||||
|
||||
TEST(Formatter, AllSubRequired) {
|
||||
TEST_CASE("Formatter: AllSubRequired", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
CLI::App *sub = app.add_subcommand("subcom", "This");
|
||||
sub->add_flag("--insub", "MyFlag");
|
||||
sub->required();
|
||||
std::string help = app.help("", CLI::AppFormatMode::All);
|
||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
||||
EXPECT_THAT(help, HasSubstr("subcom"));
|
||||
EXPECT_THAT(help, HasSubstr("REQUIRED"));
|
||||
CHECK_THAT(help, Contains("--insub"));
|
||||
CHECK_THAT(help, Contains("subcom"));
|
||||
CHECK_THAT(help, Contains("REQUIRED"));
|
||||
}
|
||||
|
||||
TEST(Formatter, NamelessSub) {
|
||||
TEST_CASE("Formatter: NamelessSub", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
CLI::App *sub = app.add_subcommand("", "This subcommand");
|
||||
sub->add_flag("--insub", "MyFlag");
|
||||
|
||||
std::string help = app.help("", CLI::AppFormatMode::Normal);
|
||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
||||
EXPECT_THAT(help, HasSubstr("This subcommand"));
|
||||
CHECK_THAT(help, Contains("--insub"));
|
||||
CHECK_THAT(help, Contains("This subcommand"));
|
||||
}
|
||||
|
||||
TEST(Formatter, NamelessSubInGroup) {
|
||||
TEST_CASE("Formatter: NamelessSubInGroup", "[formatter]") {
|
||||
CLI::App app{"My prog"};
|
||||
CLI::App *sub = app.add_subcommand("", "This subcommand");
|
||||
CLI::App *sub2 = app.add_subcommand("sub2", "subcommand2");
|
||||
@ -210,9 +203,9 @@ TEST(Formatter, NamelessSubInGroup) {
|
||||
sub->group("group1");
|
||||
sub2->group("group1");
|
||||
std::string help = app.help("", CLI::AppFormatMode::Normal);
|
||||
EXPECT_THAT(help, HasSubstr("--insub"));
|
||||
EXPECT_THAT(help, HasSubstr("This subcommand"));
|
||||
EXPECT_THAT(help, HasSubstr("group1"));
|
||||
EXPECT_THAT(help, HasSubstr("sub2"));
|
||||
EXPECT_TRUE(help.find("pos") == std::string::npos);
|
||||
CHECK_THAT(help, Contains("--insub"));
|
||||
CHECK_THAT(help, Contains("This subcommand"));
|
||||
CHECK_THAT(help, Contains("group1"));
|
||||
CHECK_THAT(help, Contains("sub2"));
|
||||
CHECK(help.find("pos") == std::string::npos);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -5,159 +5,159 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#include "app_helper.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include <complex>
|
||||
#include <cstdint>
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using cx = std::complex<double>;
|
||||
|
||||
TEST_F(TApp, Complex) {
|
||||
TEST_CASE_METHOD(TApp, "Complex", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_complex("-c,--complex", comp, "", true);
|
||||
|
||||
args = {"-c", "4", "3"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
CHECK_THAT(help, Contains("COMPLEX"));
|
||||
|
||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexOption) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexOption", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_option("-c,--complex", comp, "", true);
|
||||
|
||||
args = {"-c", "4", "3"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
CHECK_THAT(help, Contains("COMPLEX"));
|
||||
|
||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexFloat) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexFloat", "[newparse]") {
|
||||
std::complex<float> comp{1, 2};
|
||||
app.add_complex<std::complex<float>, float>("-c,--complex", comp, "", true);
|
||||
|
||||
args = {"-c", "4", "3"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
CHECK_THAT(help, Contains("COMPLEX"));
|
||||
|
||||
EXPECT_FLOAT_EQ(1, comp.real());
|
||||
EXPECT_FLOAT_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_FLOAT_EQ(4, comp.real());
|
||||
EXPECT_FLOAT_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexFloatOption) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexFloatOption", "[newparse]") {
|
||||
std::complex<float> comp{1, 2};
|
||||
app.add_option("-c,--complex", comp, "", true);
|
||||
|
||||
args = {"-c", "4", "3"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
CHECK_THAT(help, Contains("COMPLEX"));
|
||||
|
||||
EXPECT_FLOAT_EQ(1, comp.real());
|
||||
EXPECT_FLOAT_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_FLOAT_EQ(4, comp.real());
|
||||
EXPECT_FLOAT_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexWithDelimiter) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexWithDelimiter", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_complex("-c,--complex", comp, "", true)->delimiter('+');
|
||||
|
||||
args = {"-c", "4+3i"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
CHECK_THAT(help, Contains("COMPLEX"));
|
||||
|
||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
|
||||
args = {"-c", "5+-3i"};
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(5, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-3, comp.imag());
|
||||
CHECK(comp.real() == Approx(5));
|
||||
CHECK(comp.imag() == Approx(-3));
|
||||
|
||||
args = {"-c", "6", "-4i"};
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(6, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
||||
CHECK(comp.real() == Approx(6));
|
||||
CHECK(comp.imag() == Approx(-4));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexWithDelimiterOption) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexWithDelimiterOption", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_option("-c,--complex", comp, "", true)->delimiter('+');
|
||||
|
||||
args = {"-c", "4+3i"};
|
||||
|
||||
std::string help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("1"));
|
||||
EXPECT_THAT(help, HasSubstr("2"));
|
||||
EXPECT_THAT(help, HasSubstr("COMPLEX"));
|
||||
CHECK_THAT(help, Contains("1"));
|
||||
CHECK_THAT(help, Contains("2"));
|
||||
CHECK_THAT(help, Contains("COMPLEX"));
|
||||
|
||||
EXPECT_DOUBLE_EQ(1, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(1));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
|
||||
args = {"-c", "5+-3i"};
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(5, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-3, comp.imag());
|
||||
CHECK(comp.real() == Approx(5));
|
||||
CHECK(comp.imag() == Approx(-3));
|
||||
|
||||
args = {"-c", "6", "-4i"};
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(6, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
||||
CHECK(comp.real() == Approx(6));
|
||||
CHECK(comp.imag() == Approx(-4));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexIgnoreI) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexIgnoreI", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_complex("-c,--complex", comp);
|
||||
|
||||
@ -165,11 +165,11 @@ TEST_F(TApp, ComplexIgnoreI) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexIgnoreIOption) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexIgnoreIOption", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_option("-c,--complex", comp);
|
||||
|
||||
@ -177,122 +177,122 @@ TEST_F(TApp, ComplexIgnoreIOption) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(3, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(3));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexSingleArg) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexSingleArg", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_complex("-c,--complex", comp);
|
||||
|
||||
args = {"-c", "4"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(0));
|
||||
|
||||
args = {"-c", "4-2i"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(-2));
|
||||
args = {"-c", "4+2i"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
args = {"-c", "-4+2j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
args = {"-c", "-4.2-2j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4.2));
|
||||
CHECK(comp.imag() == Approx(-2));
|
||||
|
||||
args = {"-c", "-4.2-2.7i"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2.7, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4.2));
|
||||
CHECK(comp.imag() == Approx(-2.7));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexSingleArgOption) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexSingleArgOption", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_option("-c,--complex", comp);
|
||||
|
||||
args = {"-c", "4"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(0));
|
||||
|
||||
args = {"-c", "4-2i"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(-2));
|
||||
args = {"-c", "4+2i"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
args = {"-c", "-4+2j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(2, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4));
|
||||
CHECK(comp.imag() == Approx(2));
|
||||
|
||||
args = {"-c", "-4.2-2j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4.2));
|
||||
CHECK(comp.imag() == Approx(-2));
|
||||
|
||||
args = {"-c", "-4.2-2.7i"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4.2, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-2.7, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4.2));
|
||||
CHECK(comp.imag() == Approx(-2.7));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexSingleImag) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexSingleImag", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_complex("-c,--complex", comp);
|
||||
|
||||
args = {"-c", "4j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
||||
EXPECT_DOUBLE_EQ(4, comp.imag());
|
||||
CHECK(comp.real() == Approx(0));
|
||||
CHECK(comp.imag() == Approx(4));
|
||||
|
||||
args = {"-c", "-4j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
||||
CHECK(comp.real() == Approx(0));
|
||||
CHECK(comp.imag() == Approx(-4));
|
||||
args = {"-c", "-4"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4));
|
||||
CHECK(comp.imag() == Approx(0));
|
||||
args = {"-c", "+4"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(0));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ComplexSingleImagOption) {
|
||||
TEST_CASE_METHOD(TApp, "ComplexSingleImagOption", "[newparse]") {
|
||||
cx comp{1, 2};
|
||||
app.add_option("-c,--complex", comp);
|
||||
|
||||
args = {"-c", "4j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
||||
EXPECT_DOUBLE_EQ(4, comp.imag());
|
||||
CHECK(comp.real() == Approx(0));
|
||||
CHECK(comp.imag() == Approx(4));
|
||||
|
||||
args = {"-c", "-4j"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(0, comp.real());
|
||||
EXPECT_DOUBLE_EQ(-4, comp.imag());
|
||||
CHECK(comp.real() == Approx(0));
|
||||
CHECK(comp.imag() == Approx(-4));
|
||||
args = {"-c", "-4"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(-4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
||||
CHECK(comp.real() == Approx(-4));
|
||||
CHECK(comp.imag() == Approx(0));
|
||||
args = {"-c", "+4"};
|
||||
run();
|
||||
EXPECT_DOUBLE_EQ(4, comp.real());
|
||||
EXPECT_DOUBLE_EQ(0, comp.imag());
|
||||
CHECK(comp.real() == Approx(4));
|
||||
CHECK(comp.imag() == Approx(0));
|
||||
}
|
||||
|
||||
/// Simple class containing two strings useful for testing lexical cast and conversions
|
||||
@ -321,24 +321,24 @@ template <> bool lexical_cast<spair>(const std::string &input, spair &output) {
|
||||
} // namespace detail
|
||||
} // namespace CLI
|
||||
|
||||
TEST_F(TApp, custom_string_converter) {
|
||||
TEST_CASE_METHOD(TApp, "custom_string_converter", "[newparse]") {
|
||||
spair val;
|
||||
app.add_option("-d,--dual_string", val);
|
||||
|
||||
args = {"-d", "string1:string2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(val.first, "string1");
|
||||
EXPECT_EQ(val.second, "string2");
|
||||
CHECK("string1" == val.first);
|
||||
CHECK("string2" == val.second);
|
||||
}
|
||||
|
||||
TEST_F(TApp, custom_string_converterFail) {
|
||||
TEST_CASE_METHOD(TApp, "custom_string_converterFail", "[newparse]") {
|
||||
spair val;
|
||||
app.add_option("-d,--dual_string", val);
|
||||
|
||||
args = {"-d", "string2"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
/// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the
|
||||
@ -369,14 +369,14 @@ static_assert(CLI::detail::is_direct_constructible<objWrapper<std::string>, std:
|
||||
|
||||
static_assert(!std::is_assignable<objWrapper<std::string>, std::string>::value,
|
||||
"string wrapper is improperly assignable");
|
||||
TEST_F(TApp, stringWrapper) {
|
||||
TEST_CASE_METHOD(TApp, "stringWrapper", "[newparse]") {
|
||||
objWrapper<std::string> sWrapper;
|
||||
app.add_option("-v", sWrapper);
|
||||
args = {"-v", "string test"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(sWrapper.value(), "string test");
|
||||
CHECK("string test" == sWrapper.value());
|
||||
}
|
||||
|
||||
static_assert(CLI::detail::is_direct_constructible<objWrapper<double>, double>::value,
|
||||
@ -388,18 +388,18 @@ static_assert(!CLI::detail::is_direct_constructible<objWrapper<double>, int>::va
|
||||
static_assert(!CLI::detail::is_istreamable<objWrapper<double>>::value,
|
||||
"double wrapper is input streamable and it shouldn't be");
|
||||
|
||||
TEST_F(TApp, doubleWrapper) {
|
||||
TEST_CASE_METHOD(TApp, "doubleWrapper", "[newparse]") {
|
||||
objWrapper<double> dWrapper;
|
||||
app.add_option("-v", dWrapper);
|
||||
args = {"-v", "2.36"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(dWrapper.value(), 2.36);
|
||||
CHECK(2.36 == dWrapper.value());
|
||||
|
||||
args = {"-v", "thing"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
static_assert(CLI::detail::is_direct_constructible<objWrapper<int>, int>::value,
|
||||
@ -411,17 +411,17 @@ static_assert(!CLI::detail::is_direct_constructible<objWrapper<int>, double>::va
|
||||
static_assert(!CLI::detail::is_istreamable<objWrapper<int>>::value,
|
||||
"int wrapper is input streamable and it shouldn't be");
|
||||
|
||||
TEST_F(TApp, intWrapper) {
|
||||
TEST_CASE_METHOD(TApp, "intWrapper", "[newparse]") {
|
||||
objWrapper<int> iWrapper;
|
||||
app.add_option("-v", iWrapper);
|
||||
args = {"-v", "45"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(iWrapper.value(), 45);
|
||||
CHECK(45 == iWrapper.value());
|
||||
args = {"-v", "thing"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
static_assert(!CLI::detail::is_direct_constructible<objWrapper<float>, int>::value,
|
||||
@ -432,17 +432,17 @@ static_assert(!CLI::detail::is_direct_constructible<objWrapper<float>, double>::
|
||||
static_assert(!CLI::detail::is_istreamable<objWrapper<float>>::value,
|
||||
"float wrapper is input streamable and it shouldn't be");
|
||||
|
||||
TEST_F(TApp, floatWrapper) {
|
||||
TEST_CASE_METHOD(TApp, "floatWrapper", "[newparse]") {
|
||||
objWrapper<float> iWrapper;
|
||||
app.add_option<objWrapper<float>, float>("-v", iWrapper);
|
||||
args = {"-v", "45.3"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(iWrapper.value(), 45.3f);
|
||||
CHECK(45.3f == iWrapper.value());
|
||||
args = {"-v", "thing"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -461,26 +461,26 @@ class dobjWrapper {
|
||||
int ival_{0};
|
||||
};
|
||||
|
||||
TEST_F(TApp, dobjWrapper) {
|
||||
TEST_CASE_METHOD(TApp, "dobjWrapper", "[newparse]") {
|
||||
dobjWrapper iWrapper;
|
||||
app.add_option("-v", iWrapper);
|
||||
args = {"-v", "45"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(iWrapper.ivalue(), 45);
|
||||
EXPECT_EQ(iWrapper.dvalue(), 0.0);
|
||||
CHECK(45 == iWrapper.ivalue());
|
||||
CHECK(0.0 == iWrapper.dvalue());
|
||||
|
||||
args = {"-v", "thing"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
iWrapper = dobjWrapper{};
|
||||
|
||||
args = {"-v", "45.1"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(iWrapper.ivalue(), 0);
|
||||
EXPECT_EQ(iWrapper.dvalue(), 45.1);
|
||||
CHECK(0 == iWrapper.ivalue());
|
||||
CHECK(45.1 == iWrapper.dvalue());
|
||||
}
|
||||
|
||||
/// simple class to wrap another with a very specific type constructor and assignment operators to test out some of the
|
||||
@ -507,25 +507,25 @@ template <class X> class AobjWrapper {
|
||||
static_assert(std::is_assignable<AobjWrapper<std::uint16_t> &, std::uint16_t>::value,
|
||||
"AobjWrapper not assignable like it should be ");
|
||||
|
||||
TEST_F(TApp, uint16Wrapper) {
|
||||
TEST_CASE_METHOD(TApp, "uint16Wrapper", "[newparse]") {
|
||||
AobjWrapper<std::uint16_t> sWrapper;
|
||||
app.add_option<AobjWrapper<std::uint16_t>, std::uint16_t>("-v", sWrapper);
|
||||
args = {"-v", "9"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(sWrapper.value(), 9u);
|
||||
CHECK(9u == sWrapper.value());
|
||||
args = {"-v", "thing"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
|
||||
args = {"-v", "72456245754"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
|
||||
args = {"-v", "-3"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
template <class T> class SimpleWrapper {
|
||||
@ -539,25 +539,25 @@ template <class T> class SimpleWrapper {
|
||||
T val_;
|
||||
};
|
||||
|
||||
TEST_F(TApp, wrapperInt) {
|
||||
TEST_CASE_METHOD(TApp, "wrapperInt", "[newparse]") {
|
||||
SimpleWrapper<int> wrap;
|
||||
app.add_option("--val", wrap);
|
||||
args = {"--val", "2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(wrap.getRef(), 2);
|
||||
CHECK(2 == wrap.getRef());
|
||||
}
|
||||
|
||||
TEST_F(TApp, wrapperString) {
|
||||
TEST_CASE_METHOD(TApp, "wrapperString", "[newparse]") {
|
||||
SimpleWrapper<std::string> wrap;
|
||||
app.add_option("--val", wrap);
|
||||
args = {"--val", "str"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(wrap.getRef(), "str");
|
||||
CHECK("str" == wrap.getRef());
|
||||
}
|
||||
|
||||
TEST_F(TApp, wrapperVector) {
|
||||
TEST_CASE_METHOD(TApp, "wrapperVector", "[newparse]") {
|
||||
SimpleWrapper<std::vector<int>> wrap;
|
||||
app.add_option("--val", wrap);
|
||||
args = {"--val", "1", "2", "3", "4"};
|
||||
@ -565,10 +565,10 @@ TEST_F(TApp, wrapperVector) {
|
||||
run();
|
||||
auto v1 = wrap.getRef();
|
||||
auto v2 = std::vector<int>{1, 2, 3, 4};
|
||||
EXPECT_EQ(v1, v2);
|
||||
CHECK(v2 == v1);
|
||||
}
|
||||
|
||||
TEST_F(TApp, wrapperwrapperString) {
|
||||
TEST_CASE_METHOD(TApp, "wrapperwrapperString", "[newparse]") {
|
||||
SimpleWrapper<SimpleWrapper<std::string>> wrap;
|
||||
app.add_option("--val", wrap);
|
||||
args = {"--val", "arg"};
|
||||
@ -576,10 +576,10 @@ TEST_F(TApp, wrapperwrapperString) {
|
||||
run();
|
||||
auto v1 = wrap.getRef().getRef();
|
||||
auto v2 = "arg";
|
||||
EXPECT_EQ(v1, v2);
|
||||
CHECK(v2 == v1);
|
||||
}
|
||||
|
||||
TEST_F(TApp, wrapperwrapperVector) {
|
||||
TEST_CASE_METHOD(TApp, "wrapperwrapperVector", "[newparse]") {
|
||||
SimpleWrapper<SimpleWrapper<std::vector<int>>> wrap;
|
||||
auto opt = app.add_option("--val", wrap);
|
||||
args = {"--val", "1", "2", "3", "4"};
|
||||
@ -587,20 +587,20 @@ TEST_F(TApp, wrapperwrapperVector) {
|
||||
run();
|
||||
auto v1 = wrap.getRef().getRef();
|
||||
auto v2 = std::vector<int>{1, 2, 3, 4};
|
||||
EXPECT_EQ(v1, v2);
|
||||
CHECK(v2 == v1);
|
||||
opt->type_size(0, 5);
|
||||
|
||||
args = {"--val"};
|
||||
|
||||
run();
|
||||
EXPECT_TRUE(wrap.getRef().getRef().empty());
|
||||
CHECK(wrap.getRef().getRef().empty());
|
||||
|
||||
args = {"--val", "happy", "sad"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
CHECK_THROWS_AS(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, wrapperComplex) {
|
||||
TEST_CASE_METHOD(TApp, "wrapperComplex", "[newparse]") {
|
||||
SimpleWrapper<std::complex<double>> wrap;
|
||||
app.add_option("--val", wrap);
|
||||
args = {"--val", "1", "2"};
|
||||
@ -608,26 +608,26 @@ TEST_F(TApp, wrapperComplex) {
|
||||
run();
|
||||
auto &v1 = wrap.getRef();
|
||||
auto v2 = std::complex<double>{1, 2};
|
||||
EXPECT_EQ(v1.real(), v2.real());
|
||||
EXPECT_EQ(v1.imag(), v2.imag());
|
||||
CHECK(v2.real() == v1.real());
|
||||
CHECK(v2.imag() == v1.imag());
|
||||
args = {"--val", "1.4-4j"};
|
||||
|
||||
run();
|
||||
v2 = std::complex<double>{1.4, -4};
|
||||
EXPECT_EQ(v1.real(), v2.real());
|
||||
EXPECT_EQ(v1.imag(), v2.imag());
|
||||
CHECK(v2.real() == v1.real());
|
||||
CHECK(v2.imag() == v1.imag());
|
||||
}
|
||||
|
||||
TEST_F(TApp, vectorComplex) {
|
||||
TEST_CASE_METHOD(TApp, "vectorComplex", "[newparse]") {
|
||||
std::vector<std::complex<double>> vcomplex;
|
||||
app.add_option("--val", vcomplex);
|
||||
args = {"--val", "1", "2", "--val", "1.4-4j"};
|
||||
|
||||
run();
|
||||
|
||||
ASSERT_EQ(vcomplex.size(), 2U);
|
||||
EXPECT_EQ(vcomplex[0].real(), 1.0);
|
||||
EXPECT_EQ(vcomplex[0].imag(), 2.0);
|
||||
EXPECT_EQ(vcomplex[1].real(), 1.4);
|
||||
EXPECT_EQ(vcomplex[1].imag(), -4.0);
|
||||
REQUIRE(2U == vcomplex.size());
|
||||
CHECK(1.0 == vcomplex[0].real());
|
||||
CHECK(2.0 == vcomplex[0].imag());
|
||||
CHECK(1.4 == vcomplex[1].real());
|
||||
CHECK(-4.0 == vcomplex[1].imag());
|
||||
}
|
||||
|
@ -6,15 +6,11 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::Not;
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using vs_t = std::vector<std::string>;
|
||||
|
||||
TEST_F(TApp, BasicOptionGroup) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroup", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res;
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -23,11 +19,11 @@ TEST_F(TApp, BasicOptionGroup) {
|
||||
|
||||
args = {"--test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
EXPECT_EQ(app.count_all(), 1u);
|
||||
CHECK(5 == res);
|
||||
CHECK(1u == app.count_all());
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupExact) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupExact", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -38,20 +34,20 @@ TEST_F(TApp, BasicOptionGroupExact) {
|
||||
ogroup->require_option(1);
|
||||
args = {"--test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
CHECK(5 == res);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[Exactly 1");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupExactTooMany) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupExactTooMany", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -61,10 +57,10 @@ TEST_F(TApp, BasicOptionGroupExactTooMany) {
|
||||
app.add_option("--option", val2);
|
||||
ogroup->require_option(10);
|
||||
args = {"--test1", "5"};
|
||||
EXPECT_THROW(run(), CLI::InvalidError);
|
||||
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMinMax) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMax", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -75,20 +71,20 @@ TEST_F(TApp, BasicOptionGroupMinMax) {
|
||||
ogroup->require_option(1, 1);
|
||||
args = {"--test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
CHECK(5 == res);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[Exactly 1");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferent", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -99,24 +95,24 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
|
||||
ogroup->require_option(1, 2);
|
||||
args = {"--test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
CHECK(5 == res);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4"};
|
||||
EXPECT_NO_THROW(run());
|
||||
EXPECT_EQ(app.count_all(), 2u);
|
||||
CHECK_NOTHROW(run());
|
||||
CHECK(2u == app.count_all());
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[Between 1 and 2");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMaxDifferentReversed", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -125,30 +121,30 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
|
||||
int val2{0};
|
||||
app.add_option("--option", val2);
|
||||
ogroup->require_option(2, 1);
|
||||
EXPECT_EQ(ogroup->get_require_option_min(), 2u);
|
||||
EXPECT_EQ(ogroup->get_require_option_max(), 1u);
|
||||
CHECK(2u == ogroup->get_require_option_min());
|
||||
CHECK(1u == ogroup->get_require_option_max());
|
||||
args = {"--test1", "5"};
|
||||
EXPECT_THROW(run(), CLI::InvalidError);
|
||||
CHECK_THROWS_AS(run(), CLI::InvalidError);
|
||||
ogroup->require_option(1, 2);
|
||||
EXPECT_NO_THROW(run());
|
||||
EXPECT_EQ(res, 5);
|
||||
EXPECT_EQ(ogroup->get_require_option_min(), 1u);
|
||||
EXPECT_EQ(ogroup->get_require_option_max(), 2u);
|
||||
CHECK_NOTHROW(run());
|
||||
CHECK(5 == res);
|
||||
CHECK(1u == ogroup->get_require_option_min());
|
||||
CHECK(2u == ogroup->get_require_option_max());
|
||||
args = {"--test1", "5", "--test2", "4"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[Between 1 and 2");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMax) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMax", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -159,20 +155,20 @@ TEST_F(TApp, BasicOptionGroupMax) {
|
||||
ogroup->require_option(-2);
|
||||
args = {"--test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
CHECK(5 == res);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[At most 2");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMax1) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMax1", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -183,20 +179,20 @@ TEST_F(TApp, BasicOptionGroupMax1) {
|
||||
ogroup->require_option(-1);
|
||||
args = {"--test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
CHECK(5 == res);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
args = {"--test1", "5", "--test2", "4"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[At most 1");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMin) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMin", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -207,17 +203,17 @@ TEST_F(TApp, BasicOptionGroupMin) {
|
||||
ogroup->require_option();
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[At least 1");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupExact2) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupExact2", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -228,20 +224,20 @@ TEST_F(TApp, BasicOptionGroupExact2) {
|
||||
ogroup->require_option(2);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test3=5"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[Exactly 2");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMin2) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMin2", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
ogroup->add_option("--test1", res);
|
||||
@ -252,17 +248,17 @@ TEST_F(TApp, BasicOptionGroupMin2) {
|
||||
ogroup->require_option(2, 0);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
std::string help = ogroup->help();
|
||||
auto exactloc = help.find("[At least 2");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMinMoved) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMoved", "[optiongroup]") {
|
||||
|
||||
int res{0};
|
||||
auto opt1 = app.add_option("--test1", res);
|
||||
@ -278,20 +274,20 @@ TEST_F(TApp, BasicOptionGroupMinMoved) {
|
||||
ogroup->add_option(opt3);
|
||||
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
std::string help = app.help();
|
||||
auto exactloc = help.find("[At least 1");
|
||||
auto oloc = help.find("--test1");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
EXPECT_NE(oloc, std::string::npos);
|
||||
EXPECT_LT(exactloc, oloc);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
CHECK(std::string::npos != oloc);
|
||||
CHECK(oloc > exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupMinMovedAsGroup", "[optiongroup]") {
|
||||
|
||||
int res{0};
|
||||
auto opt1 = app.add_option("--test1", res);
|
||||
@ -304,22 +300,22 @@ TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
|
||||
ogroup->require_option();
|
||||
ogroup->add_options(opt1, opt2, opt3);
|
||||
|
||||
EXPECT_THROW(ogroup->add_options(opt1), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->add_options(opt1), CLI::OptionNotFound);
|
||||
args = {"--option", "9"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--test1", "5", "--test2", "4", "--test3=5"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
std::string help = app.help();
|
||||
auto exactloc = help.find("[At least 1");
|
||||
auto oloc = help.find("--test1");
|
||||
EXPECT_NE(exactloc, std::string::npos);
|
||||
EXPECT_NE(oloc, std::string::npos);
|
||||
EXPECT_LT(exactloc, oloc);
|
||||
CHECK(std::string::npos != exactloc);
|
||||
CHECK(std::string::npos != oloc);
|
||||
CHECK(oloc > exactloc);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupAddFailures) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupAddFailures", "[optiongroup]") {
|
||||
|
||||
int res{0};
|
||||
auto opt1 = app.add_option("--test1", res);
|
||||
@ -328,24 +324,24 @@ TEST_F(TApp, BasicOptionGroupAddFailures) {
|
||||
app.add_option("--option", val2);
|
||||
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
EXPECT_THROW(ogroup->add_options(app.get_config_ptr()), CLI::OptionAlreadyAdded);
|
||||
EXPECT_THROW(ogroup->add_options(app.get_help_ptr()), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(ogroup->add_options(app.get_config_ptr()), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(ogroup->add_options(app.get_help_ptr()), CLI::OptionAlreadyAdded);
|
||||
|
||||
auto sub = app.add_subcommand("sub", "subcommand");
|
||||
auto opt2 = sub->add_option("--option2", val2);
|
||||
|
||||
EXPECT_THROW(ogroup->add_option(opt2), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->add_option(opt2), CLI::OptionNotFound);
|
||||
|
||||
EXPECT_THROW(ogroup->add_options(nullptr), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->add_options(nullptr), CLI::OptionNotFound);
|
||||
|
||||
ogroup->add_option(opt1);
|
||||
|
||||
auto opt3 = app.add_option("--test1", res);
|
||||
|
||||
EXPECT_THROW(ogroup->add_option(opt3), CLI::OptionAlreadyAdded);
|
||||
CHECK_THROWS_AS(ogroup->add_option(opt3), CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BasicOptionGroupScrewedUpMove) {
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroupScrewedUpMove", "[optiongroup]") {
|
||||
|
||||
int res{0};
|
||||
auto opt1 = app.add_option("--test1", res);
|
||||
@ -356,25 +352,25 @@ TEST_F(TApp, BasicOptionGroupScrewedUpMove) {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
ogroup->require_option();
|
||||
auto ogroup2 = ogroup->add_option_group("clusters2");
|
||||
EXPECT_THROW(ogroup2->add_options(opt1, opt2), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup2->add_options(opt1, opt2), CLI::OptionNotFound);
|
||||
|
||||
CLI::Option_group EmptyGroup("description", "new group", nullptr);
|
||||
|
||||
EXPECT_THROW(EmptyGroup.add_option(opt2), CLI::OptionNotFound);
|
||||
EXPECT_THROW(app._move_option(opt2, ogroup2), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(EmptyGroup.add_option(opt2), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(app._move_option(opt2, ogroup2), CLI::OptionNotFound);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InvalidOptions) {
|
||||
TEST_CASE_METHOD(TApp, "InvalidOptions", "[optiongroup]") {
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
CLI::Option *opt = nullptr;
|
||||
EXPECT_THROW(ogroup->excludes(opt), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->excludes(opt), CLI::OptionNotFound);
|
||||
CLI::App *app_p = nullptr;
|
||||
EXPECT_THROW(ogroup->excludes(app_p), CLI::OptionNotFound);
|
||||
EXPECT_THROW(ogroup->excludes(ogroup), CLI::OptionNotFound);
|
||||
EXPECT_THROW(ogroup->add_option(opt), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->excludes(app_p), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->excludes(ogroup), CLI::OptionNotFound);
|
||||
CHECK_THROWS_AS(ogroup->add_option(opt), CLI::OptionNotFound);
|
||||
}
|
||||
|
||||
TEST_F(TApp, OptionGroupInheritedOptionDefaults) {
|
||||
TEST_CASE_METHOD(TApp, "OptionGroupInheritedOptionDefaults", "[optiongroup]") {
|
||||
app.option_defaults()->ignore_case();
|
||||
auto ogroup = app.add_option_group("clusters");
|
||||
int res{0};
|
||||
@ -382,8 +378,8 @@ TEST_F(TApp, OptionGroupInheritedOptionDefaults) {
|
||||
|
||||
args = {"--Test1", "5"};
|
||||
run();
|
||||
EXPECT_EQ(res, 5);
|
||||
EXPECT_EQ(app.count_all(), 1u);
|
||||
CHECK(5 == res);
|
||||
CHECK(1u == app.count_all());
|
||||
}
|
||||
|
||||
struct ManyGroups : public TApp {
|
||||
@ -425,48 +421,48 @@ struct ManyGroups : public TApp {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ManyGroups, SingleGroup) {
|
||||
TEST_CASE_METHOD(ManyGroups, "SingleGroup", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
main->require_option(1);
|
||||
args = {"--name1", "test"};
|
||||
run();
|
||||
EXPECT_EQ(name1, "test");
|
||||
CHECK("test" == name1);
|
||||
|
||||
args = {"--name2", "test", "--val2", "tval"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(val2, "tval");
|
||||
CHECK("tval" == val2);
|
||||
|
||||
args = {"--name1", "test", "--val2", "tval"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, ExcludesGroup) {
|
||||
TEST_CASE_METHOD(ManyGroups, "ExcludesGroup", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
g1->excludes(g2);
|
||||
g1->excludes(g3);
|
||||
args = {"--name1", "test"};
|
||||
run();
|
||||
EXPECT_EQ(name1, "test");
|
||||
CHECK("test" == name1);
|
||||
|
||||
args = {"--name1", "test", "--name2", "test2"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ExcludesError);
|
||||
CHECK_THROWS_AS(run(), CLI::ExcludesError);
|
||||
|
||||
EXPECT_TRUE(g1->remove_excludes(g2));
|
||||
EXPECT_NO_THROW(run());
|
||||
EXPECT_FALSE(g1->remove_excludes(g1));
|
||||
EXPECT_FALSE(g1->remove_excludes(g2));
|
||||
CHECK(g1->remove_excludes(g2));
|
||||
CHECK_NOTHROW(run());
|
||||
CHECK(!g1->remove_excludes(g1));
|
||||
CHECK(!g1->remove_excludes(g2));
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, NeedsGroup) {
|
||||
TEST_CASE_METHOD(ManyGroups, "NeedsGroup", "[optiongroup]") {
|
||||
remove_required();
|
||||
// all groups needed if g1 is used
|
||||
g1->needs(g2);
|
||||
g1->needs(g3);
|
||||
args = {"--name1", "test"};
|
||||
EXPECT_THROW(run(), CLI::RequiresError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiresError);
|
||||
// other groups should run fine
|
||||
args = {"--name2", "test2"};
|
||||
|
||||
@ -474,11 +470,11 @@ TEST_F(ManyGroups, NeedsGroup) {
|
||||
// all three groups should be fine
|
||||
args = {"--name1", "test", "--name2", "test2", "--name3", "test3"};
|
||||
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
}
|
||||
|
||||
// test adding an option group with existing subcommands to an app
|
||||
TEST_F(TApp, ExistingSubcommandMatch) {
|
||||
TEST_CASE_METHOD(TApp, "ExistingSubcommandMatch", "[optiongroup]") {
|
||||
auto sshared = std::make_shared<CLI::Option_group>("documenting the subcommand", "sub1g", nullptr);
|
||||
auto s1 = sshared->add_subcommand("sub1");
|
||||
auto o1 = sshared->add_option_group("opt1");
|
||||
@ -489,9 +485,9 @@ TEST_F(TApp, ExistingSubcommandMatch) {
|
||||
try {
|
||||
app.add_subcommand(sshared);
|
||||
// this should throw the next line should never be reached
|
||||
EXPECT_FALSE(true);
|
||||
CHECK(!true);
|
||||
} catch(const CLI::OptionAlreadyAdded &oaa) {
|
||||
EXPECT_THAT(oaa.what(), HasSubstr("sub1"));
|
||||
CHECK_THAT(oaa.what(), Contains("sub1"));
|
||||
}
|
||||
sshared->remove_subcommand(s1);
|
||||
|
||||
@ -500,40 +496,40 @@ TEST_F(TApp, ExistingSubcommandMatch) {
|
||||
try {
|
||||
app.add_subcommand(sshared);
|
||||
// this should throw the next line should never be reached
|
||||
EXPECT_FALSE(true);
|
||||
CHECK(!true);
|
||||
} catch(const CLI::OptionAlreadyAdded &oaa) {
|
||||
EXPECT_THAT(oaa.what(), HasSubstr("sub3"));
|
||||
CHECK_THAT(oaa.what(), Contains("sub3"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, SingleGroupError) {
|
||||
TEST_CASE_METHOD(ManyGroups, "SingleGroupError", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
main->require_option(1);
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, AtMostOneGroup) {
|
||||
TEST_CASE_METHOD(ManyGroups, "AtMostOneGroup", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
main->require_option(0, 1);
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, AtLeastTwoGroups) {
|
||||
TEST_CASE_METHOD(ManyGroups, "AtLeastTwoGroups", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
main->require_option(2, 0);
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
run();
|
||||
|
||||
args = {"--name1", "test"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, BetweenOneAndTwoGroups) {
|
||||
TEST_CASE_METHOD(ManyGroups, "BetweenOneAndTwoGroups", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
main->require_option(1, 2);
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
@ -543,19 +539,19 @@ TEST_F(ManyGroups, BetweenOneAndTwoGroups) {
|
||||
run();
|
||||
|
||||
args = {};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
|
||||
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
||||
EXPECT_THROW(run(), CLI::RequiredError);
|
||||
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, RequiredFirst) {
|
||||
TEST_CASE_METHOD(ManyGroups, "RequiredFirst", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
remove_required();
|
||||
g1->required();
|
||||
|
||||
EXPECT_TRUE(g1->get_required());
|
||||
EXPECT_FALSE(g2->get_required());
|
||||
CHECK(g1->get_required());
|
||||
CHECK(!g2->get_required());
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
run();
|
||||
|
||||
@ -563,32 +559,32 @@ TEST_F(ManyGroups, RequiredFirst) {
|
||||
try {
|
||||
run();
|
||||
} catch(const CLI::RequiredError &re) {
|
||||
EXPECT_THAT(re.what(), HasSubstr("g1"));
|
||||
CHECK_THAT(re.what(), Contains("g1"));
|
||||
}
|
||||
|
||||
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, DisableFirst) {
|
||||
TEST_CASE_METHOD(ManyGroups, "DisableFirst", "[optiongroup]") {
|
||||
// only 1 group can be used if remove_required not used
|
||||
remove_required();
|
||||
g1->disabled();
|
||||
|
||||
EXPECT_TRUE(g1->get_disabled());
|
||||
EXPECT_FALSE(g2->get_disabled());
|
||||
CHECK(g1->get_disabled());
|
||||
CHECK(!g2->get_disabled());
|
||||
args = {"--name2", "test"};
|
||||
|
||||
run();
|
||||
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
g1->disabled(false);
|
||||
args = {"--name1", "test", "--name2", "test3", "--name3=test3"};
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, SameSubcommand) {
|
||||
TEST_CASE_METHOD(ManyGroups, "SameSubcommand", "[optiongroup]") {
|
||||
// only 1 group can be used if remove_required not used
|
||||
remove_required();
|
||||
auto sub1 = g1->add_subcommand("sub1")->disabled();
|
||||
@ -602,30 +598,30 @@ TEST_F(ManyGroups, SameSubcommand) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_TRUE(*sub1);
|
||||
EXPECT_TRUE(*sub2);
|
||||
EXPECT_TRUE(*sub3);
|
||||
CHECK(*sub1);
|
||||
CHECK(*sub2);
|
||||
CHECK(*sub3);
|
||||
auto subs = app.get_subcommands();
|
||||
EXPECT_EQ(subs.size(), 3u);
|
||||
EXPECT_EQ(subs[0], sub1);
|
||||
EXPECT_EQ(subs[1], sub2);
|
||||
EXPECT_EQ(subs[2], sub3);
|
||||
CHECK(3u == subs.size());
|
||||
CHECK(sub1 == subs[0]);
|
||||
CHECK(sub2 == subs[1]);
|
||||
CHECK(sub3 == subs[2]);
|
||||
|
||||
args = {"sub1", "sub1", "sub1", "sub1"};
|
||||
// for the 4th and future ones they will route to the first one
|
||||
run();
|
||||
EXPECT_EQ(sub1->count(), 2u);
|
||||
EXPECT_EQ(sub2->count(), 1u);
|
||||
EXPECT_EQ(sub3->count(), 1u);
|
||||
CHECK(2u == sub1->count());
|
||||
CHECK(1u == sub2->count());
|
||||
CHECK(1u == sub3->count());
|
||||
|
||||
// subs should remain the same since the duplicate would not be registered there
|
||||
subs = app.get_subcommands();
|
||||
EXPECT_EQ(subs.size(), 3u);
|
||||
EXPECT_EQ(subs[0], sub1);
|
||||
EXPECT_EQ(subs[1], sub2);
|
||||
EXPECT_EQ(subs[2], sub3);
|
||||
CHECK(3u == subs.size());
|
||||
CHECK(sub1 == subs[0]);
|
||||
CHECK(sub2 == subs[1]);
|
||||
CHECK(sub3 == subs[2]);
|
||||
}
|
||||
TEST_F(ManyGroups, CallbackOrder) {
|
||||
TEST_CASE_METHOD(ManyGroups, "CallbackOrder", "[optiongroup]") {
|
||||
// only 1 group can be used if remove_required not used
|
||||
remove_required();
|
||||
std::vector<int> callback_order;
|
||||
@ -635,61 +631,61 @@ TEST_F(ManyGroups, CallbackOrder) {
|
||||
|
||||
args = {"--name2", "test"};
|
||||
run();
|
||||
EXPECT_EQ(callback_order, std::vector<int>({2, 3}));
|
||||
CHECK(std::vector<int>({2, 3}) == callback_order);
|
||||
|
||||
callback_order.clear();
|
||||
args = {"--name1", "t2", "--name2", "test"};
|
||||
g2->immediate_callback();
|
||||
run();
|
||||
EXPECT_EQ(callback_order, std::vector<int>({2, 1, 3}));
|
||||
CHECK(std::vector<int>({2, 1, 3}) == callback_order);
|
||||
callback_order.clear();
|
||||
|
||||
args = {"--name2", "test", "--name1", "t2"};
|
||||
g2->immediate_callback(false);
|
||||
run();
|
||||
EXPECT_EQ(callback_order, std::vector<int>({1, 2, 3}));
|
||||
CHECK(std::vector<int>({1, 2, 3}) == callback_order);
|
||||
}
|
||||
|
||||
// Test the fallthrough for extra arguments
|
||||
TEST_F(ManyGroups, ExtrasFallDown) {
|
||||
TEST_CASE_METHOD(ManyGroups, "ExtrasFallDown", "[optiongroup]") {
|
||||
// only 1 group can be used if remove_required not used
|
||||
remove_required();
|
||||
|
||||
args = {"--test1", "--flag", "extra"};
|
||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
main->allow_extras();
|
||||
EXPECT_NO_THROW(run());
|
||||
CHECK_NOTHROW(run());
|
||||
|
||||
EXPECT_EQ(app.remaining_size(true), 3u);
|
||||
EXPECT_EQ(main->remaining_size(), 3u);
|
||||
CHECK(3u == app.remaining_size(true));
|
||||
CHECK(3u == main->remaining_size());
|
||||
|
||||
std::vector<std::string> extras{"--test1", "--flag", "extra"};
|
||||
EXPECT_EQ(app.remaining(true), extras);
|
||||
EXPECT_EQ(main->remaining(), extras);
|
||||
CHECK(extras == app.remaining(true));
|
||||
CHECK(extras == main->remaining());
|
||||
}
|
||||
|
||||
// Test the option Inheritance
|
||||
TEST_F(ManyGroups, Inheritance) {
|
||||
TEST_CASE_METHOD(ManyGroups, "Inheritance", "[optiongroup]") {
|
||||
remove_required();
|
||||
g1->ignore_case();
|
||||
g1->ignore_underscore();
|
||||
auto t2 = g1->add_subcommand("t2");
|
||||
args = {"T2", "t_2"};
|
||||
EXPECT_TRUE(t2->get_ignore_underscore());
|
||||
EXPECT_TRUE(t2->get_ignore_case());
|
||||
CHECK(t2->get_ignore_underscore());
|
||||
CHECK(t2->get_ignore_case());
|
||||
run();
|
||||
EXPECT_EQ(t2->count(), 2u);
|
||||
CHECK(2u == t2->count());
|
||||
}
|
||||
|
||||
TEST_F(ManyGroups, Moving) {
|
||||
TEST_CASE_METHOD(ManyGroups, "Moving", "[optiongroup]") {
|
||||
remove_required();
|
||||
auto mg = app.add_option_group("maing");
|
||||
mg->add_subcommand(g1);
|
||||
mg->add_subcommand(g2);
|
||||
|
||||
EXPECT_EQ(g1->get_parent(), mg);
|
||||
EXPECT_EQ(g2->get_parent(), mg);
|
||||
EXPECT_EQ(g3->get_parent(), main);
|
||||
CHECK(mg == g1->get_parent());
|
||||
CHECK(mg == g2->get_parent());
|
||||
CHECK(main == g3->get_parent());
|
||||
}
|
||||
|
||||
struct ManyGroupsPreTrigger : public ManyGroups {
|
||||
@ -704,35 +700,35 @@ struct ManyGroupsPreTrigger : public ManyGroups {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ManyGroupsPreTrigger, PreTriggerTestsOptions) {
|
||||
TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsOptions", "[optiongroup]") {
|
||||
|
||||
args = {"--name1", "test", "--name2", "test3"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 4u);
|
||||
EXPECT_EQ(trigger1, 2u);
|
||||
EXPECT_EQ(trigger2, 0u);
|
||||
EXPECT_EQ(trigger3, 27u);
|
||||
CHECK(4u == triggerMain);
|
||||
CHECK(2u == trigger1);
|
||||
CHECK(0u == trigger2);
|
||||
CHECK(27u == trigger3);
|
||||
|
||||
args = {"--name1", "test"};
|
||||
trigger2 = 34u;
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 2u);
|
||||
EXPECT_EQ(trigger1, 0u);
|
||||
EXPECT_EQ(trigger2, 34u);
|
||||
CHECK(2u == triggerMain);
|
||||
CHECK(0u == trigger1);
|
||||
CHECK(34u == trigger2);
|
||||
|
||||
args = {};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 0u);
|
||||
CHECK(0u == triggerMain);
|
||||
|
||||
args = {"--name1", "test", "--val1", "45", "--name2", "test3", "--name3=test3", "--val2=37"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 8u);
|
||||
EXPECT_EQ(trigger1, 6u);
|
||||
EXPECT_EQ(trigger2, 2u);
|
||||
EXPECT_EQ(trigger3, 1u);
|
||||
CHECK(8u == triggerMain);
|
||||
CHECK(6u == trigger1);
|
||||
CHECK(2u == trigger2);
|
||||
CHECK(1u == trigger3);
|
||||
}
|
||||
|
||||
TEST_F(ManyGroupsPreTrigger, PreTriggerTestsPositionals) {
|
||||
TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsPositionals", "[optiongroup]") {
|
||||
// only 1 group can be used
|
||||
g1->add_option("pos1");
|
||||
g2->add_option("pos2");
|
||||
@ -740,26 +736,26 @@ TEST_F(ManyGroupsPreTrigger, PreTriggerTestsPositionals) {
|
||||
|
||||
args = {"pos1"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 1u);
|
||||
EXPECT_EQ(trigger1, 0u);
|
||||
EXPECT_EQ(trigger2, 34u);
|
||||
EXPECT_EQ(trigger3, 27u);
|
||||
CHECK(1u == triggerMain);
|
||||
CHECK(0u == trigger1);
|
||||
CHECK(34u == trigger2);
|
||||
CHECK(27u == trigger3);
|
||||
|
||||
args = {"pos1", "pos2"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 2u);
|
||||
EXPECT_EQ(trigger1, 1u);
|
||||
EXPECT_EQ(trigger2, 0u);
|
||||
CHECK(2u == triggerMain);
|
||||
CHECK(1u == trigger1);
|
||||
CHECK(0u == trigger2);
|
||||
|
||||
args = {"pos1", "pos2", "pos3"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 3u);
|
||||
EXPECT_EQ(trigger1, 2u);
|
||||
EXPECT_EQ(trigger2, 1u);
|
||||
EXPECT_EQ(trigger3, 0u);
|
||||
CHECK(3u == triggerMain);
|
||||
CHECK(2u == trigger1);
|
||||
CHECK(1u == trigger2);
|
||||
CHECK(0u == trigger3);
|
||||
}
|
||||
|
||||
TEST_F(ManyGroupsPreTrigger, PreTriggerTestsSubcommand) {
|
||||
TEST_CASE_METHOD(ManyGroupsPreTrigger, "PreTriggerTestsSubcommand", "[optiongroup]") {
|
||||
|
||||
auto sub1 = g1->add_subcommand("sub1")->fallthrough();
|
||||
g2->add_subcommand("sub2")->fallthrough();
|
||||
@ -769,23 +765,23 @@ TEST_F(ManyGroupsPreTrigger, PreTriggerTestsSubcommand) {
|
||||
sub1->preparse_callback([&subtrigger](std::size_t count) { subtrigger = count; });
|
||||
args = {"sub1"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 1u);
|
||||
EXPECT_EQ(trigger1, 0u);
|
||||
EXPECT_EQ(trigger2, 34u);
|
||||
EXPECT_EQ(trigger3, 27u);
|
||||
CHECK(1u == triggerMain);
|
||||
CHECK(0u == trigger1);
|
||||
CHECK(34u == trigger2);
|
||||
CHECK(27u == trigger3);
|
||||
|
||||
args = {"sub1", "sub2"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 2u);
|
||||
EXPECT_EQ(subtrigger, 1u);
|
||||
EXPECT_EQ(trigger1, 1u);
|
||||
EXPECT_EQ(trigger2, 0u);
|
||||
CHECK(2u == triggerMain);
|
||||
CHECK(1u == subtrigger);
|
||||
CHECK(1u == trigger1);
|
||||
CHECK(0u == trigger2);
|
||||
|
||||
args = {"sub2", "sub3", "--name1=test", "sub1"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 4u);
|
||||
EXPECT_EQ(trigger1, 1u);
|
||||
EXPECT_EQ(trigger2, 3u);
|
||||
EXPECT_EQ(trigger3, 1u); // processes the first argument in group3 which includes the entire subcommand, which will
|
||||
// go until the sub1 command is given
|
||||
CHECK(4u == triggerMain);
|
||||
CHECK(1u == trigger1);
|
||||
CHECK(3u == trigger2);
|
||||
CHECK(1u == trigger3);
|
||||
// go until the sub1 command is given
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -62,70 +62,70 @@
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
TEST_F(TApp, StdOptionalTest) {
|
||||
TEST_CASE_METHOD(TApp, "StdOptionalTest", "[optional]") {
|
||||
std::optional<int> opt;
|
||||
app.add_option("-c,--count", opt);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-c", "1"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 1);
|
||||
CHECK(opt);
|
||||
CHECK(1 == *opt);
|
||||
|
||||
args = {"--count", "3"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 3);
|
||||
CHECK(opt);
|
||||
CHECK(3 == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, StdOptionalVectorEmptyDirect) {
|
||||
TEST_CASE_METHOD(TApp, "StdOptionalVectorEmptyDirect", "[optional]") {
|
||||
std::optional<std::vector<int>> opt;
|
||||
app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-v"};
|
||||
opt = std::vector<int>{4, 3};
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-v", "1", "4", "5"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::vector<int> expV{1, 4, 5};
|
||||
EXPECT_EQ(*opt, expV);
|
||||
CHECK(expV == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, StdOptionalComplexDirect) {
|
||||
TEST_CASE_METHOD(TApp, "StdOptionalComplexDirect", "[optional]") {
|
||||
std::optional<std::complex<double>> opt;
|
||||
app.add_option("-c,--complex", opt)->type_size(0, 2);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-c"};
|
||||
opt = std::complex<double>{4.0, 3.0};
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-c", "1+2j"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::complex<double> val{1, 2};
|
||||
EXPECT_EQ(*opt, val);
|
||||
CHECK(val == *opt);
|
||||
args = {"-c", "3", "-4"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::complex<double> val2{3, -4};
|
||||
EXPECT_EQ(*opt, val2);
|
||||
CHECK(val2 == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, StdOptionalUint) {
|
||||
TEST_CASE_METHOD(TApp, "StdOptionalUint", "[optional]") {
|
||||
std::optional<std::uint64_t> opt;
|
||||
app.add_option("-i,--int", opt);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-i", "15"};
|
||||
run();
|
||||
EXPECT_EQ(*opt, 15U);
|
||||
CHECK(15U == *opt);
|
||||
static_assert(CLI::detail::classify_object<std::optional<std::uint64_t>>::value ==
|
||||
CLI::detail::object_category::wrapper_value);
|
||||
}
|
||||
@ -137,97 +137,97 @@ TEST_F(TApp, StdOptionalUint) {
|
||||
#endif
|
||||
#if CLI11_EXPERIMENTAL_OPTIONAL
|
||||
|
||||
TEST_F(TApp, ExperimentalOptionalTest) {
|
||||
TEST_CASE_METHOD(TApp, "ExperimentalOptionalTest", "[optional]") {
|
||||
std::experimental::optional<int> opt;
|
||||
app.add_option("-c,--count", opt);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-c", "1"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 1);
|
||||
CHECK(opt);
|
||||
CHECK(1 == *opt);
|
||||
|
||||
args = {"--count", "3"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 3);
|
||||
CHECK(opt);
|
||||
CHECK(3 == *opt);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if CLI11_BOOST_OPTIONAL
|
||||
|
||||
TEST_F(TApp, BoostOptionalTest) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalTest", "[optional]") {
|
||||
boost::optional<int> opt;
|
||||
app.add_option("-c,--count", opt);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-c", "1"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 1);
|
||||
CHECK(opt);
|
||||
CHECK(1 == *opt);
|
||||
opt = {};
|
||||
args = {"--count", "3"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 3);
|
||||
CHECK(opt);
|
||||
CHECK(3 == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalTestZarg) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalTestZarg", "[optional]") {
|
||||
boost::optional<int> opt;
|
||||
app.add_option("-c,--count", opt)->expected(0, 1);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-c", "1"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 1);
|
||||
CHECK(opt);
|
||||
CHECK(1 == *opt);
|
||||
opt = {};
|
||||
args = {"--count"};
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalint64Test) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalint64Test", "[optional]") {
|
||||
boost::optional<std::int64_t> opt;
|
||||
app.add_option("-c,--count", opt);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-c", "1"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 1);
|
||||
CHECK(opt);
|
||||
CHECK(1 == *opt);
|
||||
opt = {};
|
||||
args = {"--count", "3"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, 3);
|
||||
CHECK(opt);
|
||||
CHECK(3 == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalStringTest) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalStringTest", "[optional]") {
|
||||
boost::optional<std::string> opt;
|
||||
app.add_option("-s,--string", opt);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-s", "strval"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, "strval");
|
||||
CHECK(opt);
|
||||
CHECK("strval" == *opt);
|
||||
opt = {};
|
||||
args = {"--string", "strv"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_EQ(*opt, "strv");
|
||||
CHECK(opt);
|
||||
CHECK("strv" == *opt);
|
||||
}
|
||||
namespace boost {
|
||||
using CLI::enums::operator<<;
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalEnumTest) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalEnumTest", "[optional]") {
|
||||
|
||||
enum class eval : char { val0 = 0, val1 = 1, val2 = 2, val3 = 3, val4 = 4 };
|
||||
boost::optional<eval> opt, opt2;
|
||||
@ -237,93 +237,89 @@ TEST_F(TApp, BoostOptionalEnumTest) {
|
||||
optptr->capture_default_str();
|
||||
|
||||
auto dstring = optptr->get_default_str();
|
||||
EXPECT_TRUE(dstring.empty());
|
||||
CHECK(dstring.empty());
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-v", "3"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_TRUE(*opt == eval::val3);
|
||||
CHECK(opt);
|
||||
CHECK(*opt == eval::val3);
|
||||
opt = {};
|
||||
args = {"--val", "1"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
EXPECT_TRUE(*opt == eval::val1);
|
||||
CHECK(opt);
|
||||
CHECK(*opt == eval::val1);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalVector) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalVector", "[optional]") {
|
||||
boost::optional<std::vector<int>> opt;
|
||||
app.add_option_function<std::vector<int>>(
|
||||
"-v,--vec", [&opt](const std::vector<int> &v) { opt = v; }, "some vector")
|
||||
->expected(3);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
|
||||
args = {"-v", "1", "4", "5"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::vector<int> expV{1, 4, 5};
|
||||
EXPECT_EQ(*opt, expV);
|
||||
CHECK(expV == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalVectorEmpty) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalVectorEmpty", "[optional]") {
|
||||
boost::optional<std::vector<int>> opt;
|
||||
app.add_option<decltype(opt), std::vector<int>>("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-v"};
|
||||
opt = std::vector<int>{4, 3};
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-v", "1", "4", "5"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::vector<int> expV{1, 4, 5};
|
||||
EXPECT_EQ(*opt, expV);
|
||||
CHECK(expV == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalVectorEmptyDirect) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalVectorEmptyDirect", "[optional]") {
|
||||
boost::optional<std::vector<int>> opt;
|
||||
app.add_option_no_stream("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||
// app.add_option("-v,--vec", opt)->expected(0, 3)->allow_extra_args();
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-v"};
|
||||
opt = std::vector<int>{4, 3};
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-v", "1", "4", "5"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::vector<int> expV{1, 4, 5};
|
||||
EXPECT_EQ(*opt, expV);
|
||||
CHECK(expV == *opt);
|
||||
}
|
||||
|
||||
TEST_F(TApp, BoostOptionalComplexDirect) {
|
||||
TEST_CASE_METHOD(TApp, "BoostOptionalComplexDirect", "[optional]") {
|
||||
boost::optional<std::complex<double>> opt;
|
||||
app.add_option("-c,--complex", opt)->type_size(0, 2);
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-c"};
|
||||
opt = std::complex<double>{4.0, 3.0};
|
||||
run();
|
||||
EXPECT_FALSE(opt);
|
||||
CHECK(!opt);
|
||||
args = {"-c", "1+2j"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::complex<double> val{1, 2};
|
||||
EXPECT_EQ(*opt, val);
|
||||
CHECK(val == *opt);
|
||||
args = {"-c", "3", "-4"};
|
||||
run();
|
||||
EXPECT_TRUE(opt);
|
||||
CHECK(opt);
|
||||
std::complex<double> val2{3, -4};
|
||||
EXPECT_EQ(*opt, val2);
|
||||
CHECK(val2 == *opt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if !CLI11_OPTIONAL
|
||||
TEST_F(TApp, DISABLED_OptionalTest) {}
|
||||
#endif
|
||||
|
@ -31,79 +31,79 @@ static_assert(CLI::detail::pair_adaptor<std::vector<std::string>>::value == fals
|
||||
static_assert(CLI::detail::pair_adaptor<std::map<int, int>>::value == true, "Should have pairs");
|
||||
static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value == true, "Should have pairs");
|
||||
|
||||
TEST_F(TApp, SimpleMaps) {
|
||||
TEST_CASE_METHOD(TApp, "SimpleMaps", "[set]") {
|
||||
int value{0};
|
||||
std::map<std::string, int> map = {{"one", 1}, {"two", 2}};
|
||||
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
||||
args = {"-s", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, 1);
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK(1 == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, StringStringMap) {
|
||||
TEST_CASE_METHOD(TApp, "StringStringMap", "[set]") {
|
||||
std::string value;
|
||||
std::map<std::string, std::string> map = {{"a", "b"}, {"b", "c"}};
|
||||
app.add_option("-s,--set", value)->transform(CLI::CheckedTransformer(map));
|
||||
args = {"-s", "a"};
|
||||
run();
|
||||
EXPECT_EQ(value, "b");
|
||||
CHECK("b" == value);
|
||||
|
||||
args = {"-s", "b"};
|
||||
run();
|
||||
EXPECT_EQ(value, "c");
|
||||
CHECK("c" == value);
|
||||
|
||||
args = {"-s", "c"};
|
||||
EXPECT_EQ(value, "c");
|
||||
CHECK("c" == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, StringStringMapNoModify) {
|
||||
TEST_CASE_METHOD(TApp, "StringStringMapNoModify", "[set]") {
|
||||
std::string value;
|
||||
std::map<std::string, std::string> map = {{"a", "b"}, {"b", "c"}};
|
||||
app.add_option("-s,--set", value)->check(CLI::IsMember(map));
|
||||
args = {"-s", "a"};
|
||||
run();
|
||||
EXPECT_EQ(value, "a");
|
||||
CHECK("a" == value);
|
||||
|
||||
args = {"-s", "b"};
|
||||
run();
|
||||
EXPECT_EQ(value, "b");
|
||||
CHECK("b" == value);
|
||||
|
||||
args = {"-s", "c"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
enum SimpleEnum { SE_one = 1, SE_two = 2 };
|
||||
|
||||
TEST_F(TApp, EnumMap) {
|
||||
TEST_CASE_METHOD(TApp, "EnumMap", "[set]") {
|
||||
SimpleEnum value;
|
||||
std::map<std::string, SimpleEnum> map = {{"one", SE_one}, {"two", SE_two}};
|
||||
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
||||
args = {"-s", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, SE_one);
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK(SE_one == value);
|
||||
}
|
||||
|
||||
enum class SimpleEnumC { one = 1, two = 2 };
|
||||
|
||||
TEST_F(TApp, EnumCMap) {
|
||||
TEST_CASE_METHOD(TApp, "EnumCMap", "[set]") {
|
||||
SimpleEnumC value;
|
||||
std::map<std::string, SimpleEnumC> map = {{"one", SimpleEnumC::one}, {"two", SimpleEnumC::two}};
|
||||
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
|
||||
args = {"-s", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, SimpleEnumC::one);
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK(SimpleEnumC::one == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, structMap) {
|
||||
TEST_CASE_METHOD(TApp, "structMap", "[set]") {
|
||||
struct tstruct {
|
||||
int val2;
|
||||
double val3;
|
||||
@ -114,16 +114,16 @@ TEST_F(TApp, structMap) {
|
||||
auto opt = app.add_option("-s,--set", struct_name)->check(CLI::IsMember(map));
|
||||
args = {"-s", "sone"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(struct_name, "sone");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("sone" == struct_name);
|
||||
|
||||
args = {"-s", "sthree"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, structMapChange) {
|
||||
TEST_CASE_METHOD(TApp, "structMapChange", "[set]") {
|
||||
struct tstruct {
|
||||
int val2;
|
||||
double val3;
|
||||
@ -135,23 +135,23 @@ TEST_F(TApp, structMapChange) {
|
||||
->transform(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space));
|
||||
args = {"-s", "s one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(struct_name, "sone");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("sone" == struct_name);
|
||||
|
||||
args = {"-s", "sthree"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"-s", "S_t_w_o"};
|
||||
run();
|
||||
EXPECT_EQ(struct_name, "stwo");
|
||||
CHECK("stwo" == struct_name);
|
||||
args = {"-s", "S two"};
|
||||
run();
|
||||
EXPECT_EQ(struct_name, "stwo");
|
||||
CHECK("stwo" == struct_name);
|
||||
}
|
||||
|
||||
TEST_F(TApp, structMapNoChange) {
|
||||
TEST_CASE_METHOD(TApp, "structMapNoChange", "[set]") {
|
||||
struct tstruct {
|
||||
int val2;
|
||||
double val3;
|
||||
@ -163,24 +163,24 @@ TEST_F(TApp, structMapNoChange) {
|
||||
->check(CLI::IsMember(map, CLI::ignore_case, CLI::ignore_underscore, CLI::ignore_space));
|
||||
args = {"-s", "SONE"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(struct_name, "SONE");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("SONE" == struct_name);
|
||||
|
||||
args = {"-s", "sthree"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"-s", "S_t_w_o"};
|
||||
run();
|
||||
EXPECT_EQ(struct_name, "S_t_w_o");
|
||||
CHECK("S_t_w_o" == struct_name);
|
||||
|
||||
args = {"-s", "S two"};
|
||||
run();
|
||||
EXPECT_EQ(struct_name, "S two");
|
||||
CHECK("S two" == struct_name);
|
||||
}
|
||||
|
||||
TEST_F(TApp, NonCopyableMap) {
|
||||
TEST_CASE_METHOD(TApp, "NonCopyableMap", "[set]") {
|
||||
|
||||
std::string map_name;
|
||||
std::map<std::string, std::unique_ptr<double>> map;
|
||||
@ -189,16 +189,16 @@ TEST_F(TApp, NonCopyableMap) {
|
||||
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map));
|
||||
args = {"-s", "e1"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(map_name, "e1");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("e1" == map_name);
|
||||
|
||||
args = {"-s", "e45"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, NonCopyableMapWithFunction) {
|
||||
TEST_CASE_METHOD(TApp, "NonCopyableMapWithFunction", "[set]") {
|
||||
|
||||
std::string map_name;
|
||||
std::map<std::string, std::unique_ptr<double>> map;
|
||||
@ -207,16 +207,16 @@ TEST_F(TApp, NonCopyableMapWithFunction) {
|
||||
auto opt = app.add_option("-s,--set", map_name)->transform(CLI::IsMember(&map, CLI::ignore_underscore));
|
||||
args = {"-s", "e_1"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(map_name, "e1");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("e1" == map_name);
|
||||
|
||||
args = {"-s", "e45"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, NonCopyableMapNonStringMap) {
|
||||
TEST_CASE_METHOD(TApp, "NonCopyableMapNonStringMap", "[set]") {
|
||||
|
||||
std::string map_name;
|
||||
std::map<int, std::unique_ptr<double>> map;
|
||||
@ -225,16 +225,16 @@ TEST_F(TApp, NonCopyableMapNonStringMap) {
|
||||
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(&map));
|
||||
args = {"-s", "4"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(map_name, "4");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("4" == map_name);
|
||||
|
||||
args = {"-s", "e45"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, CopyableMapMove) {
|
||||
TEST_CASE_METHOD(TApp, "CopyableMapMove", "[set]") {
|
||||
|
||||
std::string map_name;
|
||||
std::map<int, double> map;
|
||||
@ -243,162 +243,162 @@ TEST_F(TApp, CopyableMapMove) {
|
||||
auto opt = app.add_option("-s,--set", map_name)->check(CLI::IsMember(std::move(map)));
|
||||
args = {"-s", "4"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(map_name, "4");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("4" == map_name);
|
||||
|
||||
args = {"-s", "e45"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SimpleSets) {
|
||||
TEST_CASE_METHOD(TApp, "SimpleSets", "[set]") {
|
||||
std::string value;
|
||||
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<std::string>({"one", "two", "three"})});
|
||||
args = {"-s", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, "one");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("one" == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SimpleSetsPtrs) {
|
||||
TEST_CASE_METHOD(TApp, "SimpleSetsPtrs", "[set]") {
|
||||
auto set = std::shared_ptr<std::set<std::string>>(new std::set<std::string>{"one", "two", "three"});
|
||||
std::string value;
|
||||
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{set});
|
||||
args = {"-s", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, "one");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("one" == value);
|
||||
|
||||
set->insert("four");
|
||||
|
||||
args = {"-s", "four"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, "four");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("four" == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SimiShortcutSets) {
|
||||
TEST_CASE_METHOD(TApp, "SimiShortcutSets", "[set]") {
|
||||
std::string value;
|
||||
auto opt = app.add_option("--set", value)->check(CLI::IsMember({"one", "two", "three"}));
|
||||
args = {"--set", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, "one");
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("one" == value);
|
||||
|
||||
std::string value2;
|
||||
auto opt2 = app.add_option("--set2", value2)->transform(CLI::IsMember({"One", "two", "three"}, CLI::ignore_case));
|
||||
args = {"--set2", "onE"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set2"));
|
||||
EXPECT_EQ(1u, opt2->count());
|
||||
EXPECT_EQ(value2, "One");
|
||||
CHECK(app.count("--set2") == 1u);
|
||||
CHECK(opt2->count() == 1u);
|
||||
CHECK("One" == value2);
|
||||
|
||||
std::string value3;
|
||||
auto opt3 = app.add_option("--set3", value3)
|
||||
->transform(CLI::IsMember({"O_ne", "two", "three"}, CLI::ignore_case, CLI::ignore_underscore));
|
||||
args = {"--set3", "onE"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set3"));
|
||||
EXPECT_EQ(1u, opt3->count());
|
||||
EXPECT_EQ(value3, "O_ne");
|
||||
CHECK(app.count("--set3") == 1u);
|
||||
CHECK(opt3->count() == 1u);
|
||||
CHECK("O_ne" == value3);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SetFromCharStarArrayVector) {
|
||||
TEST_CASE_METHOD(TApp, "SetFromCharStarArrayVector", "[set]") {
|
||||
constexpr const char *names[3]{"one", "two", "three"};
|
||||
std::string value;
|
||||
auto opt = app.add_option("-s,--set", value)
|
||||
->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))});
|
||||
args = {"-s", "one"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, "one");
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK("one" == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, OtherTypeSets) {
|
||||
TEST_CASE_METHOD(TApp, "OtherTypeSets", "[set]") {
|
||||
int value{0};
|
||||
std::vector<int> set = {2, 3, 4};
|
||||
auto opt = app.add_option("--set", value)->check(CLI::IsMember(set));
|
||||
args = {"--set", "3"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, 3);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK(3 == value);
|
||||
|
||||
args = {"--set", "5"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
std::vector<int> set2 = {-2, 3, 4};
|
||||
auto opt2 = app.add_option("--set2", value)->transform(CLI::IsMember(set2, [](int x) { return std::abs(x); }));
|
||||
args = {"--set2", "-3"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set2"));
|
||||
EXPECT_EQ(1u, opt2->count());
|
||||
EXPECT_EQ(value, 3);
|
||||
CHECK(app.count("--set2") == 1u);
|
||||
CHECK(opt2->count() == 1u);
|
||||
CHECK(3 == value);
|
||||
|
||||
args = {"--set2", "-3"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set2"));
|
||||
EXPECT_EQ(1u, opt2->count());
|
||||
EXPECT_EQ(value, 3);
|
||||
CHECK(app.count("--set2") == 1u);
|
||||
CHECK(opt2->count() == 1u);
|
||||
CHECK(3 == value);
|
||||
|
||||
args = {"--set2", "2"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--set2"));
|
||||
EXPECT_EQ(1u, opt2->count());
|
||||
EXPECT_EQ(value, -2);
|
||||
CHECK(app.count("--set2") == 1u);
|
||||
CHECK(opt2->count() == 1u);
|
||||
CHECK(-2 == value);
|
||||
}
|
||||
|
||||
TEST_F(TApp, NumericalSets) {
|
||||
TEST_CASE_METHOD(TApp, "NumericalSets", "[set]") {
|
||||
int value{0};
|
||||
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})});
|
||||
args = {"-s", "1"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-s"));
|
||||
EXPECT_EQ(1u, app.count("--set"));
|
||||
EXPECT_EQ(1u, opt->count());
|
||||
EXPECT_EQ(value, 1);
|
||||
CHECK(app.count("-s") == 1u);
|
||||
CHECK(app.count("--set") == 1u);
|
||||
CHECK(opt->count() == 1u);
|
||||
CHECK(1 == value);
|
||||
}
|
||||
|
||||
// Converted original set tests
|
||||
|
||||
TEST_F(TApp, SetWithDefaults) {
|
||||
TEST_CASE_METHOD(TApp, "SetWithDefaults", "[set]") {
|
||||
int someint{2};
|
||||
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
|
||||
|
||||
args = {"-a1", "-a2"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SetWithDefaultsConversion) {
|
||||
TEST_CASE_METHOD(TApp, "SetWithDefaultsConversion", "[set]") {
|
||||
int someint{2};
|
||||
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
|
||||
|
||||
args = {"-a", "hi"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, SetWithDefaultsIC) {
|
||||
TEST_CASE_METHOD(TApp, "SetWithDefaultsIC", "[set]") {
|
||||
std::string someint = "ho";
|
||||
app.add_option("-a", someint, "", true)->check(CLI::IsMember({"Hi", "Ho"}));
|
||||
|
||||
args = {"-aHi", "-aHo"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSet) {
|
||||
TEST_CASE_METHOD(TApp, "InSet", "[set]") {
|
||||
|
||||
std::string choice;
|
||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({"one", "two", "three"}));
|
||||
@ -406,47 +406,47 @@ TEST_F(TApp, InSet) {
|
||||
args = {"--quick", "two"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ("two", choice);
|
||||
CHECK(choice == "two");
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetWithDefault) {
|
||||
TEST_CASE_METHOD(TApp, "InSetWithDefault", "[set]") {
|
||||
|
||||
std::string choice = "one";
|
||||
app.add_option("-q,--quick", choice, "", true)->check(CLI::IsMember({"one", "two", "three"}));
|
||||
|
||||
run();
|
||||
EXPECT_EQ("one", choice);
|
||||
CHECK(choice == "one");
|
||||
|
||||
args = {"--quick", "two"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ("two", choice);
|
||||
CHECK(choice == "two");
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InCaselessSetWithDefault) {
|
||||
TEST_CASE_METHOD(TApp, "InCaselessSetWithDefault", "[set]") {
|
||||
|
||||
std::string choice = "one";
|
||||
app.add_option("-q,--quick", choice, "", true)->transform(CLI::IsMember({"one", "two", "three"}, CLI::ignore_case));
|
||||
|
||||
run();
|
||||
EXPECT_EQ("one", choice);
|
||||
CHECK(choice == "one");
|
||||
|
||||
args = {"--quick", "tWo"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ("two", choice);
|
||||
CHECK(choice == "two");
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InIntSet) {
|
||||
TEST_CASE_METHOD(TApp, "InIntSet", "[set]") {
|
||||
|
||||
int choice{0};
|
||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
||||
@ -454,13 +454,13 @@ TEST_F(TApp, InIntSet) {
|
||||
args = {"--quick", "2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(2, choice);
|
||||
CHECK(choice == 2);
|
||||
|
||||
args = {"--quick", "4"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InIntSetWindows) {
|
||||
TEST_CASE_METHOD(TApp, "InIntSetWindows", "[set]") {
|
||||
|
||||
int choice{0};
|
||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
||||
@ -468,28 +468,28 @@ TEST_F(TApp, InIntSetWindows) {
|
||||
args = {"/q", "2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(2, choice);
|
||||
CHECK(choice == 2);
|
||||
|
||||
args = {"/q", "4"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"/q4"};
|
||||
EXPECT_THROW(run(), CLI::ExtrasError);
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, FailSet) {
|
||||
TEST_CASE_METHOD(TApp, "FailSet", "[set]") {
|
||||
|
||||
int choice{0};
|
||||
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
|
||||
|
||||
args = {"--quick", "3", "--quick=2"};
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
|
||||
args = {"--quick=hello"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, FailMutableSet) {
|
||||
TEST_CASE_METHOD(TApp, "FailMutableSet", "[set]") {
|
||||
|
||||
int choice{0};
|
||||
auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3}));
|
||||
@ -497,37 +497,37 @@ TEST_F(TApp, FailMutableSet) {
|
||||
app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals));
|
||||
|
||||
args = {"--quick=hello"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--slow=hello"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetIgnoreCase) {
|
||||
TEST_CASE_METHOD(TApp, "InSetIgnoreCase", "[set]") {
|
||||
|
||||
std::string choice;
|
||||
app.add_option("-q,--quick", choice)->transform(CLI::IsMember({"one", "Two", "THREE"}, CLI::ignore_case));
|
||||
|
||||
args = {"--quick", "One"};
|
||||
run();
|
||||
EXPECT_EQ("one", choice);
|
||||
CHECK(choice == "one");
|
||||
|
||||
args = {"--quick", "two"};
|
||||
run();
|
||||
EXPECT_EQ("Two", choice); // Keeps caps from set
|
||||
CHECK(choice == "Two");
|
||||
|
||||
args = {"--quick", "ThrEE"};
|
||||
run();
|
||||
EXPECT_EQ("THREE", choice); // Keeps caps from set
|
||||
CHECK(choice == "THREE");
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--quick=one", "--quick=two"};
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetIgnoreCaseMutableValue) {
|
||||
TEST_CASE_METHOD(TApp, "InSetIgnoreCaseMutableValue", "[set]") {
|
||||
|
||||
std::set<std::string> options{"one", "Two", "THREE"};
|
||||
std::string choice;
|
||||
@ -535,22 +535,22 @@ TEST_F(TApp, InSetIgnoreCaseMutableValue) {
|
||||
|
||||
args = {"--quick", "One"};
|
||||
run();
|
||||
EXPECT_EQ("one", choice);
|
||||
CHECK(choice == "one");
|
||||
|
||||
args = {"--quick", "two"};
|
||||
run();
|
||||
EXPECT_EQ("Two", choice); // Keeps caps from set
|
||||
CHECK(choice == "Two");
|
||||
|
||||
args = {"--quick", "ThrEE"};
|
||||
run();
|
||||
EXPECT_EQ("THREE", choice); // Keeps caps from set
|
||||
CHECK(choice == "THREE");
|
||||
|
||||
options.clear();
|
||||
args = {"--quick", "ThrEE"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetIgnoreCasePointer) {
|
||||
TEST_CASE_METHOD(TApp, "InSetIgnoreCasePointer", "[set]") {
|
||||
|
||||
std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"};
|
||||
std::string choice;
|
||||
@ -558,43 +558,43 @@ TEST_F(TApp, InSetIgnoreCasePointer) {
|
||||
|
||||
args = {"--quick", "One"};
|
||||
run();
|
||||
EXPECT_EQ("one", choice);
|
||||
CHECK(choice == "one");
|
||||
|
||||
args = {"--quick", "two"};
|
||||
run();
|
||||
EXPECT_EQ("Two", choice); // Keeps caps from set
|
||||
CHECK(choice == "Two");
|
||||
|
||||
args = {"--quick", "ThrEE"};
|
||||
run();
|
||||
EXPECT_EQ("THREE", choice); // Keeps caps from set
|
||||
CHECK(choice == "THREE");
|
||||
|
||||
delete options;
|
||||
args = {"--quick", "ThrEE"};
|
||||
run();
|
||||
EXPECT_EQ("THREE", choice); // this does not throw a segfault
|
||||
CHECK(choice == "THREE");
|
||||
|
||||
args = {"--quick", "four"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--quick=one", "--quick=two"};
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, NotInSetIgnoreCasePointer) {
|
||||
TEST_CASE_METHOD(TApp, "NotInSetIgnoreCasePointer", "[set]") {
|
||||
|
||||
std::set<std::string> *options = new std::set<std::string>{"one", "Two", "THREE"};
|
||||
std::string choice;
|
||||
app.add_option("-q,--quick", choice)->check(!CLI::IsMember(*options, CLI::ignore_case));
|
||||
|
||||
args = {"--quick", "One"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--quick", "four"};
|
||||
run();
|
||||
EXPECT_EQ(choice, "four");
|
||||
CHECK("four" == choice);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetIgnoreUnderscore) {
|
||||
TEST_CASE_METHOD(TApp, "InSetIgnoreUnderscore", "[set]") {
|
||||
|
||||
std::string choice;
|
||||
app.add_option("-q,--quick", choice)
|
||||
@ -602,24 +602,24 @@ TEST_F(TApp, InSetIgnoreUnderscore) {
|
||||
|
||||
args = {"--quick", "option_one"};
|
||||
run();
|
||||
EXPECT_EQ("option_one", choice);
|
||||
CHECK(choice == "option_one");
|
||||
|
||||
args = {"--quick", "optiontwo"};
|
||||
run();
|
||||
EXPECT_EQ("option_two", choice); // Keeps underscore from set
|
||||
CHECK(choice == "option_two");
|
||||
|
||||
args = {"--quick", "_option_thr_ee"};
|
||||
run();
|
||||
EXPECT_EQ("optionthree", choice); // no underscore
|
||||
CHECK(choice == "optionthree");
|
||||
|
||||
args = {"--quick", "Option4"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--quick=option_one", "--quick=option_two"};
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
TEST_F(TApp, InSetIgnoreCaseUnderscore) {
|
||||
TEST_CASE_METHOD(TApp, "InSetIgnoreCaseUnderscore", "[set]") {
|
||||
|
||||
std::string choice;
|
||||
app.add_option("-q,--quick", choice)
|
||||
@ -628,25 +628,25 @@ TEST_F(TApp, InSetIgnoreCaseUnderscore) {
|
||||
|
||||
args = {"--quick", "option_one"};
|
||||
run();
|
||||
EXPECT_EQ("Option_One", choice);
|
||||
CHECK(choice == "Option_One");
|
||||
|
||||
args = {"--quick", "OptionTwo"};
|
||||
run();
|
||||
EXPECT_EQ("option_two", choice); // Keeps underscore and case from set
|
||||
CHECK(choice == "option_two");
|
||||
|
||||
args = {"--quick", "_OPTION_thr_ee"};
|
||||
run();
|
||||
EXPECT_EQ("OptionThree", choice); // no underscore
|
||||
CHECK(choice == "OptionThree");
|
||||
|
||||
args = {"--quick", "Option4"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--quick=option_one", "--quick=option_two"};
|
||||
EXPECT_THROW(run(), CLI::ArgumentMismatch);
|
||||
CHECK_THROWS_AS(run(), CLI::ArgumentMismatch);
|
||||
}
|
||||
|
||||
// #113
|
||||
TEST_F(TApp, AddRemoveSetItems) {
|
||||
TEST_CASE_METHOD(TApp, "AddRemoveSetItems", "[set]") {
|
||||
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
||||
|
||||
std::string type1, type2;
|
||||
@ -656,8 +656,8 @@ TEST_F(TApp, AddRemoveSetItems) {
|
||||
args = {"--type1", "TYPE1", "--type2", "TYPE2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(type1, "TYPE1");
|
||||
EXPECT_EQ(type2, "TYPE2");
|
||||
CHECK("TYPE1" == type1);
|
||||
CHECK("TYPE2" == type2);
|
||||
|
||||
items.insert("TYPE6");
|
||||
items.insert("TYPE7");
|
||||
@ -667,17 +667,17 @@ TEST_F(TApp, AddRemoveSetItems) {
|
||||
|
||||
args = {"--type1", "TYPE6", "--type2", "TYPE7"};
|
||||
run();
|
||||
EXPECT_EQ(type1, "TYPE6");
|
||||
EXPECT_EQ(type2, "TYPE7");
|
||||
CHECK("TYPE6" == type1);
|
||||
CHECK("TYPE7" == type2);
|
||||
|
||||
args = {"--type1", "TYPE1"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--type2", "TYPE2"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
||||
TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
||||
TEST_CASE_METHOD(TApp, "AddRemoveSetItemsNoCase", "[set]") {
|
||||
std::set<std::string> items{"TYPE1", "TYPE2", "TYPE3", "TYPE4", "TYPE5"};
|
||||
|
||||
std::string type1, type2;
|
||||
@ -687,8 +687,8 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
||||
args = {"--type1", "TYPe1", "--type2", "TyPE2"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(type1, "TYPE1");
|
||||
EXPECT_EQ(type2, "TYPE2");
|
||||
CHECK("TYPE1" == type1);
|
||||
CHECK("TYPE2" == type2);
|
||||
|
||||
items.insert("TYPE6");
|
||||
items.insert("TYPE7");
|
||||
@ -698,12 +698,12 @@ TEST_F(TApp, AddRemoveSetItemsNoCase) {
|
||||
|
||||
args = {"--type1", "TyPE6", "--type2", "tYPE7"};
|
||||
run();
|
||||
EXPECT_EQ(type1, "TYPE6");
|
||||
EXPECT_EQ(type2, "TYPE7");
|
||||
CHECK("TYPE6" == type1);
|
||||
CHECK("TYPE7" == type2);
|
||||
|
||||
args = {"--type1", "TYPe1"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
|
||||
args = {"--type2", "TYpE2"};
|
||||
EXPECT_THROW(run(), CLI::ValidationError);
|
||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
||||
}
|
||||
|
@ -10,11 +10,11 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#endif
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "catch.hpp"
|
||||
|
||||
using input_t = std::vector<std::string>;
|
||||
|
||||
TEST(Basic, Empty) {
|
||||
TEST_CASE("Basic: Empty", "[simple]") {
|
||||
|
||||
{
|
||||
CLI::App app;
|
||||
@ -24,7 +24,7 @@ TEST(Basic, Empty) {
|
||||
{
|
||||
CLI::App app;
|
||||
input_t spare = {"spare"};
|
||||
EXPECT_THROW(app.parse(spare), CLI::ExtrasError);
|
||||
CHECK_THROWS_AS(app.parse(spare), CLI::ExtrasError);
|
||||
}
|
||||
{
|
||||
CLI::App app;
|
||||
|
@ -6,11 +6,10 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
|
||||
TEST_F(TApp, ExistingExeCheck) {
|
||||
TEST_CASE_METHOD(TApp, "ExistingExeCheck", "[stringparse]") {
|
||||
|
||||
TempFile tmpexe{"existingExe.out"};
|
||||
|
||||
@ -27,12 +26,12 @@ TEST_F(TApp, ExistingExeCheck) {
|
||||
app.parse(std::string("./") + std::string(tmpexe) +
|
||||
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
||||
true);
|
||||
EXPECT_EQ(str, "this is my quoted string");
|
||||
EXPECT_EQ(str2, "qstring 2");
|
||||
EXPECT_EQ(str3, "\"quoted string\"");
|
||||
CHECK("this is my quoted string" == str);
|
||||
CHECK("qstring 2" == str2);
|
||||
CHECK("\"quoted string\"" == str3);
|
||||
}
|
||||
|
||||
TEST_F(TApp, ExistingExeCheckWithSpace) {
|
||||
TEST_CASE_METHOD(TApp, "ExistingExeCheckWithSpace", "[stringparse]") {
|
||||
|
||||
TempFile tmpexe{"Space File.out"};
|
||||
|
||||
@ -49,14 +48,14 @@ TEST_F(TApp, ExistingExeCheckWithSpace) {
|
||||
app.parse(std::string("./") + std::string(tmpexe) +
|
||||
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
||||
true);
|
||||
EXPECT_EQ(str, "this is my quoted string");
|
||||
EXPECT_EQ(str2, "qstring 2");
|
||||
EXPECT_EQ(str3, "\"quoted string\"");
|
||||
CHECK("this is my quoted string" == str);
|
||||
CHECK("qstring 2" == str2);
|
||||
CHECK("\"quoted string\"" == str3);
|
||||
|
||||
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
|
||||
CHECK(std::string("./") + std::string(tmpexe) == app.get_name());
|
||||
}
|
||||
|
||||
TEST_F(TApp, ExistingExeCheckWithLotsOfSpace) {
|
||||
TEST_CASE_METHOD(TApp, "ExistingExeCheckWithLotsOfSpace", "[stringparse]") {
|
||||
|
||||
TempFile tmpexe{"this is a weird file.exe"};
|
||||
|
||||
@ -73,9 +72,9 @@ TEST_F(TApp, ExistingExeCheckWithLotsOfSpace) {
|
||||
app.parse(std::string("./") + std::string(tmpexe) +
|
||||
" --string=\"this is my quoted string\" -t 'qstring 2' -m=`\"quoted string\"`",
|
||||
true);
|
||||
EXPECT_EQ(str, "this is my quoted string");
|
||||
EXPECT_EQ(str2, "qstring 2");
|
||||
EXPECT_EQ(str3, "\"quoted string\"");
|
||||
CHECK("this is my quoted string" == str);
|
||||
CHECK("qstring 2" == str2);
|
||||
CHECK("\"quoted string\"" == str3);
|
||||
|
||||
EXPECT_EQ(app.get_name(), std::string("./") + std::string(tmpexe));
|
||||
CHECK(std::string("./") + std::string(tmpexe) == app.get_name());
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,66 +5,66 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#include "CLI/Timer.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "catch.hpp"
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
TEST(Timer, MSTimes) {
|
||||
TEST_CASE("Timer: MSTimes", "[timer]") {
|
||||
CLI::Timer timer{"My Timer"};
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(123));
|
||||
std::string output = timer.to_string();
|
||||
std::string new_output = (timer / 1000000).to_string();
|
||||
EXPECT_THAT(output, HasSubstr("My Timer"));
|
||||
EXPECT_THAT(output, HasSubstr(" ms"));
|
||||
EXPECT_THAT(new_output, HasSubstr(" ns"));
|
||||
CHECK_THAT(output, Contains("My Timer"));
|
||||
CHECK_THAT(output, Contains(" ms"));
|
||||
CHECK_THAT(new_output, Contains(" ns"));
|
||||
}
|
||||
|
||||
/* Takes too long
|
||||
TEST(Timer, STimes) {
|
||||
TEST_CASE("Timer: STimes", "[timer]") {
|
||||
CLI::Timer timer;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::string output = timer.to_string();
|
||||
EXPECT_THAT(output, HasSubstr(" s"));
|
||||
CHECK_THAT (output, Contains(" s"));
|
||||
}
|
||||
*/
|
||||
|
||||
// Fails on Windows
|
||||
// TEST(Timer, UStimes) {
|
||||
// TEST_CASE("Timer: UStimes", "[timer]") {
|
||||
// CLI::Timer timer;
|
||||
// std::this_thread::sleep_for(std::chrono::microseconds(2));
|
||||
// std::string output = timer.to_string();
|
||||
// EXPECT_THAT(output, HasSubstr(" ms"));
|
||||
// CHECK_THAT (output, Contains(" ms"));
|
||||
//}
|
||||
|
||||
TEST(Timer, BigTimer) {
|
||||
TEST_CASE("Timer: BigTimer", "[timer]") {
|
||||
CLI::Timer timer{"My Timer", CLI::Timer::Big};
|
||||
std::string output = timer.to_string();
|
||||
EXPECT_THAT(output, HasSubstr("Time ="));
|
||||
EXPECT_THAT(output, HasSubstr("-----------"));
|
||||
CHECK_THAT(output, Contains("Time ="));
|
||||
CHECK_THAT(output, Contains("-----------"));
|
||||
}
|
||||
|
||||
TEST(Timer, AutoTimer) {
|
||||
TEST_CASE("Timer: AutoTimer", "[timer]") {
|
||||
CLI::AutoTimer timer;
|
||||
std::string output = timer.to_string();
|
||||
EXPECT_THAT(output, HasSubstr("Timer"));
|
||||
CHECK_THAT(output, Contains("Timer"));
|
||||
}
|
||||
|
||||
TEST(Timer, PrintTimer) {
|
||||
TEST_CASE("Timer: PrintTimer", "[timer]") {
|
||||
std::stringstream out;
|
||||
CLI::AutoTimer timer;
|
||||
out << timer;
|
||||
std::string output = out.str();
|
||||
EXPECT_THAT(output, HasSubstr("Timer"));
|
||||
CHECK_THAT(output, Contains("Timer"));
|
||||
}
|
||||
|
||||
TEST(Timer, TimeItTimer) {
|
||||
TEST_CASE("Timer: TimeItTimer", "[timer]") {
|
||||
CLI::Timer timer;
|
||||
std::string output = timer.time_it([]() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); }, .1);
|
||||
std::cout << output << std::endl;
|
||||
EXPECT_THAT(output, HasSubstr("ms"));
|
||||
CHECK_THAT(output, Contains("ms"));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,31 +6,24 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
/// This allows a set of strings to be run over by a test
|
||||
struct TApp_TBO : public TApp_base, testing::TestWithParam<const char *> {};
|
||||
|
||||
TEST_P(TApp_TBO, TrueBoolOption) {
|
||||
TEST_CASE_METHOD(TApp, "True Bool Option", "[bool][flag]") {
|
||||
// Strings needed here due to MSVC 2015.
|
||||
auto param = GENERATE(as<std::string>{}, "true", "on", "True", "ON");
|
||||
bool value{false}; // Not used, but set just in case
|
||||
app.add_option("-b,--bool", value);
|
||||
args = {"--bool", GetParam()};
|
||||
args = {"--bool", param};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--bool"));
|
||||
EXPECT_TRUE(value);
|
||||
CHECK(app.count("--bool") == 1u);
|
||||
CHECK(value);
|
||||
}
|
||||
|
||||
// Change to INSTANTIATE_TEST_SUITE_P in GTest master
|
||||
INSTANTIATE_TEST_SUITE_P(TrueBoolOptions_test, TApp_TBO, testing::Values("true", "on", "True", "ON"));
|
||||
TEST_CASE_METHOD(TApp, "False Bool Option", "[bool][flag]") {
|
||||
auto param = GENERATE(as<std::string>{}, "false", "off", "False", "OFF");
|
||||
|
||||
/// This allows a set of strings to be run over by a test
|
||||
struct TApp_FBO : public TApp_base, public ::testing::TestWithParam<const char *> {};
|
||||
|
||||
TEST_P(TApp_FBO, FalseBoolOptions) {
|
||||
bool value{true}; // Not used, but set just in case
|
||||
app.add_option("-b,--bool", value);
|
||||
args = {"--bool", GetParam()};
|
||||
args = {"--bool", param};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("--bool"));
|
||||
EXPECT_FALSE(value);
|
||||
CHECK(app.count("--bool") == 1u);
|
||||
CHECK_FALSE(value);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(FalseBoolOptions_test, TApp_FBO, ::testing::Values("false", "off", "False", "OFF"));
|
||||
|
@ -10,10 +10,10 @@
|
||||
// This test verifies that CLI11 still works if
|
||||
// Windows.h is included. #145
|
||||
|
||||
TEST_F(TApp, WindowsTestSimple) {
|
||||
TEST_CASE_METHOD(TApp, "WindowsTestSimple", "[windows]") {
|
||||
app.add_flag("-c,--count");
|
||||
args = {"-c"};
|
||||
run();
|
||||
EXPECT_EQ(1u, app.count("-c"));
|
||||
EXPECT_EQ(1u, app.count("--count"));
|
||||
CHECK(app.count("-c") == 1u);
|
||||
CHECK(app.count("--count") == 1u);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#endif
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "catch.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -20,11 +20,11 @@
|
||||
|
||||
using input_t = std::vector<std::string>;
|
||||
|
||||
class TApp_base {
|
||||
class TApp {
|
||||
public:
|
||||
CLI::App app{"My Test Program"};
|
||||
input_t args{};
|
||||
virtual ~TApp_base() = default;
|
||||
virtual ~TApp() = default;
|
||||
void run() {
|
||||
// It is okay to re-parse - clear is called automatically before a parse.
|
||||
input_t newargs = args;
|
||||
@ -33,8 +33,6 @@ class TApp_base {
|
||||
}
|
||||
};
|
||||
|
||||
class TApp : public TApp_base, public ::testing::Test {};
|
||||
|
||||
class TempFile {
|
||||
std::string _name{};
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
|
||||
#include "CLI/CLI.hpp"
|
||||
#include "CLI/Timer.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include "catch.hpp"
|
||||
|
||||
int do_nothing();
|
||||
|
||||
// Verifies there are no unguarded inlines
|
||||
TEST(Link, DoNothing) {
|
||||
TEST_CASE("Link: DoNothing", "[link]") {
|
||||
int a = do_nothing();
|
||||
EXPECT_EQ(7, a);
|
||||
CHECK(a == 7);
|
||||
}
|
||||
|
8
tests/main.cpp
Normal file
8
tests/main.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2017-2020, University of Cincinnati, developed by Henry Schreiner
|
||||
// under NSF AWARD 1414736 and by the respective contributors.
|
||||
// All rights reserved.
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
Loading…
Reference in New Issue
Block a user