-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathtest_hidden_argument.cpp
36 lines (31 loc) · 1.3 KB
/
test_hidden_argument.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <doctest.hpp>
using doctest::test_suite;
TEST_CASE("Test setting a hidden argument" * test_suite("hidden_argument")) {
argparse::ArgumentParser program("program");
program.add_argument("--hidden").flag().hidden();
program.add_argument("--regular").flag();
program.add_argument("regular_positional");
// only makes sense if last and optional...
program.add_argument("hidden_positional").nargs(0, 1).hidden();
program.parse_args({"./test.exe", "--hidden", "--regular",
"regular_positional_val", "hidden_positional_val"});
REQUIRE(program.get<bool>("--hidden") == true);
REQUIRE(program.get<bool>("--regular") == true);
REQUIRE(program.get<std::string>("regular_positional") ==
"regular_positional_val");
REQUIRE(program.get<std::string>("hidden_positional") ==
"hidden_positional_val");
REQUIRE(program.usage() ==
"Usage: program [--help] [--version] [--regular] regular_positional");
std::ostringstream s;
s << program;
// std::cout << "DEBUG:" << s.str() << std::endl;
REQUIRE(s.str().find("hidden") == std::string::npos);
REQUIRE(s.str().find("--regular") != std::string::npos);
REQUIRE(s.str().find("regular_positional") != std::string::npos);
}