-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument_test.c
More file actions
50 lines (43 loc) · 1.12 KB
/
Copy pathargument_test.c
File metadata and controls
50 lines (43 loc) · 1.12 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
#include "common.h"
static struct
{
bool opt_a;
bool opt_b;
} g_arg = {0};
static cmdp_action_t g_process(cmdp_process_param_st *params);
static cmdp_command_st g_command = {
.options =
(cmdp_option_st[]){
{'a', NULL, "option a", CMDP_TYPE_BOOL, &g_arg.opt_a},
{'b', NULL, "option b", CMDP_TYPE_BOOL, &g_arg.opt_b},
{0},
},
.fn_process = g_process,
};
static cmdp_action_t g_process(cmdp_process_param_st *params)
{
if (params->argc == 0 && params->opts == 0)
{
return CMDP_ACT_SHOW_HELP;
}
fprintf(params->out_stream, "a:%d,b:%d", g_arg.opt_a, g_arg.opt_b);
for (size_t i = 0; i < params->argc; i++)
{
fprintf(params->out_stream, ",%zu:%s", i, params->argv[i]);
}
return CMDP_ACT_OK;
}
UTEST(argument, simple)
{
START_CMD();
RUN_CMD(&g_command, "-a", "-b", "arg1", "arg2");
EXPECT_CMD(0, "a:1,b:1,0:arg1,1:arg2", "");
END_CMD();
}
UTEST(argument, end_op_options)
{
START_CMD();
RUN_CMD(&g_command, "-a", "--", "-b", "arg1", "arg2");
EXPECT_CMD(0, "a:1,b:0,0:-b,1:arg1,2:arg2", "");
END_CMD();
}