]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/shell.exp
719435d4eb55bc3af88470a49559ee991b6e77a7
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / shell.exp
1 # Copyright 2011-2019 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 # Test that the "shell", "!", "|" and "pipe" commands work.
17
18 load_lib completion-support.exp
19
20 gdb_exit
21 gdb_start
22
23 gdb_test "shell echo foo" "foo"
24
25 gdb_test "! echo foo" "foo"
26 gdb_test "!echo foo" "foo"
27
28 # Convenience variables with shell command.
29 gdb_test_no_output "! exit 0"
30 gdb_test "p \$_shell_exitcode" " = 0" "shell success exitcode"
31 gdb_test "p \$_shell_exitsignal" " = void" "shell success exitsignal"
32
33 gdb_test_no_output "! exit 1"
34 gdb_test "p \$_shell_exitcode" " = 1" "shell fail exitcode"
35 gdb_test "p \$_shell_exitsignal" " = void" "shell fail exitsignal"
36
37 gdb_test_no_output "! kill -2 $$"
38 gdb_test "p \$_shell_exitcode" " = void" "shell interrupt exitcode"
39 gdb_test "p \$_shell_exitsignal" " = 2" "shell interrupt exitsignal"
40
41 # Define the user command "foo", used to test "pipe" command.
42 gdb_test_multiple "define foo" "define foo" {
43 -re "End with" {
44 pass "define foo"
45 }
46 }
47 gdb_test \
48 [multi_line_input \
49 { echo coucou\n }\
50 { echo truc\n }\
51 { echo machin\n }\
52 { if $argc > 0 }\
53 { echo $arg0\n}\
54 {end}\
55 {end}] \
56 "" \
57 "enter commands"
58
59
60 gdb_test "pipe foo | wc -l" "3" "simple pipe"
61 gdb_test "pipe foo brol| wc -l" "4" "simple pipe with arg"
62 gdb_test "pipe foo truc2 | grep truc | wc -l" "2" "double pipe"
63
64 gdb_test "| foo truc2 | grep truc | wc -l" "2" "double pipe, pipe char"
65 gdb_test "|foo|grep truc|wc -l" "1" "no space around pipe char"
66
67 gdb_test "echo coucou\\n" "coucou" "echo coucou"
68 gdb_test "||wc -l" "1" "repeat previous command"
69
70 gdb_test "| -d ! echo this contains a | character\\n ! sed -e 's/|/PIPE/'" \
71 "this contains a PIPE character" "alternate 1char delim"
72
73 gdb_test "|-d ! echo this contains a | character\\n!sed -e 's/|/PIPE/'" \
74 "this contains a PIPE character" "alternate 1char delim, no space"
75
76 gdb_test "| -d !!! echo this contains a | character\\n !!! sed -e 's/|/PIPE/'" \
77 "this contains a PIPE character" "alternate 3char delim"
78
79 gdb_test "|-d !!! echo this contains a | character\\n!!!sed -e 's/|/PIPE/'" \
80 "this contains a PIPE character" "alternate 3char delim, no space"
81
82 # Convenience variables with pipe command.
83 gdb_test "|p 123| exit 0" ""
84 gdb_test "p \$_shell_exitcode" " = 0" "pipe success exitcode"
85 gdb_test "p \$_shell_exitsignal" " = void" "pipe success exitsignal"
86
87 gdb_test "|p 123| exit 1" ""
88 gdb_test "p \$_shell_exitcode" " = 1" "pipe fail exitcode"
89 gdb_test "p \$_shell_exitsignal" " = void" "pipe fail exitsignal"
90
91 gdb_test "|p 123| kill -2 $$" ""
92 gdb_test "p \$_shell_exitcode" " = void" "pipe interrupt exitcode"
93 gdb_test "p \$_shell_exitsignal" " = 2" "pipe interrupt exitsignal"
94
95 # Error handling verifications.
96 gdb_test "|" "Missing COMMAND" "all missing"
97 gdb_test "|-d" "-d requires an argument" "-d value missing"
98 gdb_test "|-d " "-d requires an argument" "-d spaces value missing"
99 gdb_test "| echo coucou" \
100 "Missing delimiter before SHELL_COMMAND" \
101 "| delimiter missing"
102 gdb_test "|-d DELIM echo coucou" \
103 "Missing delimiter before SHELL_COMMAND" \
104 "DELIM delimiter missing"
105 gdb_test "|echo coucou|" \
106 "Missing SHELL_COMMAND" \
107 "SHELL_COMMAND missing"
108 gdb_test "|-d ! echo coucou !" \
109 "Missing SHELL_COMMAND" \
110 "SHELL_COMMAND missing with delimiter"
111 gdb_test "|-d! echo coucou ! wc" \
112 "Missing delimiter before SHELL_COMMAND" \
113 "delimiter missing due to missing space"
114
115 # Completion tests.
116
117 test_gdb_complete_unique \
118 "pipe" \
119 "pipe"
120
121 # Note that unlike "pipe", "|" doesn't require a space. This checks
122 # that completion behaves that way too.
123 foreach cmd {"pipe " "| " "|"} {
124 test_gdb_completion_offers_commands "$cmd"
125
126 # There's only one option.
127 test_gdb_complete_unique \
128 "${cmd}-" \
129 "${cmd}-d"
130
131 # Cannot complete "-d"'s argument.
132 test_gdb_complete_none "${cmd}-d "
133 test_gdb_complete_none "${cmd}-d main"
134
135 # Check completing a GDB command, with and without -d.
136 test_gdb_complete_unique \
137 "${cmd}maint set test-se" \
138 "${cmd}maint set test-settings"
139 test_gdb_complete_unique \
140 "${cmd}-d XXX maint set test-se" \
141 "${cmd}-d XXX maint set test-settings"
142
143 # Check that GDB doesn't try to complete the shell command.
144 test_gdb_complete_none \
145 "${cmd}print 1 | "
146
147 # Same, while making sure that the completer understands "-d".
148 test_gdb_complete_unique \
149 "${cmd}-d XXX maint set" \
150 "${cmd}-d XXX maint set"
151 test_gdb_complete_none \
152 "${cmd}-d set maint set"
153 test_gdb_complete_none \
154 "${cmd}-d set maint set "
155 }