]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2011-2024 Free Software Foundation, Inc. |
ed59ded5 DE |
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 | ||
708dc93e | 16 | # Test that the "shell", "!", "|" and "pipe" commands work. |
ed59ded5 | 17 | |
5f4ba3e7 PA |
18 | load_lib completion-support.exp |
19 | ||
ed59ded5 DE |
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" | |
708dc93e PW |
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 | ||
5597c940 SL |
37 | # This test will not work when the shell is CMD.EXE. |
38 | if { ! [ishost *-*-mingw*] } { | |
39 | gdb_test_no_output "! kill -2 $$" | |
40 | gdb_test "p \$_shell_exitcode" " = void" "shell interrupt exitcode" | |
41 | gdb_test "p \$_shell_exitsignal" " = 2" "shell interrupt exitsignal" | |
42 | } | |
708dc93e | 43 | |
91265a7d PA |
44 | # Test the $_shell convenience function. |
45 | ||
46 | with_test_prefix "\$_shell convenience function" { | |
47 | # Simple commands, check the result code. | |
48 | gdb_test "p \$_shell(\"true\")" " = 0" | |
49 | gdb_test "p \$_shell(\"false\")" " = 1" | |
50 | ||
51 | # Test command with arguments. | |
52 | gdb_test "p \$_shell(\"echo foo\")" "foo\r\n\\$${decimal} = 0" | |
53 | ||
54 | # Check the type of the result. | |
55 | gdb_test "ptype \$_shell(\"true\")" "type = int" | |
56 | ||
57 | # Test passing a non-literal string as command name. | |
58 | gdb_test "p \$cmd = \"echo bar\"" " = \"echo bar\"" | |
59 | gdb_test "p \$_shell(\$cmd)" "bar\r\n\\$${decimal} = 0" | |
60 | ||
61 | # Test executing a non-existing command. The result is | |
62 | # shell-dependent, but most (all?) POSIX-like shells return 127 in | |
63 | # this case. | |
64 | gdb_test "p \$_shell(\"non-existing-command-foo-bar-qux\")" " = 127" | |
65 | ||
66 | gdb_test "p \$_shell" \ | |
67 | " = <internal function _shell>" | |
68 | gdb_test "ptype \$_shell" \ | |
69 | "type = <internal function>" | |
70 | ||
71 | # Test error scenarios. | |
72 | gdb_test "p \$_shell()" \ | |
73 | "You must provide one argument for \\\$_shell\\\." | |
74 | gdb_test "p \$_shell(\"a\", \"b\")" \ | |
75 | "You must provide one argument for \\\$_shell\\\." | |
76 | gdb_test "p \$_shell(1)" \ | |
77 | "Argument must be a string\\\." | |
78 | } | |
79 | ||
708dc93e PW |
80 | # Define the user command "foo", used to test "pipe" command. |
81 | gdb_test_multiple "define foo" "define foo" { | |
82 | -re "End with" { | |
83 | pass "define foo" | |
84 | } | |
85 | } | |
86 | gdb_test \ | |
87 | [multi_line_input \ | |
88 | { echo coucou\n }\ | |
89 | { echo truc\n }\ | |
90 | { echo machin\n }\ | |
91 | { if $argc > 0 }\ | |
92 | { echo $arg0\n}\ | |
93 | {end}\ | |
94 | {end}] \ | |
95 | "" \ | |
96 | "enter commands" | |
97 | ||
98 | ||
99 | gdb_test "pipe foo | wc -l" "3" "simple pipe" | |
100 | gdb_test "pipe foo brol| wc -l" "4" "simple pipe with arg" | |
101 | gdb_test "pipe foo truc2 | grep truc | wc -l" "2" "double pipe" | |
102 | ||
103 | gdb_test "| foo truc2 | grep truc | wc -l" "2" "double pipe, pipe char" | |
104 | gdb_test "|foo|grep truc|wc -l" "1" "no space around pipe char" | |
105 | ||
106 | gdb_test "echo coucou\\n" "coucou" "echo coucou" | |
107 | gdb_test "||wc -l" "1" "repeat previous command" | |
108 | ||
5597c940 | 109 | gdb_test "| -d ! echo this contains a | character\\n ! sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
110 | "this contains a PIPE character" "alternate 1char delim" |
111 | ||
5597c940 | 112 | gdb_test "|-d ! echo this contains a | character\\n!sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
113 | "this contains a PIPE character" "alternate 1char delim, no space" |
114 | ||
5597c940 | 115 | gdb_test "| -d !!! echo this contains a | character\\n !!! sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
116 | "this contains a PIPE character" "alternate 3char delim" |
117 | ||
5597c940 | 118 | gdb_test "|-d !!! echo this contains a | character\\n!!!sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
119 | "this contains a PIPE character" "alternate 3char delim, no space" |
120 | ||
121 | # Convenience variables with pipe command. | |
122 | gdb_test "|p 123| exit 0" "" | |
123 | gdb_test "p \$_shell_exitcode" " = 0" "pipe success exitcode" | |
124 | gdb_test "p \$_shell_exitsignal" " = void" "pipe success exitsignal" | |
125 | ||
126 | gdb_test "|p 123| exit 1" "" | |
127 | gdb_test "p \$_shell_exitcode" " = 1" "pipe fail exitcode" | |
128 | gdb_test "p \$_shell_exitsignal" " = void" "pipe fail exitsignal" | |
129 | ||
5597c940 SL |
130 | # This test will not work when the shell is CMD.EXE. |
131 | if { ! [ishost *-*-mingw*] } { | |
132 | gdb_test "|p 123| kill -2 $$" "" | |
133 | gdb_test "p \$_shell_exitcode" " = void" "pipe interrupt exitcode" | |
134 | gdb_test "p \$_shell_exitsignal" " = 2" "pipe interrupt exitsignal" | |
135 | } | |
708dc93e PW |
136 | |
137 | # Error handling verifications. | |
138 | gdb_test "|" "Missing COMMAND" "all missing" | |
5f4ba3e7 PA |
139 | gdb_test "|-d" "-d requires an argument" "-d value missing" |
140 | gdb_test "|-d " "-d requires an argument" "-d spaces value missing" | |
708dc93e PW |
141 | gdb_test "| echo coucou" \ |
142 | "Missing delimiter before SHELL_COMMAND" \ | |
143 | "| delimiter missing" | |
144 | gdb_test "|-d DELIM echo coucou" \ | |
145 | "Missing delimiter before SHELL_COMMAND" \ | |
146 | "DELIM delimiter missing" | |
147 | gdb_test "|echo coucou|" \ | |
148 | "Missing SHELL_COMMAND" \ | |
149 | "SHELL_COMMAND missing" | |
150 | gdb_test "|-d ! echo coucou !" \ | |
151 | "Missing SHELL_COMMAND" \ | |
152 | "SHELL_COMMAND missing with delimiter" | |
153 | gdb_test "|-d! echo coucou ! wc" \ | |
154 | "Missing delimiter before SHELL_COMMAND" \ | |
155 | "delimiter missing due to missing space" | |
156 | ||
5f4ba3e7 PA |
157 | # Completion tests. |
158 | ||
159 | test_gdb_complete_unique \ | |
160 | "pipe" \ | |
161 | "pipe" | |
162 | ||
163 | # Note that unlike "pipe", "|" doesn't require a space. This checks | |
164 | # that completion behaves that way too. | |
165 | foreach cmd {"pipe " "| " "|"} { | |
166 | test_gdb_completion_offers_commands "$cmd" | |
167 | ||
168 | # There's only one option. | |
169 | test_gdb_complete_unique \ | |
170 | "${cmd}-" \ | |
171 | "${cmd}-d" | |
172 | ||
173 | # Cannot complete "-d"'s argument. | |
174 | test_gdb_complete_none "${cmd}-d " | |
175 | test_gdb_complete_none "${cmd}-d main" | |
176 | ||
177 | # Check completing a GDB command, with and without -d. | |
178 | test_gdb_complete_unique \ | |
179 | "${cmd}maint set test-se" \ | |
180 | "${cmd}maint set test-settings" | |
181 | test_gdb_complete_unique \ | |
182 | "${cmd}-d XXX maint set test-se" \ | |
183 | "${cmd}-d XXX maint set test-settings" | |
184 | ||
185 | # Check that GDB doesn't try to complete the shell command. | |
186 | test_gdb_complete_none \ | |
187 | "${cmd}print 1 | " | |
188 | ||
189 | # Same, while making sure that the completer understands "-d". | |
190 | test_gdb_complete_unique \ | |
191 | "${cmd}-d XXX maint set" \ | |
192 | "${cmd}-d XXX maint set" | |
193 | test_gdb_complete_none \ | |
194 | "${cmd}-d set maint set" | |
195 | test_gdb_complete_none \ | |
196 | "${cmd}-d set maint set " | |
197 | } |