Skip to content

Commit

Permalink
ECKIT-620 Add tests for specific option names/values
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosbento committed Oct 27, 2023
1 parent 3c17dc0 commit fceef17
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/option/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
foreach( TESTCASE RANGE 1 38 )
foreach( TESTCASE RANGE 1 40 )
ecbuild_add_test(
TARGET eckit_test_option_cmdargs_${TESTCASE}
SOURCES eckit_test_option_cmdargs.cc
Expand Down
73 changes: 73 additions & 0 deletions tests/option/eckit_test_option_cmdargs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,79 @@ CASE("test_eckit_option__allows_to_set_default_value_for_options") {
}
#endif

#if TESTCASE == 39
CASE("test_eckit_option__cmdargs_argument_with_dot_in_option_name") {
options_t options;
options.push_back(new SimpleOption<std::string>("a.a", ""));
options.push_back(new SimpleOption<std::string>("b.b.b", ""));
options.push_back(new SimpleOption<std::string>("c.", ""));
options.push_back(new SimpleOption<std::string>(".d", ""));

std::vector<const char*> input = {"exe", "--a.a=a", "--b.b.b=b", "--c.=c", "--.d=d"};
Main::initialise(input.size(), const_cast<char**>(&input[0]));

CmdArgs args(&usage, options, 0, 0, true);
Log::info() << args << std::endl;

std::string a;
EXPECT(args.get("a.a", a));
EXPECT(a == "a");
EXPECT(args.getString("a.a") == a);

std::string b;
EXPECT(args.get("b.b.b", b));
EXPECT(b == "b");
EXPECT(args.getString("b.b.b") == b);

std::string c;
EXPECT(args.get("c.", c));
EXPECT(c == "c");
EXPECT(args.getString("c.") == c);

std::string d;
EXPECT(args.get(".d", d));
EXPECT(d == "d");
EXPECT(args.getString(".d") == d);
}
#endif

#if TESTCASE == 40
CASE("test_eckit_option__cmdargs_argument_with_dot_in_option_name_and_value") {
options_t options;
options.push_back(new SimpleOption<std::string>("a.a", ""));
options.push_back(new SimpleOption<std::string>("b.b.b", ""));
options.push_back(new SimpleOption<std::string>("c.", ""));
options.push_back(new SimpleOption<std::string>(".d", ""));

std::vector<const char*> input = {"exe", "--a.a=a.a", "--b.b.b=b.b.b", "--c.=c.", "--.d=.d"};
Main::initialise(input.size(), const_cast<char**>(&input[0]));

CmdArgs args(&usage, options, 0, 0, true);
Log::info() << args << std::endl;

std::string a;
EXPECT(args.get("a.a", a));
EXPECT(a == "a.a");
EXPECT(args.getString("a.a") == a);

std::string b;
EXPECT(args.get("b.b.b", b));
EXPECT(b == "b.b.b");
EXPECT(args.getString("b.b.b") == b);

std::string c;
EXPECT(args.get("c.", c));
EXPECT(c == "c.");
EXPECT(args.getString("c.") == c);

std::string d;
EXPECT(args.get(".d", d));
EXPECT(d == ".d");
EXPECT(args.getString(".d") == d);
}
#endif


//----------------------------------------------------------------------------------------------------------------------

} // namespace eckit::test
Expand Down

0 comments on commit fceef17

Please sign in to comment.