mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-03 22:54:39 +00:00
Add tests for ArgumentParser::get
These test the API shown in README.md, rather than the Argument::get function that does most of the work. Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This commit is contained in:
parent
b6cedf4d56
commit
97993666ab
@ -30,6 +30,7 @@ file(GLOB ARGPARSE_TEST_SOURCES
|
||||
test_compound_arguments.cpp
|
||||
test_container_arguments.cpp
|
||||
test_const_correct.cpp
|
||||
test_get.cpp
|
||||
test_help.cpp
|
||||
test_invalid_arguments.cpp
|
||||
test_is_used.cpp
|
||||
|
29
test/test_get.cpp
Normal file
29
test/test_get.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <doctest.hpp>
|
||||
#include <argparse/argparse.hpp>
|
||||
|
||||
using doctest::test_suite;
|
||||
|
||||
TEST_CASE("Getting a simple argument" * test_suite("ArgumentParser::get")) {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("-s", "--stuff");
|
||||
REQUIRE_NOTHROW(program.parse_args({ "test", "-s", "./src" }));
|
||||
REQUIRE(program.get("--stuff") == "./src");
|
||||
}
|
||||
|
||||
TEST_CASE("Missing argument" * test_suite("ArgumentParser::get")) {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("-s", "--stuff");
|
||||
REQUIRE_NOTHROW(program.parse_args({ "test" }));
|
||||
REQUIRE_THROWS_WITH_AS(program.get("--stuff"),
|
||||
"No value provided",
|
||||
std::logic_error);
|
||||
}
|
||||
|
||||
TEST_CASE("Implicit argument" * test_suite("ArgumentParser::get")) {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("-s", "--stuff").nargs(1);
|
||||
REQUIRE_NOTHROW(program.parse_args({ "test" }));
|
||||
REQUIRE_THROWS_WITH_AS(program.get("--stuff"),
|
||||
"No value provided",
|
||||
std::logic_error);
|
||||
}
|
Loading…
Reference in New Issue
Block a user