blob: 29cfb0e8e3f512c01f42d73e398b0afd2a049e49 (
plain) (
blame)
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
37
38
39
40
41
42
43
44
45
|
#include <library/cpp/getopt/ygetopt.h>
#include <library/cpp/testing/unittest/registar.h>
class TGetOptTest: public TTestBase {
UNIT_TEST_SUITE(TGetOptTest);
UNIT_TEST(TestGetOpt);
UNIT_TEST_EXCEPTION(TestZeroArgC, yexception);
UNIT_TEST_SUITE_END();
public:
void TestGetOpt();
void TestZeroArgC();
};
UNIT_TEST_SUITE_REGISTRATION(TGetOptTest);
void TGetOptTest::TestZeroArgC() {
TGetOpt opt(0, nullptr, "");
}
void TGetOptTest::TestGetOpt() {
const char* argv[] = {
"/usr/bin/bash",
"-f",
"-p",
"qwerty123",
"-z",
"-q",
nullptr};
TString res;
const TString format = "qzp:f";
TGetOpt opt(sizeof(argv) / sizeof(*argv) - 1, argv, format);
for (TGetOpt::TIterator it = opt.Begin(); it != opt.End(); ++it) {
res += it->Key();
if (it->HaveArg()) {
res += it->Arg();
}
}
UNIT_ASSERT_EQUAL(res, "fpqwerty123zq");
}
|