Add skip_ada_tests to more Ada testcases
[binutils-gdb.git] / gdb / testsuite / gdb.ada / complete.exp
index 1b0e87bc12ec62e65c209b4eb84cfd42d603062c..7fbbb8530f6916ff7370cece34d5d46c5fb45d52 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2005-2013 Free Software Foundation, Inc.
+# Copyright 2005-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
@@ -15,6 +15,8 @@
 
 load_lib "ada.exp"
 
+if { [skip_ada_tests] } { return -1 }
+
 standard_ada_testfile foo
 
 if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
@@ -31,10 +33,13 @@ set eol "\[\r\n\]*"
 # A convenience function that verifies that the "complete EXPR" command
 # returns the EXPECTED_OUTPUT.
 
-proc test_gdb_complete { expr expected_output } {
+proc test_gdb_complete { expr expected_output {msg ""} } {
+    set cmd "complete p $expr"
+    if {$msg == ""} {
+       set msg $cmd
+    }
     gdb_test "complete p $expr" \
-             "$expected_output" \
-             "complete p $expr"
+             "$expected_output" $msg
 }
 
 # A convenience function that verifies that the "complete EXPR" command
@@ -44,16 +49,6 @@ proc test_gdb_no_completion { expr } {
     gdb_test_no_output "complete p $expr"
 }
 
-# A convenience function that joins all the arguments together,
-# with a regexp that matches zero-or-more end of lines in between
-# each argument.  This function is ideal to write the expected output
-# of a GDB command that generates more than a couple of lines, as
-# this allows us to write each line as a separate string, which is
-# easier to read by a human being.
-
-proc multi_line { args } {
-    return [join $args "\[\r\n\]*"]
-}
 # Try a global variable, only one match should be found:
 
 test_gdb_complete "my_glob" \
@@ -71,7 +66,8 @@ test_gdb_no_completion "inner.insi"
 
 # An incomplete nested package name, were lies a single symbol:
 test_gdb_complete "pck.inne" \
-                  "p pck.inner.inside_variable"
+                  "p pck.inner.inside_variable" \
+                  "complete nested package name"
 
 # A fully qualified symbol name, mangled...
 test_gdb_complete "pck__inner__ins" \
@@ -93,6 +89,16 @@ test_gdb_no_completion "exported"
 test_gdb_complete "<Exported" \
                   "p <Exported_Capitalized>"
 
+# While at it, make sure we can print the symbol too, using the '<'
+# notation.
+gdb_test "p <Exported_Capitalized>" " = 2"
+
+# Confirm that we can't print the symbol without the '<' notation.
+gdb_test "p Exported_Capitalized" \
+    "No definition of \"exported_capitalized\" in current context."
+gdb_test "p exported_capitalized" \
+    "No definition of \"exported_capitalized\" in current context."
+
 # A global symbol, created by the binder, that starts with __gnat...
 test_gdb_complete "__gnat_ada_main_progra" \
                   "p __gnat_ada_main_program_name"
@@ -119,7 +125,8 @@ test_gdb_complete "pck.my" \
 
 # A fully qualified package name
 test_gdb_complete "pck.inne" \
-                  "p pck.inner.inside_variable"
+    "p pck.inner.inside_variable" \
+    "complete fully qualified package name"
 
 # A fully qualified package name, with a dot at the end
 test_gdb_complete "pck.inner." \
@@ -150,6 +157,7 @@ test_gdb_complete "external_ident" \
 test_gdb_complete "pck" \
                   [multi_line "(p pck\\.ad\[sb\])?" \
                               "(p pck\\.ad\[sb\])?" \
+                              "p pck.ambiguous_func" \
                               "p pck.external_identical_one" \
                               "p pck.inner.inside_variable" \
                               "p pck.local_identical_one" \
@@ -161,6 +169,7 @@ test_gdb_complete "pck" \
 test_gdb_complete "pck." \
                   [multi_line "(p pck\\.ad\[sb\])?" \
                               "(p pck\\.ad\[sb\])?" \
+                              "p pck.ambiguous_func" \
                               "p pck.external_identical_one" \
                               "p pck.inner.inside_variable" \
                               "p pck.local_identical_one" \
@@ -176,15 +185,51 @@ test_gdb_complete "<pck__my" \
 # The verification we are trying to make involves the event loop,
 # and using the "complete" command is not sufficient to reproduce
 # the original problem.
-set test "interactive complete 'print some'"
-send_gdb "print some\t"
-gdb_test_multiple "" "$test" {
-    -re "^print some_local_variable $" {
-        send_gdb "\n"
-        gdb_test_multiple "" "$test" {
-            -re " = 1$eol$gdb_prompt $" {
-                pass "$test"
-            }
-        }
+
+if { [readline_is_used] } {
+    set test "interactive complete 'print some'"
+    send_gdb "print some\t"
+    gdb_test_multiple "" "$test" {
+       -re "^print some_local_variable $" {
+           send_gdb "\n"
+           gdb_test_multiple "" "$test" {
+               -re " = 1$eol$gdb_prompt $" {
+                   pass "$test"
+               }
+           }
+       }
+    }
+}
+
+# Usually, parsing a function name that is ambiguous yields a menu through
+# which users can select a specific function.  This should not happen during
+# completion, though.
+test_gdb_complete "ambig" \
+                  [multi_line "p ambiguous_func" \
+                              "p ambiguous_proc" ]
+test_gdb_complete "ambiguous_f" \
+                  "p ambiguous_func"
+test_gdb_complete "ambiguous_func" \
+                  "p ambiguous_func"
+
+# Perform a test intented to verify the behavior where the number
+# of possible completions is very large.  The goal is not to verify
+# precisely the list returned by the complete command (this depends
+# on too many parameters -- targets, compiler version, runtime, etc).
+# However, we want to sanity-check each one of them, knowing that
+# each result should start with "break ada" and that the proposed
+# completion should look like a valid symbol name (in particular,
+# no uppercase letters...).  See gdb/22670.  File names are OK as
+# well, which is why "/" and "-" appear in the regexp.
+
+gdb_test_no_output "set max-completions unlimited"
+
+set test "complete break ada"
+gdb_test_multiple "$test" $test {
+    -re "^$test$eol\(break ada\[-a-z0-9._@/\]*$eol\)+$gdb_prompt $" {
+        pass $test
+    }
+    -re "\[A-Z\].*$gdb_prompt $" {
+       fail "$test (gdb/22670)"
     }
 }