mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 07:04:39 +00:00
Merge pull request #34 from wtdcode/add-required-aruguments-tests
Some basic tests for required arguments
This commit is contained in:
commit
272b19bec2
@ -10,3 +10,4 @@
|
||||
#include <test_parent_parsers.hpp>
|
||||
#include <test_invalid_arguments.hpp>
|
||||
#include <test_negative_numbers.hpp>
|
||||
#include <test_required_arguments.hpp>
|
45
test/test_required_arguments.hpp
Normal file
45
test/test_required_arguments.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include <catch.hpp>
|
||||
#include <argparse.hpp>
|
||||
|
||||
TEST_CASE("Parse required arguments which are not set and don't have default value.", "[required_arguments]") {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--output", "-o").required();
|
||||
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]") {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--output", "-o").required();
|
||||
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]") {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--output", "-o").required();
|
||||
program.parse_args({ "./main", "-o", "filename" });
|
||||
REQUIRE(program.get("--output") == "filename");
|
||||
REQUIRE(program.get("-o") == "filename");
|
||||
}
|
||||
|
||||
TEST_CASE("Parse required arguments which are not set and have default value.", "[required_arguments]") {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
||||
program.parse_args({ "./main" });
|
||||
REQUIRE(program.get("--output") == "filename");
|
||||
REQUIRE(program.get("-o") == "filename");
|
||||
}
|
||||
|
||||
TEST_CASE("Parse required arguments which are set as empty and have default value.", "[required_arguments]") {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
||||
REQUIRE_THROWS(program.parse_args({ "./main", "-o" }));
|
||||
}
|
||||
|
||||
TEST_CASE("Parse required arguments which are set as some value and have default value.", "[required_arguments]") {
|
||||
argparse::ArgumentParser program("test");
|
||||
program.add_argument("--output", "-o").required().default_value(std::string("filename"));
|
||||
program.parse_args({ "./main", "-o", "anotherfile" });
|
||||
REQUIRE(program.get("--output") == "anotherfile");
|
||||
REQUIRE(program.get("-o") == "anotherfile");
|
||||
}
|
Loading…
Reference in New Issue
Block a user