packaging: Add python3-base dependency
[platform/upstream/gdb.git] / gdb / testsuite / gdb.base / readline.exp
1 # Copyright 2002-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 # This file was written by Tom Tromey <tromey@redhat.com>
17
18 # This file is part of the gdb testsuite.
19
20 #
21 # Tests for readline operations.
22 #
23
24 # This function is used to test operate-and-get-next.
25 # NAME is the name of the test.
26 # ARGS is a list of alternating commands and expected results.
27 proc operate_and_get_next {name args} {
28   global gdb_prompt
29
30   set my_gdb_prompt "($gdb_prompt| >)"
31
32   set reverse {}
33   foreach {item result} $args {
34     verbose "sending $item"
35     sleep 1
36
37     # We can't use gdb_test here because we might see a " >" prompt.
38     set status 0
39     send_gdb "$item\n"
40     gdb_expect {
41       -re "$item" {
42         # Ok
43       }
44       timeout {
45         set status 1
46       }
47     }
48
49     if {! $status} {
50       gdb_expect {
51         -re "$result" {
52           # Ok.
53         }
54         timeout {
55           set status 1
56         }
57       }
58     }
59
60     if {$status} {
61       fail "$name - send $item"
62       return 0
63     }
64     pass "$name - send $item"
65
66     set reverse [linsert $reverse 0 $item $result]
67   }
68
69   # Now use C-p to go back to the start.
70   foreach {item result} $reverse {
71     # Actually send C-p followed by C-l.  This lets us recognize the
72     # command when gdb prints it again.
73     send_gdb "\x10\x0c"
74     set status 0
75     gdb_expect {
76       -re "$item" {
77         # Ok
78       }
79       timeout {
80         set status 1
81       }
82     }
83     if {$status} {
84       fail "$name - C-p to $item"
85       return 0
86     }
87     pass "$name - C-p to $item"
88   }
89
90   # Now C-o through the list.  Don't send the command, since it is
91   # already there.  Strip off the first command from the list so we
92   # can see the next command inside the loop.
93   set count 0
94   foreach {item result} $args {
95     set status 0
96
97     # If this isn't the first item, make sure we see the command at
98     # the prompt.
99     if {$count > 0} {
100       gdb_expect {
101         -re ".*$item" {
102           # Ok
103         }
104         timeout {
105           set status 1
106         }
107       }
108     }
109
110     if {! $status} {
111       # For the last item, send a simple \n instead of C-o.
112       if {$count == [llength $args] - 2} {
113         send_gdb "\n"
114       } else {
115         # 15 is C-o.
116         send_gdb [format %c 15]
117       }
118       set status 0
119       gdb_expect {
120         -re "$result" {
121           # Ok
122         }
123         timeout {
124           set status 1
125         }
126       }
127     }
128
129     if {$status} {
130       fail "$name - C-o for $item"
131       return 0
132     }
133     pass "$name - C-o for $item"
134
135     set count [expr {$count + 2}]
136   }
137
138   # Match the prompt so the next test starts at the right place.
139   gdb_test "" ".*" "$name - final prompt"
140
141   return 1
142 }
143
144 save_vars { env(TERM) } {
145     # The arrow key test relies on the standard VT100 bindings, so
146     # make sure that an appropriate terminal is selected.  The same
147     # bug doesn't show up if we use ^P / ^N instead.
148     setenv TERM vt100
149
150     gdb_start
151     gdb_reinitialize_dir $srcdir/$subdir
152
153     if { ![readline_is_used] } {
154         unsupported "readline isn't used."
155         return -1
156     }
157
158     save_vars { timeout env(GDBHISTSIZE) env(GDBHISTFILE) } {
159         set timeout 30
160
161         # A simple test of operate-and-get-next.
162         operate_and_get_next "Simple operate-and-get-next" \
163             "p 1" ".* = 1" \
164             "p 2" ".* = 2" \
165             "p 3" ".* = 3"
166
167         # Test operate-and-get-next with a secondary prompt.
168         operate_and_get_next "operate-and-get-next with secondary prompt" \
169             "if 1 > 0" "" \
170             "p 5" "" \
171             "end" ".* = 5"
172
173         # Verify that arrow keys work in secondary prompts.  The control
174         # sequence is a hard-coded VT100 up arrow.
175         gdb_test "print 42" "\\\$\[0-9\]* = 42"
176         set msg "arrow keys with secondary prompt"
177         gdb_test_multiple "if 1 > 0\n\033\[A\033\[A\nend" $msg {
178             -re ".*\\\$\[0-9\]* = 42\r\n$gdb_prompt $" {
179                 pass $msg
180             }
181             -re ".*Undefined command:.*$gdb_prompt $" {
182                 fail $msg
183             }
184         }
185
186         # Use the up arrow to select a previous command.  Check that
187         # no unexpected output is added between the previously
188         # selected command, and the output of that command.
189         gdb_test "print 123" "\\\$\[0-9\]* = 123"
190         gdb_test_multiple "\033\[A" "use up arrow" {
191             -re -wrap "print 123\r\n\\\$\[0-9\]* = 123" {
192                 pass $gdb_test_name
193             }
194         }
195
196         # Now repeat the first test with a history file that fills the entire
197         # history list.
198
199         set env(GDBHISTFILE) "${srcdir}/${subdir}/gdb_history"
200         set env(GDBHISTSIZE) "10"
201
202         gdb_exit
203         gdb_start
204         gdb_reinitialize_dir $srcdir/$subdir
205
206         operate_and_get_next "Simple operate-and-get-next, two" \
207             "p 7" ".* = 7" \
208             "p 8" ".* = 8" \
209             "p 9" ".* = 9"
210     }
211 }