-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcommand_options.bats
More file actions
163 lines (148 loc) · 6.18 KB
/
command_options.bats
File metadata and controls
163 lines (148 loc) · 6.18 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
load test_helpers
setup() {
load "${BATS_UTILS_PATH}/bats-support/load.bash"
load "${BATS_UTILS_PATH}/bats-assert/load.bash"
cd ./tests/command_options
}
@test "command_options: no options is passed" {
run lets test-options
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT="
assert_line --index 2 "LETSOPT_BOOL_OPT="
assert_line --index 3 "LETSOPT_ARGS="
assert_line --index 4 "LETSOPT_ATTR="
assert_line --index 5 "LETSCLI_KV_OPT="
assert_line --index 6 "LETSCLI_BOOL_OPT="
assert_line --index 7 "LETSCLI_ARGS="
assert_line --index 8 "LETSCLI_ATTR="
}
@test "command_options: should parse --kv-opt value with equal sign" {
run lets test-options --kv-opt=hello
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT=hello"
assert_line --index 2 "LETSOPT_BOOL_OPT="
assert_line --index 3 "LETSOPT_ARGS="
assert_line --index 4 "LETSOPT_ATTR="
assert_line --index 5 "LETSCLI_KV_OPT=--kv-opt hello"
assert_line --index 6 "LETSCLI_BOOL_OPT="
assert_line --index 7 "LETSCLI_ARGS="
assert_line --index 8 "LETSCLI_ATTR="
}
@test "command_options: should parse --kv-opt value with space" {
run lets test-options --kv-opt hello
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT=hello"
assert_line --index 2 "LETSOPT_BOOL_OPT="
assert_line --index 3 "LETSOPT_ARGS="
assert_line --index 4 "LETSOPT_ATTR="
assert_line --index 5 "LETSCLI_KV_OPT=--kv-opt hello"
assert_line --index 6 "LETSCLI_BOOL_OPT="
assert_line --index 7 "LETSCLI_ARGS="
assert_line --index 8 "LETSCLI_ATTR="
}
@test "command_options: should parse --kv-opt and --bool-opt" {
run lets test-options --kv-opt hello --bool-opt
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT=hello"
assert_line --index 2 "LETSOPT_BOOL_OPT=true"
assert_line --index 3 "LETSOPT_ARGS="
assert_line --index 4 "LETSOPT_ATTR="
assert_line --index 5 "LETSCLI_KV_OPT=--kv-opt hello"
assert_line --index 6 "LETSCLI_BOOL_OPT=--bool-opt"
assert_line --index 7 "LETSCLI_ARGS="
assert_line --index 8 "LETSCLI_ATTR="
}
@test "command_options: should parse --kv-opt, --bool-opt and positional args" {
run lets test-options --kv-opt hello --bool-opt myarg1 myarg2
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT=hello"
assert_line --index 2 "LETSOPT_BOOL_OPT=true"
assert_line --index 3 "LETSOPT_ARGS=myarg1 myarg2"
assert_line --index 4 "LETSOPT_ATTR="
assert_line --index 5 "LETSCLI_KV_OPT=--kv-opt hello"
assert_line --index 6 "LETSCLI_BOOL_OPT=--bool-opt"
assert_line --index 7 "LETSCLI_ARGS=myarg1 myarg2"
assert_line --index 8 "LETSCLI_ATTR="
}
@test "command_options: should parse only positional args" {
run lets test-options myarg1 myarg2
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT="
assert_line --index 2 "LETSOPT_BOOL_OPT="
assert_line --index 3 "LETSOPT_ARGS=myarg1 myarg2"
assert_line --index 4 "LETSOPT_ATTR="
assert_line --index 5 "LETSCLI_KV_OPT="
assert_line --index 6 "LETSCLI_BOOL_OPT="
assert_line --index 7 "LETSCLI_ARGS=myarg1 myarg2"
assert_line --index 8 "LETSCLI_ATTR="
}
@test "command_options: should parse repeated kv flags --attr" {
run lets test-options --attr=myarg1 --attr=myarg2
assert_success
assert_line --index 0 "Flags command"
assert_line --index 1 "LETSOPT_KV_OPT="
assert_line --index 2 "LETSOPT_BOOL_OPT="
assert_line --index 3 "LETSOPT_ARGS="
assert_line --index 4 "LETSOPT_ATTR=myarg1 myarg2"
assert_line --index 5 "LETSCLI_KV_OPT="
assert_line --index 6 "LETSCLI_BOOL_OPT="
assert_line --index 7 "LETSCLI_ARGS="
assert_line --index 8 "LETSCLI_ATTR=--attr myarg1 myarg2"
}
@test "command_options: option without required argument" {
run lets test-options --kv-opt
assert_failure
assert_line --index 0 "lets: command failed:"
assert_line --index 1 " └─ test-options <-- failed here"
assert_line --index 2 "lets: failed to parse docopt options for cmd test-options: --kv-opt requires argument"
assert_line --index 3 "Usage:"
assert_line --index 4 " lets test-options [--kv-opt=<kv-opt>] [--bool-opt] [--attr=<attr>...] [<args>...]"
assert_line --index 5 "Options:"
assert_line --index 6 " <args>... Positional args in the end"
assert_line --index 7 " --bool-opt, -b Boolean opt"
assert_line --index 8 " --kv-opt=<kv-opt>, -K Key value opt"
assert_line --index 9 " --attr=<attr>... Repeated kv args"
}
@test "command_options: wrong usage" {
run lets options-wrong-usage
assert_failure
assert_line --index 0 "lets: command failed:"
assert_line --index 1 " └─ options-wrong-usage <-- failed here"
assert_line --index 2 "lets: failed to parse docopt options for cmd options-wrong-usage: unknown option or argument: options-wrong-usage"
assert_line --index 3 "Usage: lets options-wrong-usage-xxx"
}
@test "command_options: should not break json argument" {
run lets test-proxy-options \
start \
path.to.pythonModule.py \
--kwargs='{"sobaka": true}' \
'--json={"x": 25, "y": [1, 2, 3]}'
assert_success
linesLen="${#lines[@]}"
[[ $linesLen = 4 ]]
assert_line --index 0 'start'
assert_line --index 1 'path.to.pythonModule.py'
assert_line --index 2 '--kwargs={"sobaka": true}'
assert_line --index 3 '--json={"x": 25, "y": [1, 2, 3]}'
}
@test "command_options: should not break string argument with whitespace" {
run lets test-proxy-options generate somethingUseful -m "my message contains whitespace!!"
assert_success
linesLen="${#lines[@]}"
[[ $linesLen = 4 ]]
assert_line --index 0 "generate"
assert_line --index 1 "somethingUseful"
assert_line --index 2 "-m"
assert_line --index 3 "my message contains whitespace!!"
}
@test "command_options: param with same name as command name itself" {
run lets say Bro
assert_success
assert_line --index 0 "Hi Bro"
}