mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Closes #53
This commit is contained in:
parent
c95835acf8
commit
f9ab33d1a6
@ -25,8 +25,6 @@ endif()
|
|||||||
# ARGPARSE executable
|
# ARGPARSE executable
|
||||||
file(GLOB ARGPARSE_TEST_SOURCES
|
file(GLOB ARGPARSE_TEST_SOURCES
|
||||||
"*.cpp"
|
"*.cpp"
|
||||||
"*.hpp"
|
|
||||||
"../include/argparse.hpp"
|
|
||||||
)
|
)
|
||||||
ADD_EXECUTABLE(ARGPARSE ${ARGPARSE_TEST_SOURCES})
|
ADD_EXECUTABLE(ARGPARSE ${ARGPARSE_TEST_SOURCES})
|
||||||
INCLUDE_DIRECTORIES("../include" ".")
|
INCLUDE_DIRECTORIES("../include" ".")
|
||||||
|
15883
test/catch.hpp
15883
test/catch.hpp
File diff suppressed because it is too large
Load Diff
5941
test/doctest.hpp
Normal file
5941
test/doctest.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,2 @@
|
|||||||
#define CATCH_CONFIG_MAIN
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
#include <iostream>
|
#include <doctest.hpp>
|
||||||
#include <argparse.hpp>
|
|
||||||
#include <test_help.hpp>
|
|
||||||
#include <test_parse_args.hpp>
|
|
||||||
#include <test_positional_arguments.hpp>
|
|
||||||
#include <test_optional_arguments.hpp>
|
|
||||||
#include <test_compound_arguments.hpp>
|
|
||||||
#include <test_actions.hpp>
|
|
||||||
#include <test_container_arguments.hpp>
|
|
||||||
#include <test_parent_parsers.hpp>
|
|
||||||
#include <test_invalid_arguments.hpp>
|
|
||||||
#include <test_negative_numbers.hpp>
|
|
||||||
#include <test_required_arguments.hpp>
|
|
||||||
#include <test_value_semantics.hpp>
|
|
||||||
#include <test_issue_37.hpp>
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
TEST_CASE("Users can use default value inside actions", "[actions]") {
|
DOCTEST_TEST_CASE("Users can use default value inside actions [actions]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input")
|
program.add_argument("input")
|
||||||
.default_value("bar")
|
.default_value("bar")
|
||||||
@ -19,7 +18,7 @@ TEST_CASE("Users can use default value inside actions", "[actions]") {
|
|||||||
REQUIRE(program.get("input") == "bar");
|
REQUIRE(program.get("input") == "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Users can add actions that return nothing", "[actions]") {
|
DOCTEST_TEST_CASE("Users can add actions that return nothing [actions]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
auto &arg = program.add_argument("button").action(
|
auto &arg = program.add_argument("button").action(
|
||||||
@ -27,12 +26,12 @@ TEST_CASE("Users can add actions that return nothing", "[actions]") {
|
|||||||
|
|
||||||
REQUIRE_FALSE(pressed);
|
REQUIRE_FALSE(pressed);
|
||||||
|
|
||||||
SECTION("action performed") {
|
DOCTEST_SUBCASE("action performed") {
|
||||||
program.parse_args({"test", "ignored"});
|
program.parse_args({"test", "ignored"});
|
||||||
REQUIRE(pressed);
|
REQUIRE(pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("action performed and nothing overrides the default value") {
|
DOCTEST_SUBCASE("action performed and nothing overrides the default value") {
|
||||||
arg.default_value(42);
|
arg.default_value(42);
|
||||||
|
|
||||||
program.parse_args({"test", "ignored"});
|
program.parse_args({"test", "ignored"});
|
||||||
@ -67,7 +66,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("Users can bind arguments to actions", "[actions]") {
|
DOCTEST_TEST_CASE("Users can bind arguments to actions [actions]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
|
|
||||||
GIVEN("an default initialized object bounded by reference") {
|
GIVEN("an default initialized object bounded by reference") {
|
||||||
@ -120,7 +119,7 @@ TEST_CASE("Users can bind arguments to actions", "[actions]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Users can use actions on remaining arguments", "[actions]") {
|
DOCTEST_TEST_CASE("Users can use actions on remaining arguments [actions]") {
|
||||||
argparse::ArgumentParser program("sum");
|
argparse::ArgumentParser program("sum");
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
@ -1,9 +1,8 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
#include <test_utility.hpp>
|
#include <test_utility.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse compound toggle arguments with implicit values", "[compound_arguments]") {
|
DOCTEST_TEST_CASE("Parse compound toggle arguments with implicit values [compound_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("-a")
|
program.add_argument("-a")
|
||||||
.default_value(false)
|
.default_value(false)
|
||||||
@ -23,7 +22,7 @@ TEST_CASE("Parse compound toggle arguments with implicit values", "[compound_arg
|
|||||||
REQUIRE(program.get<bool>("-x") == true);
|
REQUIRE(program.get<bool>("-x") == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse compound toggle arguments with implicit values and nargs", "[compound_arguments]") {
|
DOCTEST_TEST_CASE("Parse compound toggle arguments with implicit values and nargs [compound_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("-a")
|
program.add_argument("-a")
|
||||||
.default_value(false)
|
.default_value(false)
|
||||||
@ -55,7 +54,7 @@ TEST_CASE("Parse compound toggle arguments with implicit values and nargs", "[co
|
|||||||
REQUIRE(input_files[2] == "c.txt");
|
REQUIRE(input_files[2] == "c.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse compound toggle arguments with implicit values and nargs and other positional arguments", "[compound_arguments]") {
|
DOCTEST_TEST_CASE("Parse compound toggle arguments with implicit values and nargs and other positional arguments [compound_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
|
|
||||||
program.add_argument("numbers")
|
program.add_argument("numbers")
|
||||||
@ -80,7 +79,7 @@ TEST_CASE("Parse compound toggle arguments with implicit values and nargs and ot
|
|||||||
REQUIRE_THROWS(program.parse_args({ "./test.exe", "1", "-abc", "3.14", "2.718", "2", "--input_files", "a.txt", "b.txt", "c.txt", "3" }));
|
REQUIRE_THROWS(program.parse_args({ "./test.exe", "1", "-abc", "3.14", "2.718", "2", "--input_files", "a.txt", "b.txt", "c.txt", "3" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse out-of-order compound arguments", "[compound_arguments]") {
|
DOCTEST_TEST_CASE("Parse out-of-order compound arguments [compound_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
|
|
||||||
program.add_argument("-a")
|
program.add_argument("-a")
|
||||||
@ -105,7 +104,7 @@ TEST_CASE("Parse out-of-order compound arguments", "[compound_arguments]") {
|
|||||||
REQUIRE(program["-c"] == std::vector<float>{3.14f, 2.718f});
|
REQUIRE(program["-c"] == std::vector<float>{3.14f, 2.718f});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse out-of-order compound arguments. Second variation", "[compound_arguments]") {
|
DOCTEST_TEST_CASE("Parse out-of-order compound arguments. Second variation [compound_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
|
|
||||||
program.add_argument("-a")
|
program.add_argument("-a")
|
@ -1,9 +1,8 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
#include <test_utility.hpp>
|
#include <test_utility.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse vector of arguments", "[vector]") {
|
DOCTEST_TEST_CASE("Parse vector of arguments [vector]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input")
|
program.add_argument("input")
|
||||||
.nargs(2);
|
.nargs(2);
|
||||||
@ -16,7 +15,7 @@ TEST_CASE("Parse vector of arguments", "[vector]") {
|
|||||||
REQUIRE(inputs[1] == "thrust_profile.csv");
|
REQUIRE(inputs[1] == "thrust_profile.csv");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse list of arguments", "[vector]") {
|
DOCTEST_TEST_CASE("Parse list of arguments [vector]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input")
|
program.add_argument("input")
|
||||||
.nargs(2);
|
.nargs(2);
|
||||||
@ -29,7 +28,7 @@ TEST_CASE("Parse list of arguments", "[vector]") {
|
|||||||
REQUIRE(testutility::get_from_list(inputs, 1) == "thrust_profile.csv");
|
REQUIRE(testutility::get_from_list(inputs, 1) == "thrust_profile.csv");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse list of arguments with default values", "[vector]") {
|
DOCTEST_TEST_CASE("Parse list of arguments with default values [vector]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--input")
|
program.add_argument("--input")
|
||||||
.default_value(std::list<int>{1, 2, 3, 4, 5})
|
.default_value(std::list<int>{1, 2, 3, 4, 5})
|
||||||
@ -47,7 +46,7 @@ TEST_CASE("Parse list of arguments with default values", "[vector]") {
|
|||||||
REQUIRE(program["--input"] == std::list<int>{1, 2, 3, 4, 5});
|
REQUIRE(program["--input"] == std::list<int>{1, 2, 3, 4, 5});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse list of arguments and save in an object", "[vector]") {
|
DOCTEST_TEST_CASE("Parse list of arguments and save in an object [vector]") {
|
||||||
|
|
||||||
struct ConfigManager {
|
struct ConfigManager {
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Users can format help message", "[help]") {
|
DOCTEST_TEST_CASE("Users can format help message [help]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input")
|
program.add_argument("input")
|
||||||
.help("positional input");
|
.help("positional input");
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse unknown optional argument", "[compound_arguments]") {
|
DOCTEST_TEST_CASE("Parse unknown optional argument [compound_arguments]") {
|
||||||
|
|
||||||
argparse::ArgumentParser bfm("bfm");
|
argparse::ArgumentParser bfm("bfm");
|
||||||
|
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Issues with implicit values #37", "[implicit_values]") {
|
DOCTEST_TEST_CASE("Issues with implicit values #37 [implicit_values]") {
|
||||||
argparse::ArgumentParser m_bfm("test");
|
argparse::ArgumentParser m_bfm("test");
|
||||||
m_bfm.add_argument("-l", "--load")
|
m_bfm.add_argument("-l", "--load")
|
||||||
.help("load a VMM into the kernel");
|
.help("load a VMM into the kernel");
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse negative integer", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse negative integer [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
||||||
@ -17,7 +16,7 @@ TEST_CASE("Parse negative integer", "[positional_arguments]") {
|
|||||||
REQUIRE(program.get<int>("number") == -1);
|
REQUIRE(program.get<int>("number") == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse negative integers into a vector", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse negative integers into a vector [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
||||||
@ -33,7 +32,7 @@ TEST_CASE("Parse negative integers into a vector", "[positional_arguments]") {
|
|||||||
REQUIRE(program["number"] == std::vector<int>{-1, -2, 3});
|
REQUIRE(program["number"] == std::vector<int>{-1, -2, 3});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse negative float", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse negative float [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
||||||
@ -48,7 +47,7 @@ TEST_CASE("Parse negative float", "[positional_arguments]") {
|
|||||||
REQUIRE(program.get<float>("number") == -1.0);
|
REQUIRE(program.get<float>("number") == -1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse negative floats into a vector", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse negative floats into a vector [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
||||||
@ -64,7 +63,7 @@ TEST_CASE("Parse negative floats into a vector", "[positional_arguments]") {
|
|||||||
REQUIRE(program["number"] == std::vector<double>{-1.001, -2.002, 3.003});
|
REQUIRE(program["number"] == std::vector<double>{-1.001, -2.002, 3.003});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse numbers in E notation", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse numbers in E notation [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
||||||
@ -79,7 +78,7 @@ TEST_CASE("Parse numbers in E notation", "[positional_arguments]") {
|
|||||||
REQUIRE(program.get<double>("number") == -1200.0);
|
REQUIRE(program.get<double>("number") == -1200.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse numbers in E notation (capital E)", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse numbers in E notation (capital E) [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse toggle arguments with default value", "[optional_arguments]") {
|
DOCTEST_TEST_CASE("Parse toggle arguments with default value [optional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.default_value(false)
|
.default_value(false)
|
||||||
@ -13,7 +12,7 @@ TEST_CASE("Parse toggle arguments with default value", "[optional_arguments]") {
|
|||||||
REQUIRE(program["--verbose"] == false);
|
REQUIRE(program["--verbose"] == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse toggle arguments with implicit value", "[optional_arguments]") {
|
DOCTEST_TEST_CASE("Parse toggle arguments with implicit value [optional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--verbose")
|
program.add_argument("--verbose")
|
||||||
.default_value(false)
|
.default_value(false)
|
||||||
@ -25,7 +24,7 @@ TEST_CASE("Parse toggle arguments with implicit value", "[optional_arguments]")
|
|||||||
REQUIRE(program["--verbose"] != false);
|
REQUIRE(program["--verbose"] != false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse multiple toggle arguments with implicit values", "[optional_arguments]") {
|
DOCTEST_TEST_CASE("Parse multiple toggle arguments with implicit values [optional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("-a")
|
program.add_argument("-a")
|
||||||
.default_value(false)
|
.default_value(false)
|
||||||
@ -45,7 +44,7 @@ TEST_CASE("Parse multiple toggle arguments with implicit values", "[optional_arg
|
|||||||
REQUIRE(program.get<bool>("-x") == true);
|
REQUIRE(program.get<bool>("-x") == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse optional arguments of many values", "[optional_arguments]") {
|
DOCTEST_TEST_CASE("Parse optional arguments of many values [optional_arguments]") {
|
||||||
GIVEN("a program that accepts an optional argument of many values") {
|
GIVEN("a program that accepts an optional argument of many values") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("-i").remaining().action(
|
program.add_argument("-i").remaining().action(
|
||||||
@ -74,7 +73,7 @@ TEST_CASE("Parse optional arguments of many values", "[optional_arguments]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse arguments of different types", "[optional_arguments]") {
|
DOCTEST_TEST_CASE("Parse arguments of different types [optional_arguments]") {
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Add parent parsers", "[parent_parsers]") {
|
DOCTEST_TEST_CASE("Add parent parsers [parent_parsers]") {
|
||||||
argparse::ArgumentParser parent_parser("main");
|
argparse::ArgumentParser parent_parser("main");
|
||||||
parent_parser.add_argument("--verbose")
|
parent_parser.add_argument("--verbose")
|
||||||
.default_value(false)
|
.default_value(false)
|
||||||
@ -15,7 +14,7 @@ TEST_CASE("Add parent parsers", "[parent_parsers]") {
|
|||||||
REQUIRE(parent_parser["--verbose"] == false);
|
REQUIRE(parent_parser["--verbose"] == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Add parent to multiple parent parsers", "[parent_parsers]") {
|
DOCTEST_TEST_CASE("Add parent to multiple parent parsers [parent_parsers]") {
|
||||||
argparse::ArgumentParser parent_parser("main");
|
argparse::ArgumentParser parent_parser("main");
|
||||||
parent_parser.add_argument("--parent")
|
parent_parser.add_argument("--parent")
|
||||||
.default_value(0)
|
.default_value(0)
|
@ -1,15 +1,14 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse a string argument with value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a string argument with value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--config");
|
program.add_argument("--config");
|
||||||
program.parse_args({ "test", "--config", "config.yml"});
|
program.parse_args({ "test", "--config", "config.yml"});
|
||||||
REQUIRE(program.get("--config") == "config.yml");
|
REQUIRE(program.get("--config") == "config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a string argument with default value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a string argument with default value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--config")
|
program.add_argument("--config")
|
||||||
.default_value(std::string("foo.yml"));
|
.default_value(std::string("foo.yml"));
|
||||||
@ -17,7 +16,7 @@ TEST_CASE("Parse a string argument with default value", "[parse_args]") {
|
|||||||
REQUIRE(program.get("--config") == "foo.yml");
|
REQUIRE(program.get("--config") == "foo.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse an int argument with value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse an int argument with value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--count")
|
program.add_argument("--count")
|
||||||
.action([](const std::string& value) { return std::stoi(value); });
|
.action([](const std::string& value) { return std::stoi(value); });
|
||||||
@ -25,7 +24,7 @@ TEST_CASE("Parse an int argument with value", "[parse_args]") {
|
|||||||
REQUIRE(program.get<int>("--count") == 5);
|
REQUIRE(program.get<int>("--count") == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse an int argument with default value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse an int argument with default value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--count")
|
program.add_argument("--count")
|
||||||
.default_value(2)
|
.default_value(2)
|
||||||
@ -34,7 +33,7 @@ TEST_CASE("Parse an int argument with default value", "[parse_args]") {
|
|||||||
REQUIRE(program.get<int>("--count") == 2);
|
REQUIRE(program.get<int>("--count") == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a float argument with value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a float argument with value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--ratio")
|
program.add_argument("--ratio")
|
||||||
.action([](const std::string& value) { return std::stof(value); });
|
.action([](const std::string& value) { return std::stof(value); });
|
||||||
@ -42,7 +41,7 @@ TEST_CASE("Parse a float argument with value", "[parse_args]") {
|
|||||||
REQUIRE(program.get<float>("--ratio") == 5.6645f);
|
REQUIRE(program.get<float>("--ratio") == 5.6645f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a float argument with default value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a float argument with default value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--ratio")
|
program.add_argument("--ratio")
|
||||||
.default_value(3.14f)
|
.default_value(3.14f)
|
||||||
@ -51,7 +50,7 @@ TEST_CASE("Parse a float argument with default value", "[parse_args]") {
|
|||||||
REQUIRE(program.get<float>("--ratio") == 3.14f);
|
REQUIRE(program.get<float>("--ratio") == 3.14f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a double argument with value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a double argument with value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--ratio")
|
program.add_argument("--ratio")
|
||||||
.action([](const std::string& value) { return std::stod(value); });
|
.action([](const std::string& value) { return std::stod(value); });
|
||||||
@ -59,7 +58,7 @@ TEST_CASE("Parse a double argument with value", "[parse_args]") {
|
|||||||
REQUIRE(program.get<double>("--ratio") == 5.6645);
|
REQUIRE(program.get<double>("--ratio") == 5.6645);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a double argument with default value", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a double argument with default value [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--ratio")
|
program.add_argument("--ratio")
|
||||||
.default_value(3.14)
|
.default_value(3.14)
|
||||||
@ -68,7 +67,7 @@ TEST_CASE("Parse a double argument with default value", "[parse_args]") {
|
|||||||
REQUIRE(program.get<double>("--ratio") == 3.14);
|
REQUIRE(program.get<double>("--ratio") == 3.14);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a vector of integer arguments", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a vector of integer arguments [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--vector")
|
program.add_argument("--vector")
|
||||||
.nargs(5)
|
.nargs(5)
|
||||||
@ -83,7 +82,7 @@ TEST_CASE("Parse a vector of integer arguments", "[parse_args]") {
|
|||||||
REQUIRE(vector[4] == 5);
|
REQUIRE(vector[4] == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a vector of float arguments", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a vector of float arguments [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--vector")
|
program.add_argument("--vector")
|
||||||
.nargs(5)
|
.nargs(5)
|
||||||
@ -98,7 +97,7 @@ TEST_CASE("Parse a vector of float arguments", "[parse_args]") {
|
|||||||
REQUIRE(vector[4] == 5.5f);
|
REQUIRE(vector[4] == 5.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a vector of double arguments", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a vector of double arguments [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--vector")
|
program.add_argument("--vector")
|
||||||
.nargs(5)
|
.nargs(5)
|
||||||
@ -113,7 +112,7 @@ TEST_CASE("Parse a vector of double arguments", "[parse_args]") {
|
|||||||
REQUIRE(vector[4] == 5.5);
|
REQUIRE(vector[4] == 5.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a vector of string arguments", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a vector of string arguments [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--vector")
|
program.add_argument("--vector")
|
||||||
.nargs(5)
|
.nargs(5)
|
||||||
@ -128,7 +127,7 @@ TEST_CASE("Parse a vector of string arguments", "[parse_args]") {
|
|||||||
REQUIRE(vector[4] == "mno");
|
REQUIRE(vector[4] == "mno");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a vector of character arguments", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a vector of character arguments [parse_args]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--vector")
|
program.add_argument("--vector")
|
||||||
.nargs(5)
|
.nargs(5)
|
||||||
@ -143,7 +142,7 @@ TEST_CASE("Parse a vector of character arguments", "[parse_args]") {
|
|||||||
REQUIRE(vector[4] == 'e');
|
REQUIRE(vector[4] == 'e');
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse a vector of string arguments and construct objects", "[parse_args]") {
|
DOCTEST_TEST_CASE("Parse a vector of string arguments and construct objects [parse_args]") {
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
TEST_CASE("Parse positional arguments", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse positional arguments [positional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input");
|
program.add_argument("input");
|
||||||
program.add_argument("output");
|
program.add_argument("output");
|
||||||
@ -11,7 +11,7 @@ TEST_CASE("Parse positional arguments", "[positional_arguments]") {
|
|||||||
REQUIRE(program.get("output") == "thrust_profile.csv");
|
REQUIRE(program.get("output") == "thrust_profile.csv");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse positional arguments with fixed nargs", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse positional arguments with fixed nargs [positional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input");
|
program.add_argument("input");
|
||||||
program.add_argument("output").nargs(2);
|
program.add_argument("output").nargs(2);
|
||||||
@ -23,7 +23,7 @@ TEST_CASE("Parse positional arguments with fixed nargs", "[positional_arguments]
|
|||||||
REQUIRE(outputs[1] == "output.mesh");
|
REQUIRE(outputs[1] == "output.mesh");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse positional arguments with optional arguments", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse positional arguments with optional arguments [positional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input");
|
program.add_argument("input");
|
||||||
program.add_argument("output").nargs(2);
|
program.add_argument("output").nargs(2);
|
||||||
@ -38,7 +38,7 @@ TEST_CASE("Parse positional arguments with optional arguments", "[positional_arg
|
|||||||
REQUIRE(outputs[1] == "output.mesh");
|
REQUIRE(outputs[1] == "output.mesh");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse positional arguments with optional arguments in the middle", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Parse positional arguments with optional arguments in the middle [positional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("input");
|
program.add_argument("input");
|
||||||
program.add_argument("output").nargs(2);
|
program.add_argument("output").nargs(2);
|
||||||
@ -47,8 +47,7 @@ TEST_CASE("Parse positional arguments with optional arguments in the middle", "[
|
|||||||
REQUIRE_THROWS(program.parse_args({ "test", "rocket.mesh", "thrust_profile.csv", "--num_iterations", "15", "output.mesh" }));
|
REQUIRE_THROWS(program.parse_args({ "test", "rocket.mesh", "thrust_profile.csv", "--num_iterations", "15", "output.mesh" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse remaining arguments deemed positional",
|
DOCTEST_TEST_CASE("Parse remaining arguments deemed positional [positional_arguments]") {
|
||||||
"[positional_arguments]") {
|
|
||||||
GIVEN("a program that accepts an optional argument and remaining arguments") {
|
GIVEN("a program that accepts an optional argument and remaining arguments") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("-o");
|
program.add_argument("-o");
|
||||||
@ -95,12 +94,12 @@ TEST_CASE("Parse remaining arguments deemed positional",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Negative nargs is not allowed", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Negative nargs is not allowed [positional_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
REQUIRE_THROWS_AS(program.add_argument("output").nargs(-1), std::logic_error);
|
REQUIRE_THROWS_AS(program.add_argument("output").nargs(-1), std::logic_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Square a number", "[positional_arguments]") {
|
DOCTEST_TEST_CASE("Square a number [positional_arguments]") {
|
||||||
argparse::ArgumentParser program;
|
argparse::ArgumentParser program;
|
||||||
program.add_argument("--verbose", "-v")
|
program.add_argument("--verbose", "-v")
|
||||||
.help("enable verbose logging")
|
.help("enable verbose logging")
|
@ -1,20 +1,19 @@
|
|||||||
#pragma once
|
#include <doctest.hpp>
|
||||||
#include <catch.hpp>
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
|
|
||||||
TEST_CASE("Parse required arguments which are not set and don't have default value.", "[required_arguments]") {
|
DOCTEST_TEST_CASE("Parse required arguments which are not set and don't have default value. [required_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--output", "-o").required();
|
program.add_argument("--output", "-o").required();
|
||||||
REQUIRE_THROWS(program.parse_args({ "./main" }));
|
REQUIRE_THROWS(program.parse_args({ "./main" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse required arguments which are set as empty value and don't have default value.", "[required_arguments]") {
|
DOCTEST_TEST_CASE("Parse required arguments which are set as empty value and don't have default value. [required_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--output", "-o").required();
|
program.add_argument("--output", "-o").required();
|
||||||
REQUIRE_THROWS(program.parse_args({ "./main", "-o" }));
|
REQUIRE_THROWS(program.parse_args({ "./main", "-o" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse required arguments which are set as some value and don't have default value.", "[required_arguments]") {
|
DOCTEST_TEST_CASE("Parse required arguments which are set as some value and don't have default value. [required_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--output", "-o").required();
|
program.add_argument("--output", "-o").required();
|
||||||
program.parse_args({ "./main", "-o", "filename" });
|
program.parse_args({ "./main", "-o", "filename" });
|
||||||
@ -22,7 +21,7 @@ TEST_CASE("Parse required arguments which are set as some value and don't have d
|
|||||||
REQUIRE(program.get("-o") == "filename");
|
REQUIRE(program.get("-o") == "filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse required arguments which are not set and have default value.", "[required_arguments]") {
|
DOCTEST_TEST_CASE("Parse required arguments which are not set and have default value. [required_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
||||||
program.parse_args({ "./main" });
|
program.parse_args({ "./main" });
|
||||||
@ -30,13 +29,13 @@ TEST_CASE("Parse required arguments which are not set and have default value.",
|
|||||||
REQUIRE(program.get("-o") == "filename");
|
REQUIRE(program.get("-o") == "filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse required arguments which are set as empty and have default value.", "[required_arguments]") {
|
DOCTEST_TEST_CASE("Parse required arguments which are set as empty and have default value. [required_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
||||||
REQUIRE_THROWS(program.parse_args({ "./main", "-o" }));
|
REQUIRE_THROWS(program.parse_args({ "./main", "-o" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse required arguments which are set as some value and have default value.", "[required_arguments]") {
|
DOCTEST_TEST_CASE("Parse required arguments which are set as some value and have default value. [required_arguments]") {
|
||||||
argparse::ArgumentParser program("test");
|
argparse::ArgumentParser program("test");
|
||||||
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
||||||
program.parse_args({ "./main", "-o", "anotherfile" });
|
program.parse_args({ "./main", "-o", "anotherfile" });
|
@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
|
||||||
#include <argparse.hpp>
|
#include <argparse.hpp>
|
||||||
#include <catch.hpp>
|
#include <doctest.hpp>
|
||||||
|
|
||||||
TEST_CASE("ArgumentParser is MoveConstructible and MoveAssignable",
|
DOCTEST_TEST_CASE("ArgumentParser is MoveConstructible and MoveAssignable [value_semantics]") {
|
||||||
"[value_semantics]") {
|
|
||||||
GIVEN("a parser that has two arguments") {
|
GIVEN("a parser that has two arguments") {
|
||||||
argparse::ArgumentParser parser("test");
|
argparse::ArgumentParser parser("test");
|
||||||
parser.add_argument("foo");
|
parser.add_argument("foo");
|
||||||
@ -34,8 +32,7 @@ TEST_CASE("ArgumentParser is MoveConstructible and MoveAssignable",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("ArgumentParser is CopyConstructible and CopyAssignable",
|
DOCTEST_TEST_CASE("ArgumentParser is CopyConstructible and CopyAssignable [value_semantics]") {
|
||||||
"[value_semantics]") {
|
|
||||||
GIVEN("a parser that has two arguments") {
|
GIVEN("a parser that has two arguments") {
|
||||||
argparse::ArgumentParser parser("test");
|
argparse::ArgumentParser parser("test");
|
||||||
parser.add_argument("foo");
|
parser.add_argument("foo");
|
Loading…
Reference in New Issue
Block a user