File: gh-4076-argparse-wrong-bool-handling.result

package info (click to toggle)
tarantool 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,364 kB
  • sloc: ansic: 513,760; cpp: 69,489; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,173; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (203 lines) | stat: -rw-r--r-- 3,422 bytes parent folder | download | duplicates (3)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
-- test-run result file version 2
test_run = require('test_run').new()
 | ---
 | ...
test_run:cmd("push filter ".."'\\.lua.*:[0-9]+: ' to '.lua:<line>\"]: '")
 | ---
 | - true
 | ...
argparse = require('internal.argparse').parse
 | ---
 | ...
--
-- gh-4076: argparse incorrectly processed boolean parameters,
-- that led to problems with tarantoolctl usage.
--
params = {}
 | ---
 | ...
params[1] = {'flag1', 'boolean'}
 | ---
 | ...
params[2] = {'flag2', 'boolean'}
 | ---
 | ...
params[3] = {'flag3', 'boolean'}
 | ---
 | ...
args = {'--flag1', 'positional value', '--flag2'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - 1: positional value
 |   flag1: true
 |   flag2: true
 | ...

--
-- When several 'boolean' arguments are passed, the result will be
-- `true` (just as for one such argument).
--
params = {}
 | ---
 | ...
params[1] = {'foo', 'boolean'}
 | ---
 | ...
args = {'--foo', '--foo'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - foo: true
 | ...

--
-- When several 'boolean+' arguments are passed, the result will
-- be a list of `true` values.
--
params = {}
 | ---
 | ...
params[1] = {'foo', 'boolean+'}
 | ---
 | ...
args = {'--foo', '--foo'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - foo:
 |   - true
 |   - true
 | ...

params = {}
 | ---
 | ...
params[1] = {'foo', 'boolean+'}
 | ---
 | ...
args = {'--foo', 'positional value', '--foo'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - foo:
 |   - true
 |   - true
 |   1: positional value
 | ...

--
-- When a value is provided for a 'boolean' / 'boolean+' option
-- using --foo=bar syntax, the error should state that a value is
-- not expected for this option.
--
params = {}
 | ---
 | ...
params[1] = {'foo', 'boolean'}
 | ---
 | ...
argparse({'--foo=bar'}, params)
 | ---
 | - error: 'builtin/internal.argparse.lua:<line>"]: Bad value for parameter "foo". No value
 |     expected, got "bar"'
 | ...

params = {}
 | ---
 | ...
params[1] = {'foo', 'boolean+'}
 | ---
 | ...
argparse({'--foo=bar'}, params)
 | ---
 | - error: 'builtin/internal.argparse.lua:<line>"]: Bad value for parameter "foo". No value
 |     expected, got "bar"'
 | ...

--
-- When parameter value was omitted, it was replaced internally
-- with boolean true, and sometimes was showed in error messages.
-- Now it is 'nothing'.
--
params = {}
 | ---
 | ...
params[1] = {'value', 'number'}
 | ---
 | ...
argparse({'--value'}, params)
 | ---
 | - error: 'builtin/internal.argparse.lua:<line>"]: Bad value for parameter "value". Expected
 |     number, got nothing'
 | ...

params = {}
 | ---
 | ...
params[1] = {'value', 'string'}
 | ---
 | ...
argparse({'--value'}, params)
 | ---
 | - error: 'builtin/internal.argparse.lua:<line>"]: Bad value for parameter "value". Expected
 |     string, got nothing'
 | ...

--
-- Verify that short 'boolean' and 'boolean+' options behaviour
-- is the same as for long options.
--
params = {}
 | ---
 | ...
params[1] = {'f', 'boolean'}
 | ---
 | ...
args = {'-f'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - f: true
 | ...
args = {'-f', '-f'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - f: true
 | ...

params = {}
 | ---
 | ...
params[1] = {'f', 'boolean+'}
 | ---
 | ...
args = {'-f'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - f:
 |   - true
 | ...
args = {'-f', '-f'}
 | ---
 | ...
argparse(args, params)
 | ---
 | - f:
 |   - true
 |   - true
 | ...

test_run:cmd("clear filter")
 | ---
 | - true
 | ...