]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-prompt.exp
Eliminate spurious returns from the test suite
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-prompt.exp
CommitLineData
213516ef 1# Copyright (C) 2011-2023 Free Software Foundation, Inc.
7d8e6458 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 is part of the GDB testsuite. It tests the mechanism
17# for defining the prompt in Python.
18
b4a58790 19standard_testfile
7d8e6458 20
7d8e6458 21load_lib gdb-python.exp
22load_lib prompt.exp
23
d82e5429 24require allow_python_tests
7d8e6458 25
b4a58790 26if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} {
7d8e6458 27 return -1
28}
29
30global GDBFLAGS
31set saved_gdbflags $GDBFLAGS
32set GDBFLAGS [concat $GDBFLAGS " -ex \"set height 0\""]
33set GDBFLAGS [concat $GDBFLAGS " -ex \"set width 0\""]
34set GDBFLAGS [concat $GDBFLAGS " -ex \"python p = list()\""]
35set prompt_func "python def foo(x): global p; p.append(x); return \'(Foo) \'"
36set GDBFLAGS [concat $GDBFLAGS " -ex \"$prompt_func\""]
37set GDBFLAGS [concat $GDBFLAGS " -ex \"python gdb.prompt_hook=foo\""]
38
39set tmp_gdbflags $GDBFLAGS
40set gdb_prompt_fail $gdb_prompt
41
42global gdb_prompt
43# Does not include the space at the end of the prompt.
44# gdb_test expects it not to be there.
45set gdb_prompt "\[(\]Foo\[)\]"
46
e3e48d8f
AB
47with_test_prefix "set editing on" {
48 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""]
49 prompt_gdb_start
50 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
51 ".*prompt is \"$gdb_prompt \".*" \
52 "show prompt gets the correct result"
53 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
54 "retrieving the prompt causes no extra prompt_hook calls"
55 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
56 "prompt_hook argument is default prompt."
57 gdb_exit
58}
7d8e6458 59
e3e48d8f
AB
60with_test_prefix "set editing off" {
61 set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""]
62 prompt_gdb_start
63 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
64 ".*prompt is \"$gdb_prompt \".*" \
65 "show prompt gets the correct result 2"
66 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
67 "retrieving the prompt causes no extra prompt_hook calls 2"
68 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
69 "prompt_hook argument is default prompt. 2"
70 gdb_exit
71}
7d8e6458 72
60b3033e 73if {![can_spawn_for_attach]} {
3d230f71 74 set GDBFLAGS $saved_gdbflags
60b3033e
PA
75 return 0
76}
77
2c8c5d37
PA
78set test_spawn_id [spawn_wait_for_attach $binfile]
79set testpid [spawn_id_get_pid $test_spawn_id]
7d8e6458 80
329ea579 81set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
7d8e6458 82set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
83set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
84set GDBFLAGS [concat $GDBFLAGS " -ex \"continue&\""]
85
86# sync_execution = 1 is_running = 1
e3e48d8f
AB
87with_test_prefix "sync_execution = 1, is_running = 1" {
88 prompt_gdb_start
89 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
90 ".*prompt is \"$gdb_prompt \".*" \
91 "show prompt gets the correct result 3"
92 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
93 "retrieving the prompt causes no extra prompt_hook calls 3"
94 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
95 "prompt_hook argument is default prompt. 3"
96 gdb_exit
97}
7d8e6458 98
329ea579 99set GDBFLAGS [concat $tmp_gdbflags " -ex \"set pagination off\""]
7d8e6458 100set GDBFLAGS [concat $GDBFLAGS " -ex \"set editing on\""]
101set GDBFLAGS [concat $GDBFLAGS " -ex \"attach $testpid\""]
102set GDBFLAGS [concat $GDBFLAGS " -ex \"interrupt\""]
103
104# sync_execution = 1 is_running = 0
e3e48d8f
AB
105with_test_prefix "sync_execution = 1, is_running = 0" {
106 prompt_gdb_start
107 gdb_test "python x = len(p); print (gdb.execute(\"show prompt\", to_string = True))" \
108 ".*prompt is \"$gdb_prompt \".*" \
109 "show prompt gets the correct result 4"
110 gdb_test "python print ('%d %d' % (x, len(p)))" "1 2" \
111 "retrieving the prompt causes no extra prompt_hook calls 4"
112 gdb_test "python print (\"'\" + str(p\[0\]) + \"'\")" "'$gdb_prompt_fail '" \
113 "prompt_hook argument is default prompt. 4"
114 gdb_exit
115}
7d8e6458 116
117set GDBFLAGS $saved_gdbflags
2c8c5d37 118kill_wait_spawned_process $test_spawn_id