MCPcopy Create free account
hub / github.com/Kitware/CMake / testCommandLineArguments1

Function testCommandLineArguments1

Source/kwsys/testCommandLineArguments1.cxx:18–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#include <cstring> /* strcmp */
17
18int testCommandLineArguments1(int argc, char* argv[])
19{
20 kwsys::CommandLineArguments arg;
21 arg.Initialize(argc, argv);
22
23 int n = 0;
24 char* m = nullptr;
25 std::string p;
26 int res = 0;
27
28 using argT = kwsys::CommandLineArguments;
29 arg.AddArgument("-n", argT::SPACE_ARGUMENT, &n, "Argument N");
30 arg.AddArgument("-m", argT::EQUAL_ARGUMENT, &m, "Argument M");
31 arg.AddBooleanArgument("-p", &p, "Argument P");
32
33 arg.StoreUnusedArguments(true);
34
35 if (!arg.Parse()) {
36 std::cerr << "Problem parsing arguments" << std::endl;
37 res = 1;
38 }
39 if (n != 24) {
40 std::cout << "Problem setting N. Value of N: " << n << std::endl;
41 res = 1;
42 }
43 if (!m || strcmp(m, "test value") != 0) {
44 std::cout << "Problem setting M. Value of M: " << m << std::endl;
45 res = 1;
46 }
47 if (p != "1") {
48 std::cout << "Problem setting P. Value of P: " << p << std::endl;
49 res = 1;
50 }
51 std::cout << "Value of N: " << n << std::endl;
52 std::cout << "Value of M: " << m << std::endl;
53 std::cout << "Value of P: " << p << std::endl;
54 delete[] m;
55
56 char** newArgv = nullptr;
57 int newArgc = 0;
58 arg.GetUnusedArguments(&newArgc, &newArgv);
59 int cc;
60 char const* valid_unused_args[9] = { nullptr,
61 "--ignored",
62 "--second-ignored",
63 "third-ignored",
64 "some",
65 "junk",
66 "at",
67 "the",
68 "end" };
69 if (newArgc != 9) {
70 std::cerr << "Bad number of unused arguments: " << newArgc << std::endl;
71 res = 1;
72 }
73 for (cc = 0; cc < newArgc; ++cc) {
74 assert(newArgv[cc]); /* Quiet Clang scan-build. */
75 std::cout << "Unused argument[" << cc << "] = [" << newArgv[cc] << "]"

Callers

nothing calls this directly

Calls 5

GetUnusedArgumentsMethod · 0.80
InitializeMethod · 0.45
AddArgumentMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…