]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Handle optional lines correctly in gdb.ada/complete.exp
authorTom Tromey <tromey@adacore.com>
Thu, 5 Sep 2024 18:09:43 +0000 (12:09 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 20 Feb 2025 14:50:55 +0000 (07:50 -0700)
While working on another series, I discovered that the existing code
in gdb.ada/complete.exp that conditionally accepts a completion does
not work correctly.  The code assumes that wrapping a line in "(...)?"
will make the entire line optional, but really this will only match a
blank line.

Meanwhile, I needed this same patch for a second series I'm working
on, so I've pulled this out.  As it only affects Ada, I am going to
check it in.

gdb/testsuite/gdb.ada/complete.exp

index 6263c4e849a05c70a8075f78cb5ba9fd6b025206..70d4945f8c8c11b48dca9f298206ba3ab8e1facf 100644 (file)
@@ -30,6 +30,17 @@ runto "foo.adb:$bp_location"
 
 set eol "\r\n"
 
+# Like multi_line, but if a line is optional (like "(mumble)?"), then
+# insert the \r\n into the optional part.
+proc multi_line_with_optional {args} {
+    set result ""
+    foreach line $args {
+       append result [regsub -- "(\\)\\?)?$" $line "\r\n\\1"]
+    }
+    # Remove the final \r\n.
+    return [string range $result 0 end-2]
+}
+
 # A convenience function that verifies that the "complete EXPR" command
 # returns the EXPECTED_OUTPUT.
 
@@ -155,29 +166,35 @@ test_gdb_complete "external_ident" \
 
 # Complete on the name of package. 
 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.internal_capitalized" \
-                              "p pck.local_identical_one" \
-                              "p pck.local_identical_two" \
-                              "p pck.my_global_variable" \
-                              "p pck.proc" ]
+    [multi_line_with_optional \
+        "(p pck)?" \
+        "(p pck\\.ad\[sb\])?" \
+        "(p pck\\.ad\[sb\])?" \
+        "p pck.ambiguous_func" \
+        "p pck.external_identical_one" \
+        "(p pck.inner)?" \
+        "p pck.inner.inside_variable" \
+        "p pck.internal_capitalized" \
+        "p pck.local_identical_one" \
+        "p pck.local_identical_two" \
+        "p pck.my_global_variable" \
+        "p pck.proc" ]
 
 # Complete on the name of a package followed by a dot:
 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.internal_capitalized" \
-                              "p pck.local_identical_one" \
-                              "p pck.local_identical_two" \
-                              "p pck.my_global_variable" \
-                              "p pck.proc" ]
+    [multi_line_with_optional \
+        "(p pck\\.)?" \
+        "(p pck\\.ad\[sb\])?" \
+        "(p pck\\.ad\[sb\])?" \
+        "p pck.ambiguous_func" \
+        "p pck.external_identical_one" \
+        "(p pck.inner)?" \
+        "p pck.inner.inside_variable" \
+        "p pck.internal_capitalized" \
+        "p pck.local_identical_one" \
+        "p pck.local_identical_two" \
+        "p pck.my_global_variable" \
+        "p pck.proc" ]
 
 # Complete a mangled symbol name, but using the '<...>' notation.
 test_gdb_complete "<pck__my" \