xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.mi/mi-complete.exp (revision 7bdf38e5b7a28439665f2fdeff81e36913eef7dd)
1# Copyright 2018-2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Verify GDB/MI -complete in various scenarios. This test only tests
17# -complete command, not the correctness of completions.
18
19load_lib mi-support.exp
20set MIFLAGS "-i=mi"
21
22standard_testfile .cc
23
24if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
25     untested "failed to compile"
26     return -1
27}
28
29mi_clean_restart $binfile
30
31mi_runto_main
32
33mi_gdb_test "1-complete br" \
34            "1\\^done,completion=\"break\",matches=\\\[.*\"break\",.*\"break-range\".*\\\],max_completions_reached=\"0\"" \
35            "-complete br"
36
37# Check empty completion list.
38mi_gdb_test "5-complete bogus" \
39            "5\\^done,matches=\\\[\\\],max_completions_reached=\"0\"" \
40            "-complete bogus"
41
42# Check completions for commands with space.
43mi_gdb_test "4-complete \"b mai\"" \
44            "4\\^done,completion=\"b main\",matches=\\\[.*\"b main\".*\\\],max_completions_reached=\"0\"" \
45            "-complete \"b mai\""
46
47# Check wildmatching.
48mi_gdb_test "5-complete \"b push_ba\"" \
49            "5\\^done,completion=\"b push_back\\(\",matches=\\\[.*\"b A::push_back\\(void\\*\\)\".*\\\],max_completions_reached=\"0\"" \
50            "-complete \"b push_ba\", wildmatching"
51
52mi_gdb_test "-info-gdb-mi-command complete" \
53            "\\^done,command=\{exists=\"true\"\}" \
54            "-info-gdb-mi-command complete"
55
56# Limit max completions and check that max_completions_reached=\"0\" is set
57# to 1.
58mi_gdb_test "set max-completions 1" ".*=cmd-param-changed.*\\^done" \
59    "set max-completions 1"
60
61mi_gdb_test "2-complete br" \
62            ".*2\\^done,completion=\"br\[A-Za-z0-9-\]+\",matches=\\\[\"br\[A-Za-z0-9-\]+\"\\\],max_completions_reached=\"1\"" \
63            "-complete br, max-completions 1"
64
65# Disable completions and check an error is returned
66mi_gdb_test "set max-completions 0" ".*=cmd-param-changed.*\\^done" \
67    "set max-completions 0"
68
69mi_gdb_test "3-complete br" \
70            ".*3\\^error,msg=\".*" \
71            "-complete br, max-completions 0"
72