-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathcommand_run_test.cpp
More file actions
57 lines (53 loc) · 1.6 KB
/
command_run_test.cpp
File metadata and controls
57 lines (53 loc) · 1.6 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
/*
Copyright René Ferdinand Rivera Morell
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/
#include "mini_test.hpp"
#include <lyra/lyra.hpp>
int main(int, const char **)
{
using namespace lyra;
bfg::mini_test::scope test;
{
auto cli = lyra::cli()
| command("one")
| command("two");
test(REQUIRE(cli.parse({ "TestApp", "one" })));
test(REQUIRE(cli.parse({ "TestApp", "two" })));
test(REQUIRE(cli.parse({ "TestApp" })));
}
{
std::string one = "one";
int two = 2;
auto cli = lyra::cli()
| command("one").add_argument(arg(one, "one"))
| command("two").add_argument(arg(two, "two"));
test(REQUIRE(cli.parse({ "TestApp", "one" })));
test(REQUIRE(cli.parse({ "TestApp", "two" })));
test(REQUIRE(cli.parse({ "TestApp", "one", "ONE" })));
test(REQUIRE(cli.parse({ "TestApp", "two", "3" })));
test(REQUIRE(!cli.parse({ "TestApp", "one", "OnE", "TwO" })));
test(REQUIRE(!cli.parse({ "TestApp", "two", "3", "4" })));
test(REQUIRE(cli.parse({ "TestApp" })));
}
{
bool a = false;
bool b = false;
bool c = false;
bool d = false;
auto cli = lyra::cli()
| command("one")
.add_argument(opt(a, "a").name("--a").optional())
.add_argument(opt(b, "b").name("--b").optional())
| command("two")
.add_argument(opt(c, "c").name("--c").optional())
.add_argument(opt(d, "d").name("--d").optional())
;
test(REQUIRE(cli.parse({ "TestApp", "one", "--a=1" })));
test(REQUIRE(cli.parse({ "TestApp", "two", "--c=1" })));
test(REQUIRE(cli.parse({ "TestApp" })));
}
return test;
}