File: test_hidden_argument.cpp

package info (click to toggle)
libargparse 3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: cpp: 11,319; python: 8; makefile: 4; sh: 3
file content (36 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
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);
}