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