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