]>
Commit | Line | Data |
---|---|---|
9d0faba9 PA |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
3 | # Copyright 2019 Free Software Foundation, Inc. | |
4 | ||
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 3 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | # Test the gdb::option framework. | |
19 | ||
20 | # The test uses the "maintenance test-options" subcommands to exercise | |
21 | # TAB-completion and option processing. | |
7d8062de | 22 | # |
d4c16835 PA |
23 | # It also tests option integration in various commands, including: |
24 | # | |
25 | ||
26 | # - compile print | |
27 | # - backtrace | |
9d0faba9 PA |
28 | |
29 | load_lib completion-support.exp | |
30 | ||
7d8062de PA |
31 | standard_testfile .c |
32 | ||
33 | if {[build_executable "failed to prepare" $testfile $srcfile debug]} { | |
34 | return -1 | |
35 | } | |
36 | ||
9d0faba9 PA |
37 | clean_restart |
38 | ||
39 | if { ![readline_is_used] } { | |
40 | untested "no tab completion support without readline" | |
41 | return -1 | |
42 | } | |
43 | ||
44 | # Check the completion result, as returned by the "maintenance show | |
45 | # test-options-completion-result" command. TEST is used as test name. | |
46 | proc check_completion_result {expected test} { | |
47 | gdb_test "maintenance show test-options-completion-result" \ | |
48 | "$expected" \ | |
49 | "$test: res=$expected" | |
50 | } | |
51 | ||
52 | # Like test_gdb_complete_unique, but the expected output is expected | |
53 | # to be the input line. I.e., the line is already complete. We're | |
54 | # just checking whether GDB recognizes the option and auto-appends a | |
55 | # space. | |
56 | proc test_completer_recognizes {res input_line} { | |
57 | set expected_re [string_to_regexp $input_line] | |
58 | test_gdb_complete_unique $input_line $expected_re | |
59 | check_completion_result $res $input_line | |
60 | } | |
61 | ||
62 | # Wrapper around test_gdb_complete_multiple that also checks the | |
63 | # completion result is RES. | |
64 | proc res_test_gdb_complete_multiple {res cmd_prefix completion_word args} { | |
65 | test_gdb_complete_multiple $cmd_prefix $completion_word {*}$args | |
66 | check_completion_result $res "$cmd_prefix$completion_word" | |
67 | } | |
68 | ||
69 | # Wrapper around test_gdb_complete_none that also checks the | |
70 | # completion result is RES. | |
71 | proc res_test_gdb_complete_none { res input_line } { | |
72 | test_gdb_complete_none $input_line | |
73 | check_completion_result $res "$input_line" | |
74 | } | |
75 | ||
76 | # Wrapper around test_gdb_complete_unique that also checks the | |
77 | # completion result is RES. | |
78 | proc res_test_gdb_complete_unique { res input_line args} { | |
79 | test_gdb_complete_unique $input_line {*}$args | |
80 | check_completion_result $res "$input_line" | |
81 | } | |
82 | ||
83 | # Make a full command name from VARIANT. VARIANT is either | |
84 | # "require-delimiter", "unknown-is-error" or "unknown-is-operand". | |
85 | proc make_cmd {variant} { | |
86 | return "maint test-options $variant" | |
87 | } | |
88 | ||
89 | # Return a string for the expected result of running "maint | |
90 | # test-options xxx", with no flag/option set. OPERAND is the expected | |
91 | # operand. | |
92 | proc expect_none {operand} { | |
93 | return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- $operand" | |
94 | } | |
95 | ||
96 | # Return a string for the expected result of running "maint | |
97 | # test-options xxx", with -flag set. OPERAND is the expected operand. | |
98 | proc expect_flag {operand} { | |
99 | return "-flag 1 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- $operand" | |
100 | } | |
101 | ||
102 | # Return a string for the expected result of running "maint | |
103 | # test-options xxx", with -bool set. OPERAND is the expected operand. | |
104 | proc expect_bool {operand} { | |
105 | return "-flag 0 -xx1 0 -xx2 0 -bool 1 -enum xxx -uint 0 -zuint-unl 0 -- $operand" | |
106 | } | |
107 | ||
108 | # Return a string for the expected result of running "maint | |
109 | # test-options xxx", with one of the integer options set to $VAL. | |
110 | # OPTION determines which option to expect set. OPERAND is the | |
111 | # expected operand. | |
112 | proc expect_integer {option val operand} { | |
113 | if {$option == "uinteger"} { | |
114 | return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint $val -zuint-unl 0 -- $operand" | |
115 | } elseif {$option == "zuinteger-unlimited"} { | |
116 | return "-flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl $val -- $operand" | |
117 | } else { | |
118 | error "unsupported option: $option" | |
119 | } | |
120 | } | |
121 | ||
122 | set all_options { | |
123 | "-bool" | |
124 | "-enum" | |
125 | "-flag" | |
126 | "-uinteger" | |
127 | "-xx1" | |
128 | "-xx2" | |
129 | "-zuinteger-unlimited" | |
130 | } | |
131 | ||
7d8062de PA |
132 | # Basic option-machinery + "print" command integration tests. |
133 | proc_with_prefix test-print {{prefix ""}} { | |
134 | clean_restart | |
135 | ||
136 | # Completing "print" with no argument completes on symbols only, | |
137 | # no options are offered. Since we haven't loaded any symbols, | |
138 | # the match list should be empty. | |
139 | test_gdb_complete_none "${prefix}print " | |
140 | ||
141 | # OTOH, completing at "-" should list all options. | |
142 | test_gdb_complete_multiple "${prefix}print " "-" "" { | |
143 | "-address" | |
144 | "-array" | |
145 | "-array-indexes" | |
146 | "-elements" | |
147 | "-max-depth" | |
148 | "-null-stop" | |
149 | "-object" | |
150 | "-pretty" | |
151 | "-repeats" | |
152 | "-static-members" | |
153 | "-symbol" | |
154 | "-union" | |
155 | "-vtbl" | |
156 | } | |
157 | ||
158 | global binfile | |
159 | clean_restart $binfile | |
160 | ||
161 | if ![runto_main] { | |
162 | fail "cannot run to main" | |
163 | return | |
164 | } | |
165 | ||
166 | # Mix options and format. | |
167 | gdb_test "${prefix}print -pretty -- /x 1" " = 0x1" | |
168 | ||
169 | # Smoke test that options actually work. | |
170 | gdb_test "${prefix}print -pretty -- g_s" \ | |
171 | [multi_line \ | |
172 | " = {" \ | |
173 | " a = 1," \ | |
174 | " b = 2," \ | |
175 | " c = 3" \ | |
176 | "}"] | |
177 | ||
178 | test_gdb_complete_unique \ | |
179 | "${prefix}print xxx" \ | |
180 | "${prefix}print xxx1" | |
181 | test_gdb_complete_unique \ | |
182 | "${prefix}print -- xxx" \ | |
183 | "${prefix}print -- xxx1" | |
184 | ||
185 | # Error messages when testing with "compile" are different from | |
186 | # the error messages gdb's internal parser throws. This procedure | |
187 | # hides the difference. EXPECTED_RE is only considered when not | |
188 | # testing with "compile". | |
189 | proc test_invalid_expression {cmd expected_re} { | |
190 | upvar prefix prefix | |
191 | ||
192 | if {$prefix != "compile "} { | |
193 | gdb_test $cmd $expected_re | |
194 | } else { | |
195 | # Error messages depend on compiler version, so we just | |
196 | # look for the last line indicating a failure. | |
197 | gdb_test $cmd "Compilation failed\\." | |
198 | } | |
199 | } | |
200 | ||
201 | # Check that '-XXX' without a "--" is handled as an | |
202 | # expression. | |
203 | gdb_test "${prefix}print -1" " = -1" | |
204 | test_invalid_expression \ | |
205 | "${prefix}print --1" \ | |
206 | "Left operand of assignment is not an lvalue\\." | |
207 | test_invalid_expression \ | |
208 | "${prefix}print -object" \ | |
209 | "No symbol \"object\".*" | |
210 | ||
211 | # Test printing with options and no expression. | |
212 | set test "${prefix}print -object --" | |
213 | if {$prefix != "compile "} { | |
214 | # Regular "print" repeats the last history value. | |
215 | gdb_test $test " = -1" | |
216 | } else { | |
217 | # "compile print" starts a multiline expression. | |
218 | gdb_test_multiple $test $test { | |
219 | -re ">$" { | |
220 | gdb_test "-1\nend" " = -1" \ | |
221 | $test | |
222 | } | |
223 | } | |
224 | } | |
225 | ||
226 | # Check that everything after "-- " is treated as an | |
227 | # expression, not confused with an option. | |
228 | test_invalid_expression \ | |
229 | "${prefix}print -- -address" \ | |
230 | "No symbol.*" | |
231 | gdb_test "${prefix}print -- -1" " = -1" | |
232 | test_invalid_expression \ | |
233 | "${prefix}print -- --1" \ | |
234 | "Left operand of assignment is not an lvalue\\." | |
235 | } | |
236 | ||
d4c16835 PA |
237 | # Basic option-machinery + "backtrace" command integration tests. |
238 | proc_with_prefix test-backtrace {} { | |
239 | clean_restart | |
240 | ||
241 | test_gdb_complete_unique "backtrace" "backtrace" | |
242 | test_gdb_complete_none "backtrace " | |
243 | ||
244 | gdb_test "backtrace -" "Ambiguous option at: -" | |
245 | gdb_test "backtrace --" "No stack\\." | |
246 | gdb_test "backtrace -- -" "No stack\\." | |
247 | ||
248 | test_gdb_complete_multiple "backtrace " "-" "" { | |
249 | "-entry-values" | |
250 | "-frame-arguments" | |
251 | "-full" | |
252 | "-hide" | |
253 | "-no-filters" | |
254 | "-past-entry" | |
255 | "-past-main" | |
256 | "-raw-frame-arguments" | |
257 | } | |
258 | ||
90a1ef87 PA |
259 | # Test that we complete the qualifiers, if there's any. |
260 | test_gdb_complete_unique \ | |
261 | "backtrace ful" \ | |
262 | "backtrace full" | |
263 | test_gdb_complete_unique \ | |
264 | "backtrace hid" \ | |
265 | "backtrace hide" | |
266 | test_gdb_complete_unique \ | |
267 | "backtrace no-fil" \ | |
268 | "backtrace no-filters" | |
269 | ||
d4c16835 PA |
270 | global binfile |
271 | clean_restart $binfile | |
272 | ||
273 | if ![runto_main] { | |
274 | fail "cannot run to main" | |
275 | return | |
276 | } | |
277 | ||
278 | # COUNT in "backtrace COUNT" is parsed as an expression. Check | |
279 | # that we complete expressions. | |
280 | ||
281 | test_gdb_complete_unique \ | |
282 | "backtrace xxx" \ | |
283 | "backtrace xxx1" | |
284 | ||
285 | test_gdb_complete_unique \ | |
286 | "backtrace -xxx" \ | |
287 | "backtrace -xxx1" | |
288 | ||
289 | test_gdb_complete_unique \ | |
290 | "backtrace 1 + xxx" \ | |
291 | "backtrace 1 + xxx1" | |
292 | ||
293 | test_gdb_complete_unique \ | |
294 | "backtrace (1 + xxx" \ | |
295 | "backtrace (1 + xxx1" | |
296 | } | |
297 | ||
9d0faba9 PA |
298 | # Miscellaneous tests. |
299 | proc_with_prefix test-misc {variant} { | |
300 | global all_options | |
301 | ||
302 | set cmd [make_cmd $variant] | |
303 | ||
304 | # Call test command with no arguments at all. | |
305 | gdb_test "$cmd" [expect_none ""] | |
306 | ||
307 | # Now with a single dash. | |
308 | if {$variant == "require-delimiter"} { | |
309 | gdb_test "$cmd -" [expect_none "-"] | |
310 | } else { | |
311 | gdb_test "$cmd -" "Ambiguous option at: -" | |
312 | } | |
313 | ||
314 | # Completing at "-" should list all options. | |
315 | res_test_gdb_complete_multiple "1" "$cmd " "-" "" $all_options | |
316 | ||
317 | # Now with a double dash. | |
318 | gdb_test "$cmd --" [expect_none ""] | |
319 | ||
320 | # "--" is recognized by options completer, gdb auto-appends a | |
321 | # space. | |
322 | test_completer_recognizes 1 "$cmd --" | |
323 | ||
324 | # Now with a double dash, plus a dash as operand. | |
325 | gdb_test "$cmd -- -" [expect_none "-"] | |
326 | res_test_gdb_complete_none "0 -" "$cmd -- -" | |
327 | ||
328 | # Completing an unambiguous option just appends an empty space. | |
329 | test_completer_recognizes 1 "$cmd -flag" | |
330 | ||
331 | # Try running an ambiguous option. | |
332 | if {$variant == "require-delimiter"} { | |
333 | gdb_test "$cmd -xx" [expect_none "-xx"] | |
334 | } else { | |
335 | gdb_test "$cmd -xx" "Ambiguous option at: -xx" | |
336 | } | |
337 | ||
338 | # Check that options are not case insensitive. | |
339 | gdb_test "$cmd -flag --" [expect_flag ""] | |
340 | ||
341 | # Check how the different modes behave on unknown option, with a | |
342 | # delimiter. | |
343 | gdb_test "$cmd -FLAG --" \ | |
344 | "Unrecognized option at: -FLAG --" | |
345 | ||
346 | # Check how the different modes behave on unknown option, without | |
347 | # a delimiter. | |
348 | if {$variant == "unknown-is-error"} { | |
349 | gdb_test "$cmd -FLAG" \ | |
350 | "Unrecognized option at: -FLAG" | |
351 | } else { | |
352 | gdb_test "$cmd -FLAG" [expect_none "-FLAG"] | |
353 | } | |
354 | ||
355 | # Test parsing stops at a negative integer. | |
356 | gdb_test "$cmd -1 --" \ | |
357 | "Unrecognized option at: -1 --" | |
358 | gdb_test "$cmd -2 --" \ | |
359 | "Unrecognized option at: -2 --" | |
360 | } | |
361 | ||
362 | # Flag option tests. | |
363 | proc_with_prefix test-flag {variant} { | |
364 | global all_options | |
365 | ||
366 | set cmd [make_cmd $variant] | |
367 | ||
368 | # Completing a flag just appends a space. | |
369 | test_completer_recognizes 1 "$cmd -flag" | |
370 | ||
371 | # Add a dash, and all options should be shown. | |
372 | test_gdb_complete_multiple "$cmd -flag " "-" "" $all_options | |
373 | ||
374 | # Basic smoke tests of accepted / not accepted values. | |
375 | ||
376 | # Check all the different variants a bool option may be specified. | |
377 | if {$variant == "require-delimiter"} { | |
378 | gdb_test "$cmd -flag 999" [expect_none "-flag 999"] | |
379 | } else { | |
380 | gdb_test "$cmd -flag 999" [expect_flag "999"] | |
381 | } | |
382 | gdb_test "$cmd -flag -- 999" [expect_flag "999"] | |
383 | ||
384 | # If the "--" separator is present, then GDB errors out if the | |
385 | # flag option is passed some value -- check that too. | |
386 | gdb_test "$cmd -flag xxx 999 --" "Unrecognized option at: xxx 999 --" | |
387 | gdb_test "$cmd -flag o 999 --" "Unrecognized option at: o 999 --" | |
388 | gdb_test "$cmd -flag 1 999 --" "Unrecognized option at: 1 999 --" | |
389 | ||
390 | # Extract twice the same flag, separated by one space. | |
391 | gdb_test "$cmd -flag -flag -- non flags args" \ | |
392 | [expect_flag "non flags args"] | |
393 | ||
394 | # Extract twice the same flag, separated by one space. | |
395 | gdb_test "$cmd -xx1 -xx2 -xx1 -xx2 -xx1 -- non flags args" \ | |
396 | "-flag 0 -xx1 1 -xx2 1 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- non flags args" | |
397 | ||
398 | # Extract 2 known flags in front of unknown flags. | |
399 | gdb_test "$cmd -xx1 -xx2 -a -b -c -xx1 --" \ | |
400 | "Unrecognized option at: -a -b -c -xx1 --" | |
401 | ||
402 | # Check that combined flags are not recognised. | |
403 | gdb_test "$cmd -xx1 -xx1xx2 -xx1 --" \ | |
404 | "Unrecognized option at: -xx1xx2 -xx1 --" | |
405 | ||
406 | # Make sure the completer don't confuse a flag option with a | |
407 | # boolean option. Specifically, "o" should not complete to | |
408 | # "on/off". | |
409 | ||
410 | if {$variant == "require-delimiter"} { | |
411 | res_test_gdb_complete_none "1" "$cmd -flag o" | |
412 | ||
413 | gdb_test "$cmd -flag o" [expect_none "-flag o"] | |
414 | } else { | |
415 | res_test_gdb_complete_none "0 o" "$cmd -flag o" | |
416 | ||
417 | gdb_test "$cmd -flag o" [expect_flag "o"] | |
418 | } | |
419 | } | |
420 | ||
421 | # Boolean option tests. | |
422 | proc_with_prefix test-boolean {variant} { | |
423 | global all_options | |
424 | ||
425 | set cmd [make_cmd $variant] | |
426 | ||
427 | # Boolean option's values are optional -- "on" is implied. Check | |
428 | # that: | |
429 | # | |
430 | # - For require-delimiter commands, completing after a boolean | |
431 | # option lists all other options, plus "on/off". This is | |
432 | # because operands won't be processed until we see a "--" | |
433 | # delimiter. | |
434 | # | |
435 | # - For !require-delimiter commands, completing after a boolean | |
436 | # option completes as an operand, since that will tend to be | |
437 | # more common than typing "on/off". | |
438 | # E.g., "frame apply all -past-main COMMAND". | |
439 | ||
440 | if {$variant == "require-delimiter"} { | |
441 | res_test_gdb_complete_multiple 1 "$cmd -bool " "" "" { | |
442 | "-bool" | |
443 | "-enum" | |
444 | "-flag" | |
445 | "-uinteger" | |
446 | "-xx1" | |
447 | "-xx2" | |
448 | "-zuinteger-unlimited" | |
449 | "off" | |
450 | "on" | |
451 | } | |
452 | } else { | |
453 | res_test_gdb_complete_none "0 " "$cmd -bool " | |
454 | } | |
455 | ||
456 | # Add another dash, and "on/off" are no longer offered: | |
457 | res_test_gdb_complete_multiple 1 "$cmd -bool " "-" "" $all_options | |
458 | ||
459 | # Basic smoke tests of accepted / not accepted values. | |
460 | ||
461 | # The command accepts all of "1/0/enable/disable/yes/no" too, even | |
462 | # though like the "set" command, we don't offer those as | |
463 | # completion candidates if you complete right after the boolean | |
464 | # command's name, like: | |
465 | # | |
466 | # (gdb) maint test-options require-delimiter -bool [TAB] | |
467 | # off on | |
468 | # | |
469 | # However, the completer does recognize them if you start typing | |
470 | # the boolean value. | |
471 | foreach value {"0" "1"} { | |
472 | test_completer_recognizes 1 "$cmd -bool $value" | |
473 | } | |
474 | foreach value {"of" "off"} { | |
475 | res_test_gdb_complete_unique 1 \ | |
476 | "$cmd -bool $value" \ | |
477 | "$cmd -bool off" | |
478 | } | |
479 | foreach value {"y" "ye" "yes"} { | |
480 | res_test_gdb_complete_unique 1 \ | |
481 | "$cmd -bool $value" \ | |
482 | "$cmd -bool yes" | |
483 | } | |
484 | foreach value {"n" "no"} { | |
485 | res_test_gdb_complete_unique 1 \ | |
486 | "$cmd -bool $value" \ | |
487 | "$cmd -bool no" | |
488 | } | |
489 | foreach value { | |
490 | "e" | |
491 | "en" | |
492 | "ena" | |
493 | "enab" | |
494 | "enabl" | |
495 | "enable" | |
496 | } { | |
497 | res_test_gdb_complete_unique 1 \ | |
498 | "$cmd -bool $value" \ | |
499 | "$cmd -bool enable" | |
500 | } | |
501 | foreach value { | |
502 | "d" | |
503 | "di" | |
504 | "dis" | |
505 | "disa" | |
506 | "disab" | |
507 | "disabl" | |
508 | "disable" | |
509 | } { | |
510 | res_test_gdb_complete_unique 1 \ | |
511 | "$cmd -bool $value" \ | |
512 | "$cmd -bool disable" | |
513 | } | |
514 | ||
515 | if {$variant == "require-delimiter"} { | |
516 | res_test_gdb_complete_none "1" "$cmd -bool xxx" | |
517 | } else { | |
518 | res_test_gdb_complete_none "0 xxx" "$cmd -bool xxx" | |
519 | } | |
520 | ||
521 | # The command accepts abbreviations of "enable/disable/yes/no", | |
522 | # even though we don't offer those for completion. | |
523 | foreach value { | |
524 | "1" | |
525 | "y" "ye" "yes" | |
526 | "e" | |
527 | "en" | |
528 | "ena" | |
529 | "enab" | |
530 | "enabl" | |
531 | "enable"} { | |
532 | gdb_test "$cmd -bool $value --" [expect_bool ""] | |
533 | } | |
534 | foreach value { | |
535 | "0" | |
536 | "of" "off" | |
537 | "n" "no" | |
538 | "d" | |
539 | "di" | |
540 | "dis" | |
541 | "disa" | |
542 | "disab" | |
543 | "disabl" | |
544 | "disable"} { | |
545 | gdb_test "$cmd -bool $value --" [expect_none ""] | |
546 | } | |
547 | ||
548 | if {$variant == "require-delimiter"} { | |
549 | gdb_test "$cmd -bool 999" [expect_none "-bool 999"] | |
550 | } else { | |
551 | gdb_test "$cmd -bool 999" [expect_bool "999"] | |
552 | } | |
553 | gdb_test "$cmd -bool -- 999" [expect_bool "999"] | |
554 | ||
555 | # Since "on" is implied after a boolean option, for | |
556 | # !require-delimiter commands, anything that is not | |
557 | # yes/no/1/0/on/off/enable/disable should be considered as the raw | |
558 | # input after the last option. Also check "o", which might look | |
559 | # like "on" or "off", but it's treated the same. | |
560 | ||
561 | foreach arg {"xxx" "o"} { | |
562 | if {$variant == "require-delimiter"} { | |
563 | gdb_test "$cmd -bool $arg" [expect_none "-bool $arg"] | |
564 | } else { | |
565 | gdb_test "$cmd -bool $arg" [expect_bool "$arg"] | |
566 | } | |
567 | } | |
568 | # Also try -1. "unknown-is-error" commands error out saying that | |
569 | # that's not a valid option. | |
570 | if {$variant == "require-delimiter"} { | |
571 | gdb_test "$cmd -bool -1" \ | |
572 | [expect_none "-bool -1"] | |
573 | } elseif {$variant == "unknown-is-error"} { | |
574 | gdb_test "$cmd -bool -1" \ | |
575 | "Unrecognized option at: -1" | |
576 | } else { | |
577 | gdb_test "$cmd -bool -1" [expect_bool "-1"] | |
578 | } | |
579 | ||
580 | # OTOH, if the "--" separator is present, then GDB errors out if | |
581 | # the boolean option is passed an invalid value -- check that too. | |
582 | gdb_test "$cmd -bool -1 999 --" \ | |
583 | "Unrecognized option at: -1 999 --" | |
584 | gdb_test "$cmd -bool xxx 999 --" \ | |
585 | "Value given for `-bool' is not a boolean: xxx" | |
586 | gdb_test "$cmd -bool o 999 --" \ | |
587 | "Value given for `-bool' is not a boolean: o" | |
588 | ||
589 | # Completing after a boolean option + "o" does list "on/off", | |
590 | # though. | |
591 | if {$variant == "require-delimiter"} { | |
592 | res_test_gdb_complete_multiple 1 "$cmd -bool " "o" "" { | |
593 | "off" | |
594 | "on" | |
595 | } | |
596 | } else { | |
597 | res_test_gdb_complete_multiple "0 o" "$cmd -bool " "o" "" { | |
598 | "off" | |
599 | "on" | |
600 | } | |
601 | } | |
602 | } | |
603 | ||
604 | # Uinteger option tests. OPTION is which integer option we're | |
605 | # testing. Can be "uinteger" or "zuinteger-unlimited". | |
606 | proc_with_prefix test-uinteger {variant option} { | |
607 | global all_options | |
608 | ||
609 | set cmd "[make_cmd $variant] -$option" | |
610 | ||
611 | # Test completing a uinteger option: | |
612 | res_test_gdb_complete_multiple 1 "$cmd " "" "" { | |
613 | "NUMBER" | |
614 | "unlimited" | |
615 | } | |
616 | ||
617 | # NUMBER above is just a placeholder, make sure we don't complete | |
618 | # it as a valid option. | |
619 | res_test_gdb_complete_none 1 "$cmd NU" | |
620 | ||
621 | # "unlimited" is valid though. | |
622 | res_test_gdb_complete_unique 1 \ | |
623 | "$cmd u" \ | |
624 | "$cmd unlimited" | |
625 | ||
626 | # Basic smoke test of accepted / not accepted values. | |
627 | gdb_test "$cmd 1 -- 999" [expect_integer $option "1" "999"] | |
628 | gdb_test "$cmd unlimited -- 999" \ | |
629 | [expect_integer $option "unlimited" "999"] | |
630 | if {$option == "zuinteger-unlimited"} { | |
631 | gdb_test "$cmd -1 --" [expect_integer $option "unlimited" ""] | |
632 | gdb_test "$cmd 0 --" [expect_integer $option "0" ""] | |
633 | } else { | |
634 | gdb_test "$cmd -1 --" "integer -1 out of range" | |
635 | gdb_test "$cmd 0 --" [expect_integer $option "unlimited" ""] | |
636 | } | |
637 | gdb_test "$cmd xxx --" \ | |
638 | "Expected integer at: xxx --" | |
639 | gdb_test "$cmd unlimitedx --" \ | |
640 | "Expected integer at: unlimitedx --" | |
641 | ||
642 | # Don't offer completions until we're past the | |
643 | # -uinteger/-zuinteger-unlimited argument. | |
644 | res_test_gdb_complete_none 1 "$cmd 1" | |
645 | ||
646 | # A number of invalid values. | |
647 | foreach value {"x" "x " "1a" "1a " "1-" "1- " "unlimitedx"} { | |
648 | res_test_gdb_complete_none 1 "$cmd $value" | |
649 | } | |
650 | ||
651 | # Try "-1". | |
652 | if {$option == "uinteger"} { | |
653 | # -1 is invalid uinteger. | |
654 | foreach value {"-1" "-1 "} { | |
655 | res_test_gdb_complete_none 1 "$cmd $value" | |
656 | } | |
657 | } else { | |
658 | # -1 is valid for zuinteger-unlimited. | |
659 | res_test_gdb_complete_none 1 "$cmd -1" | |
660 | if {$variant == "require-delimiter"} { | |
661 | res_test_gdb_complete_multiple 1 "$cmd -1 " "" "-" $all_options | |
662 | } else { | |
663 | res_test_gdb_complete_none "0 " "$cmd -1 " | |
664 | } | |
665 | } | |
666 | ||
667 | # Check that after a fully parsed option: | |
668 | # | |
669 | # - for require-delimiter commands, completion offers all | |
670 | # options. | |
671 | # | |
672 | # - for !require-delimiter commands, completion offers nothing | |
673 | # and returns false. | |
674 | if {$variant == "require-delimiter"} { | |
675 | res_test_gdb_complete_multiple 1 "$cmd 1 " "" "-" $all_options | |
676 | } else { | |
677 | res_test_gdb_complete_none "0 " "$cmd 1 " | |
678 | } | |
679 | ||
680 | # Test completing non-option arguments after "-uinteger 1 ". | |
681 | foreach operand {"x" "x " "1a" "1a " "1-" "1- "} { | |
682 | if {$variant == "require-delimiter"} { | |
683 | res_test_gdb_complete_none 1 "$cmd 1 $operand" | |
684 | } else { | |
685 | res_test_gdb_complete_none "0 $operand" "$cmd 1 $operand" | |
686 | } | |
687 | } | |
688 | # These look like options, but they aren't. | |
689 | foreach operand {"-1" "-1 "} { | |
690 | if {$variant == "unknown-is-operand"} { | |
691 | res_test_gdb_complete_none "0 $operand" "$cmd 1 $operand" | |
692 | } else { | |
693 | res_test_gdb_complete_none 1 "$cmd 1 $operand" | |
694 | } | |
695 | } | |
696 | } | |
697 | ||
698 | # Enum option tests. | |
699 | proc_with_prefix test-enum {variant} { | |
700 | set cmd [make_cmd $variant] | |
701 | ||
702 | res_test_gdb_complete_multiple 1 "$cmd -enum " "" "" { | |
703 | "xxx" | |
704 | "yyy" | |
705 | "zzz" | |
706 | } | |
707 | ||
708 | # Check that "-" where a value is expected does not show the | |
709 | # command's options. I.e., an enum's value is not optional. | |
710 | # Check both completion and running the command. | |
711 | res_test_gdb_complete_none 1 "$cmd -enum -" | |
712 | gdb_test "$cmd -enum --"\ | |
713 | "Requires an argument. Valid arguments are xxx, yyy, zzz\\." | |
714 | ||
715 | # Try passing an undefined item to an enum option. | |
716 | gdb_test "$cmd -enum www --" "Undefined item: \"www\"." | |
717 | } | |
718 | ||
719 | # Run the options framework tests first. | |
720 | foreach_with_prefix cmd { | |
721 | "require-delimiter" | |
722 | "unknown-is-error" | |
723 | "unknown-is-operand" | |
724 | } { | |
725 | test-misc $cmd | |
726 | test-flag $cmd | |
727 | test-boolean $cmd | |
728 | foreach subcmd {"uinteger" "zuinteger-unlimited" } { | |
729 | test-uinteger $cmd $subcmd | |
730 | } | |
731 | test-enum $cmd | |
732 | } | |
7d8062de PA |
733 | |
734 | # Run the print integration tests. | |
735 | test-print "" | |
736 | ||
737 | # Same for "compile print". | |
738 | if ![skip_compile_feature_tests] { | |
739 | test-print "compile " | |
740 | } | |
d4c16835 PA |
741 | |
742 | # Basic "backtrace" integration tests. | |
743 | test-backtrace |