-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsub_alias_test.c
More file actions
60 lines (54 loc) · 1.86 KB
/
Copy pathsub_alias_test.c
File metadata and controls
60 lines (54 loc) · 1.86 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
58
59
60
#include "common.h"
static cmdp_command_st g_command = {
"App",
.sub_commands =
(cmdp_command_st *[]){
&(cmdp_command_st){"init", "init something"},
&(cmdp_command_st){"run", "run something", .alias_name = "r",
.sub_commands =
(cmdp_command_st *[]){
&(cmdp_command_st){"app-a", "run app a", .alias_name = "a"},
&(cmdp_command_st){"app-b", "run app b"},
NULL,
}},
&(cmdp_command_st){"test", "test something", .alias_name = "t"},
&(cmdp_command_st){"help", "help doc", .alias_name = "h"},
&(cmdp_command_st){"exit", "exit app"},
NULL,
},
};
static const char *g_App_help = " init init something\n"
" r, run run something\n"
" t, test test something\n"
" h, help help doc\n"
" exit exit app\n";
static const char *g_run_help = " a, app-a run app a\n"
" app-b run app b\n";
UTEST(sub_alias, void)
{
START_CMD();
RUN_CMD(&g_command, );
EXPECT_CMD(0, g_App_help, "");
END_CMD();
}
UTEST(sub_alias, r)
{
START_CMD();
RUN_CMD(&g_command, "r");
EXPECT_CMD(0, g_run_help, "");
END_CMD();
}
UTEST(sub_alias, r_a)
{
START_CMD();
RUN_CMD(&g_command, "r", "a");
EXPECT_CMD(0, "", "");
END_CMD();
}
UTEST(sub_alias, r_b)
{
START_CMD();
RUN_CMD(&g_command, "r", "b");
EXPECT_CMD(1, "", "Unknown command b.\n");
END_CMD();
}