Adjust command completion output when TUI is disabled
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / completion-support.exp
index fe5b16a85b858b8b550be933e6694e9190f240ff..51436cc6713caa307339d9a559a9029d55d71a5d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2017 Free Software Foundation, Inc.
+# Copyright 2017-2020 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -108,21 +108,28 @@ proc test_gdb_complete_tab_unique { input_line complete_line_re append_char_re }
 
     set test "tab complete \"$input_line\""
     send_gdb "$input_line\t"
+    set res 1
     gdb_test_multiple "" "$test" {
        -re "^$complete_line_re$append_char_re$" {
            pass "$test"
        }
+       timeout {
+           fail "$test (timeout)"
+           set res -1
+       }
     }
 
     clear_input_line $test
+    return $res
 }
 
 # Test that completing INPUT_LINE with TAB completes to "INPUT_LINE +
 # ADD_COMPLETED_LINE" and that it displays the completion matches in
-# COMPLETION_LIST.
+# COMPLETION_LIST.  If MAX_COMPLETIONS then we expect the completion
+# to hit the max-completions limit.
 
 proc test_gdb_complete_tab_multiple { input_line add_completed_line \
-                                         completion_list } {
+                                         completion_list {max_completions 0}} {
     global gdb_prompt
 
     set input_line_re [string_to_regexp $input_line]
@@ -130,6 +137,12 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \
 
     set expected_re [make_tab_completion_list_re $completion_list]
 
+    if {$max_completions} {
+       append expected_re "\r\n"
+       append expected_re \
+           "\\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*"
+    }
+
     set test "tab complete \"$input_line\""
     send_gdb "$input_line\t"
     gdb_test_multiple "" "$test (first tab)" {
@@ -139,10 +152,17 @@ proc test_gdb_complete_tab_multiple { input_line add_completed_line \
            # extra tab to show the matches list.
            if {$add_completed_line != ""} {
                send_gdb "\t"
+               set maybe_bell ${completion::bell_re}
+           } else {
+               set maybe_bell ""
            }
            gdb_test_multiple "" "$test (second tab)" {
-               -re "$expected_re\r\n$gdb_prompt $input_line_re$add_completed_line_re$" {
-                   pass "$test"
+               -re "^${maybe_bell}\r\n$expected_re\r\n$gdb_prompt " {
+                   gdb_test_multiple "" "$test (second tab)" {
+                       -re "^$input_line_re$add_completed_line_re$" {
+                           pass "$test"
+                       }
+                   }
                }
            }
        }
@@ -176,12 +196,21 @@ proc test_gdb_complete_cmd_unique { input_line complete_line_re } {
 
 # Test that completing "CMD_PREFIX + COMPLETION_WORD" with the
 # complete command displays the COMPLETION_LIST completion list.  Each
-# entry in the list should be prefixed by CMD_PREFIX.
+# entry in the list should be prefixed by CMD_PREFIX.  If
+# MAX_COMPLETIONS then we expect the completion to hit the
+# max-completions limit.
 
-proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} } {
+proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list {start_quote_char ""} {end_quote_char ""} {max_completions 0}} {
     global gdb_prompt
 
     set expected_re [make_cmd_completion_list_re $cmd_prefix $completion_list $start_quote_char $end_quote_char]
+
+    if {$max_completions} {
+       set cmd_prefix_re [string_to_regexp $cmd_prefix]
+       append expected_re \
+           "$cmd_prefix_re \\*\\*\\* List may be truncated, max-completions reached\\. \\*\\*\\*.*\r\n"
+    }
+
     set cmd_re [string_to_regexp "complete $cmd_prefix$completion_word"]
     set test "cmd complete \"$cmd_prefix$completion_word\""
     gdb_test_multiple "complete $cmd_prefix$completion_word" $test {
@@ -194,7 +223,9 @@ proc test_gdb_complete_cmd_multiple { cmd_prefix completion_word completion_list
 # Test that completing LINE completes to nothing.
 
 proc test_gdb_complete_none { input_line } {
-    test_gdb_complete_tab_none $input_line
+    if { [readline_is_used] } {
+       test_gdb_complete_tab_none $input_line
+    }
     test_gdb_complete_cmd_none $input_line
 }
 
@@ -216,7 +247,12 @@ proc test_gdb_complete_none { input_line } {
 
 proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "} {max_completions 0}} {
     set append_char_re [string_to_regexp $append_char]
-    test_gdb_complete_tab_unique $input_line $complete_line_re $append_char_re
+    if { [readline_is_used] } {
+       if { [test_gdb_complete_tab_unique $input_line $complete_line_re \
+                 $append_char_re] == -1 } {
+           return -1
+       }
+    }
 
     # Trim INPUT_LINE and COMPLETE LINE, for the case we're completing
     # a command with leading whitespace.  Leading command whitespace
@@ -239,6 +275,7 @@ proc test_gdb_complete_unique_re { input_line complete_line_re {append_char " "}
     }
 
     test_gdb_complete_cmd_unique $input_line $expected_output_re
+    return 1
 }
 
 # Like TEST_GDB_COMPLETE_UNIQUE_RE, but COMPLETE_LINE is a string, not
@@ -252,11 +289,17 @@ proc test_gdb_complete_unique { input_line complete_line {append_char " "} {max_
 # Test that completing "CMD_PREFIX + COMPLETION_WORD" adds
 # ADD_COMPLETED_LINE to the input line, and that it displays
 # COMPLETION_LIST as completion match list.  COMPLETION_WORD is the
-# completion word.
-
-proc test_gdb_complete_multiple { cmd_prefix completion_word add_completed_line completion_list {start_quote_char ""} {end_quote_char ""}} {
-    test_gdb_complete_tab_multiple "$cmd_prefix$completion_word" $add_completed_line $completion_list
-    test_gdb_complete_cmd_multiple $cmd_prefix $completion_word $completion_list $start_quote_char $end_quote_char
+# completion word.  If MAX_COMPLETIONS then we expect the completion
+# to hit the max-completions limit.
+
+proc test_gdb_complete_multiple {
+  cmd_prefix completion_word add_completed_line completion_list
+  {start_quote_char ""} {end_quote_char ""} {max_completions 0}
+} {
+    if { [readline_is_used] } {
+      test_gdb_complete_tab_multiple "$cmd_prefix$completion_word" $add_completed_line $completion_list $max_completions
+    }
+    test_gdb_complete_cmd_multiple $cmd_prefix $completion_word $completion_list $start_quote_char $end_quote_char $max_completions
 }
 
 # Test that all the substring prefixes of INPUT from [0..START) to
@@ -268,9 +311,22 @@ proc test_complete_prefix_range_re {input completion_re start {end -1}} {
        set end [string length $input]
     }
 
+    set timeouts 0
+    set max_timeouts 3
     for {set i $start} {$i < $end} {incr i} {
        set line [string range $input 0 $i]
-       test_gdb_complete_unique_re "$line" $completion_re
+       set res [test_gdb_complete_unique_re "$line" $completion_re]
+       if { $res == -1 } {
+           incr timeouts
+       } else {
+           if { $timeouts > 0 } {
+               set timeouts 0
+           }
+       }
+       if { $timeouts == $max_timeouts } {
+           verbose -log "Consecutive timeouts in test_complete_prefix_range_re, giving up"
+           break
+       }
     }
 }
 
@@ -478,3 +534,41 @@ proc foreach_location_labels { sources functions labels body_linespec body_expli
            }
        }
 }
+
+# Check that completion of INPUT_LINE results in GDB completing on all
+# command names.
+proc test_gdb_completion_offers_commands {input_line} {
+    global gdb_prompt
+
+    # There are two many commands to usefully check here.  So we force
+    # max-completions to 2, and check if those 2 come out.
+
+    # Save current max-completions.
+    set max_completions 0
+    set test "show max-completions"
+    gdb_test_multiple $test $test {
+       -re "Maximum number of completion candidates is (.*)\\.\r\n$gdb_prompt $" {
+           set max_completions $expect_out(1,string)
+       }
+    }
+
+    # Force showing two commands.
+    gdb_test_no_output "set max-completions 2" ""
+
+    # TUI adds additional commands to the possible completions, so we
+    # need different patterns depending on whether or not it is enabled.
+    if { [skip_tui_tests] } {
+       test_gdb_complete_multiple $input_line "" "" {
+           "!"
+           "actions"
+       } "" "" 1
+    } else {
+       test_gdb_complete_multiple $input_line "" "" {
+           "!"
+           "+"
+       } "" "" 1
+    }
+
+    # Restore.
+    gdb_test_no_output "set max-completions $max_completions" ""
+}
This page took 0.028279 seconds and 4 git commands to generate.