Add max-completions parameter, and implement tab-completion limiting.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.linespec / ls-errs.exp
CommitLineData
32d0add0 1# Copyright 2012-2015 Free Software Foundation, Inc.
40e084e1
KS
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# Tests for linespec error conditions
17
f91e3dc1
TT
18standard_testfile
19set exefile $testfile
40e084e1
KS
20
21if {[prepare_for_testing $testfile $exefile $srcfile \
22 {debug nowarnings}]} {
23 return -1
24}
25
26# Turn off the pending breakpoint queries.
27gdb_test_no_output "set breakpoint pending off"
28
ef0b411a
GB
29# Turn off completion limiting
30gdb_test_no_output "set max-completions unlimited"
31
40e084e1
KS
32# We intentionally do not use gdb_breakpoint for these tests.
33
c2e827ad
DB
34# Break at 'linespec' and expect the message in ::error_messages indexed by
35# msg_id with the associated args.
36proc test_break {linespec msg_id args} {
40e084e1 37 global error_messages
40e084e1 38
c2e827ad 39 gdb_test "break $linespec" [string_to_regexp \
40e084e1
KS
40 [eval format \$error_messages($msg_id) $args]]
41}
42
43# Common error message format strings.
44array set error_messages {
45 invalid_file "No source file named %s."
46 invalid_function "Function \"%s\" not defined."
47 invalid_var_or_func "Undefined convenience variable or function \"%s\" not defined."
48 invalid_function_f "Function \"%s\" not defined in \"%s\"."
49 invalid_var_or_func_f \
50 "Undefined convenience variable or function \"%s\" not defined in \"%s\"."
51 invalid_label "No label \"%s\" defined in function \"%s\"."
52 invalid_offset "No line %d in the current file."
53 invalid_offset_f "No line %d in file \"%s\"."
54 unexpected "malformed linespec error: unexpected %s"
55 unexpected_opt "malformed linespec error: unexpected %s, \"%s\""
56 unmatched_quote "unmatched quote"
57}
58
59# Some commonly used whitespace tests around ':'.
60set spaces [list ":" ": " " :" " : " "\t: " " :\t" "\t:\t" " \t:\t " \
61 "\t \t:\t \t \t"]
62
63# A list of invalid offsets.
64set invalid_offsets [list -100 +500 1000]
65
40e084e1
KS
66# Try some simple, invalid linespecs involving spaces.
67foreach x $spaces {
c2e827ad 68 test_break $x unexpected "colon"
40e084e1
KS
69}
70
71# Test invalid filespecs starting with offset. This is done
72# first so that default offsets are tested.
73foreach x $invalid_offsets {
74 set offset $x
75
76 # Relative offsets are relative to line 16. Adjust
77 # expected offset from error message accordingly.
78 if {[string index $x 0] == "+" ||
79 [string index $x 0] == "-"} {
80 incr offset 16
81 }
c2e827ad 82 test_break $x invalid_offset $offset
40e084e1
KS
83}
84
85# Test offsets with trailing tokens w/ and w/o spaces.
86foreach x $spaces {
c2e827ad
DB
87 test_break "3$x" unexpected "colon"
88 test_break "+10$x" unexpected "colon"
89 test_break "-10$x" unexpected "colon"
40e084e1
KS
90}
91
92foreach x {1 +1 +100 -10} {
c2e827ad
DB
93 test_break "3 $x" unexpected_opt "number" $x
94 test_break "+10 $x" unexpected_opt "number" $x
95 test_break "-10 $x" unexpected_opt "number" $x
40e084e1
KS
96}
97
c2e827ad
DB
98test_break "3 foo" unexpected_opt "string" "foo"
99test_break "+10 foo" unexpected_opt "string" "foo"
100test_break "-10 foo" unexpected_opt "string" "foo"
40e084e1
KS
101
102# Test invalid linespecs starting with filename.
103foreach x [list "this_file_doesn't_exist.c" \
104 "this file has spaces.c" \
105 "\"file::colons.c\"" \
106 "'file::colons.c'" \
107 "\"this \"file\" has quotes.c\"" \
108 "'this \"file\" has quotes.c'" \
109 "'this 'file' has quotes.c'" \
f3b5e280
KS
110 "\"this 'file' has quotes.c\"" \
111 "\"spaces: and :colons.c\"" \
112 "'more: :spaces: :and colons::.c'"] {
40e084e1 113 # Remove any quoting from FILENAME for the error message.
c2e827ad 114 test_break "$x:3" invalid_file [string trim $x \"']
40e084e1
KS
115}
116
117# Test unmatched quotes.
118foreach x {"\"src-file.c'" "'src-file.c"} {
c2e827ad 119 test_break "$x:3" unmatched_quote
40e084e1
KS
120}
121
c2e827ad 122test_break $srcfile invalid_function $srcfile
40e084e1
KS
123foreach x {"foo" " foo" " foo "} {
124 # Trim any leading/trailing whitespace for error messages.
c2e827ad
DB
125 test_break "$srcfile:$x" invalid_function_f [string trim $x] $srcfile
126 test_break "$srcfile:main:$x" invalid_label [string trim $x] "main"
40e084e1
KS
127}
128
129foreach x $spaces {
c2e827ad
DB
130 test_break "$srcfile$x" unexpected "end of input"
131 test_break "$srcfile:main$x" unexpected "end of input"
40e084e1
KS
132}
133
c2e827ad
DB
134test_break "${srcfile}::" invalid_function "${srcfile}::"
135test_break "$srcfile:3 1" unexpected_opt "number" "1"
136test_break "$srcfile:3 +100" unexpected_opt "number" "+100"
137test_break "$srcfile:3 -100" unexpected_opt "number" "-100"
138test_break "$srcfile:3 foo" unexpected_opt "string" "foo"
40e084e1
KS
139
140foreach x $invalid_offsets {
c2e827ad
DB
141 test_break "$srcfile:$x" invalid_offset_f $x $srcfile
142 test_break "\"$srcfile:$x\"" invalid_offset_f $x $srcfile
143 test_break "'$srcfile:$x'" invalid_offset_f $x $srcfile
40e084e1
KS
144}
145
146# Test invalid filespecs starting with function.
147foreach x {"foobar" "foo::bar" "foo.bar" "foo ." "foo bar" "foo 1" \
148 "foo 0" "foo +10" "foo -10" "foo +100" "foo -100"} {
c2e827ad 149 test_break $x invalid_function $x
40e084e1
KS
150}
151
152foreach x $spaces {
c2e827ad
DB
153 test_break "main${x}there" invalid_label "there" "main"
154 if {[test_compiler_info {clang-*-*}]} { setup_xfail clang/14500 *-*-* }
155 test_break "main:here${x}" unexpected "end of input"
40e084e1
KS
156}
157
c2e827ad
DB
158test_break "main 3" invalid_function "main 3"
159test_break "main +100" invalid_function "main +100"
160test_break "main -100" invalid_function "main -100"
161test_break "main foo" invalid_function "main foo"
40e084e1
KS
162
163foreach x {"3" "+100" "-100" "foo"} {
c2e827ad 164 test_break "main:here $x" invalid_label "here $x" "main"
40e084e1
KS
165}
166
167foreach x {"if" "task" "thread"} {
c2e827ad 168 test_break $x invalid_function $x
40e084e1
KS
169}
170
c2e827ad
DB
171test_break "'main.c'flubber" unexpected_opt "string" "flubber"
172test_break "'main.c',21" invalid_function "main.c"
173test_break "'main.c' " invalid_function "main.c"
174test_break "'main.c'3" unexpected_opt "number" "3"
175test_break "'main.c'+3" unexpected_opt "number" "+3"
40e084e1
KS
176
177# Test undefined convenience variables.
178set x {$zippo}
c2e827ad
DB
179test_break $x invalid_var_or_func $x
180test_break "$srcfile:$x" invalid_var_or_func_f $x $srcfile
This page took 0.376917 seconds and 4 git commands to generate.