Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2011-2022 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 PW |
43 | |
44 | # Define the user command "foo", used to test "pipe" command. | |
45 | gdb_test_multiple "define foo" "define foo" { | |
46 | -re "End with" { | |
47 | pass "define foo" | |
48 | } | |
49 | } | |
50 | gdb_test \ | |
51 | [multi_line_input \ | |
52 | { echo coucou\n }\ | |
53 | { echo truc\n }\ | |
54 | { echo machin\n }\ | |
55 | { if $argc > 0 }\ | |
56 | { echo $arg0\n}\ | |
57 | {end}\ | |
58 | {end}] \ | |
59 | "" \ | |
60 | "enter commands" | |
61 | ||
62 | ||
63 | gdb_test "pipe foo | wc -l" "3" "simple pipe" | |
64 | gdb_test "pipe foo brol| wc -l" "4" "simple pipe with arg" | |
65 | gdb_test "pipe foo truc2 | grep truc | wc -l" "2" "double pipe" | |
66 | ||
67 | gdb_test "| foo truc2 | grep truc | wc -l" "2" "double pipe, pipe char" | |
68 | gdb_test "|foo|grep truc|wc -l" "1" "no space around pipe char" | |
69 | ||
70 | gdb_test "echo coucou\\n" "coucou" "echo coucou" | |
71 | gdb_test "||wc -l" "1" "repeat previous command" | |
72 | ||
5597c940 | 73 | gdb_test "| -d ! echo this contains a | character\\n ! sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
74 | "this contains a PIPE character" "alternate 1char delim" |
75 | ||
5597c940 | 76 | gdb_test "|-d ! echo this contains a | character\\n!sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
77 | "this contains a PIPE character" "alternate 1char delim, no space" |
78 | ||
5597c940 | 79 | gdb_test "| -d !!! echo this contains a | character\\n !!! sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
80 | "this contains a PIPE character" "alternate 3char delim" |
81 | ||
5597c940 | 82 | gdb_test "|-d !!! echo this contains a | character\\n!!!sed -e \"s/|/PIPE/\"" \ |
708dc93e PW |
83 | "this contains a PIPE character" "alternate 3char delim, no space" |
84 | ||
85 | # Convenience variables with pipe command. | |
86 | gdb_test "|p 123| exit 0" "" | |
87 | gdb_test "p \$_shell_exitcode" " = 0" "pipe success exitcode" | |
88 | gdb_test "p \$_shell_exitsignal" " = void" "pipe success exitsignal" | |
89 | ||
90 | gdb_test "|p 123| exit 1" "" | |
91 | gdb_test "p \$_shell_exitcode" " = 1" "pipe fail exitcode" | |
92 | gdb_test "p \$_shell_exitsignal" " = void" "pipe fail exitsignal" | |
93 | ||
5597c940 SL |
94 | # This test will not work when the shell is CMD.EXE. |
95 | if { ! [ishost *-*-mingw*] } { | |
96 | gdb_test "|p 123| kill -2 $$" "" | |
97 | gdb_test "p \$_shell_exitcode" " = void" "pipe interrupt exitcode" | |
98 | gdb_test "p \$_shell_exitsignal" " = 2" "pipe interrupt exitsignal" | |
99 | } | |
708dc93e PW |
100 | |
101 | # Error handling verifications. | |
102 | gdb_test "|" "Missing COMMAND" "all missing" | |
5f4ba3e7 PA |
103 | gdb_test "|-d" "-d requires an argument" "-d value missing" |
104 | gdb_test "|-d " "-d requires an argument" "-d spaces value missing" | |
708dc93e PW |
105 | gdb_test "| echo coucou" \ |
106 | "Missing delimiter before SHELL_COMMAND" \ | |
107 | "| delimiter missing" | |
108 | gdb_test "|-d DELIM echo coucou" \ | |
109 | "Missing delimiter before SHELL_COMMAND" \ | |
110 | "DELIM delimiter missing" | |
111 | gdb_test "|echo coucou|" \ | |
112 | "Missing SHELL_COMMAND" \ | |
113 | "SHELL_COMMAND missing" | |
114 | gdb_test "|-d ! echo coucou !" \ | |
115 | "Missing SHELL_COMMAND" \ | |
116 | "SHELL_COMMAND missing with delimiter" | |
117 | gdb_test "|-d! echo coucou ! wc" \ | |
118 | "Missing delimiter before SHELL_COMMAND" \ | |
119 | "delimiter missing due to missing space" | |
120 | ||
5f4ba3e7 PA |
121 | # Completion tests. |
122 | ||
123 | test_gdb_complete_unique \ | |
124 | "pipe" \ | |
125 | "pipe" | |
126 | ||
127 | # Note that unlike "pipe", "|" doesn't require a space. This checks | |
128 | # that completion behaves that way too. | |
129 | foreach cmd {"pipe " "| " "|"} { | |
130 | test_gdb_completion_offers_commands "$cmd" | |
131 | ||
132 | # There's only one option. | |
133 | test_gdb_complete_unique \ | |
134 | "${cmd}-" \ | |
135 | "${cmd}-d" | |
136 | ||
137 | # Cannot complete "-d"'s argument. | |
138 | test_gdb_complete_none "${cmd}-d " | |
139 | test_gdb_complete_none "${cmd}-d main" | |
140 | ||
141 | # Check completing a GDB command, with and without -d. | |
142 | test_gdb_complete_unique \ | |
143 | "${cmd}maint set test-se" \ | |
144 | "${cmd}maint set test-settings" | |
145 | test_gdb_complete_unique \ | |
146 | "${cmd}-d XXX maint set test-se" \ | |
147 | "${cmd}-d XXX maint set test-settings" | |
148 | ||
149 | # Check that GDB doesn't try to complete the shell command. | |
150 | test_gdb_complete_none \ | |
151 | "${cmd}print 1 | " | |
152 | ||
153 | # Same, while making sure that the completer understands "-d". | |
154 | test_gdb_complete_unique \ | |
155 | "${cmd}-d XXX maint set" \ | |
156 | "${cmd}-d XXX maint set" | |
157 | test_gdb_complete_none \ | |
158 | "${cmd}-d set maint set" | |
159 | test_gdb_complete_none \ | |
160 | "${cmd}-d set maint set " | |
161 | } |