2 Test the lldb command line completion mechanism.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
13 class CommandLineCompletionTestCase(TestBase):
15 mydir = TestBase.compute_mydir(__file__)
18 def classCleanup(cls):
19 """Cleanup the test byproducts."""
21 os.remove("child_send.txt")
22 os.remove("child_read.txt")
26 @expectedFailureHostWindows("llvm.org/pr24679")
27 @skipIfFreeBSD # timing out on the FreeBSD buildbot
30 """Test that 'at' completes to 'attach '."""
31 self.complete_from_to('at', 'attach ')
33 @expectedFailureHostWindows("llvm.org/pr24679")
34 @skipIfFreeBSD # timing out on the FreeBSD buildbot
37 """Test that 'de' completes to 'detach '."""
38 self.complete_from_to('de', 'detach ')
40 @expectedFailureHostWindows("llvm.org/pr24679")
41 @skipIfFreeBSD # timing out on the FreeBSD buildbot
43 def test_process_attach_dash_dash_con(self):
44 """Test that 'process attach --con' completes to 'process attach --continue '."""
45 self.complete_from_to('process attach --con', 'process attach --continue ')
47 # <rdar://problem/11052829>
48 @expectedFailureHostWindows("llvm.org/pr24679")
49 @skipIfFreeBSD # timing out on the FreeBSD buildbot
51 def test_infinite_loop_while_completing(self):
52 """Test that 'process print hello\' completes to itself and does not infinite loop."""
53 self.complete_from_to('process print hello\\', 'process print hello\\',
54 turn_off_re_match=True)
56 @expectedFailureHostWindows("llvm.org/pr24679")
57 @skipIfFreeBSD # timing out on the FreeBSD buildbot
59 def test_watchpoint_co(self):
60 """Test that 'watchpoint co' completes to 'watchpoint command '."""
61 self.complete_from_to('watchpoint co', 'watchpoint command ')
63 @expectedFailureHostWindows("llvm.org/pr24679")
64 @skipIfFreeBSD # timing out on the FreeBSD buildbot
66 def test_watchpoint_command_space(self):
67 """Test that 'watchpoint command ' completes to ['Available completions:', 'add', 'delete', 'list']."""
68 self.complete_from_to('watchpoint command ', ['Available completions:', 'add', 'delete', 'list'])
70 @expectedFailureHostWindows("llvm.org/pr24679")
71 @skipIfFreeBSD # timing out on the FreeBSD buildbot
73 def test_watchpoint_command_a(self):
74 """Test that 'watchpoint command a' completes to 'watchpoint command add '."""
75 self.complete_from_to('watchpoint command a', 'watchpoint command add ')
77 @expectedFailureHostWindows("llvm.org/pr24679")
78 @skipIfFreeBSD # timing out on the FreeBSD buildbot
80 def test_watchpoint_set_variable_dash_w(self):
81 """Test that 'watchpoint set variable -w' completes to 'watchpoint set variable -w '."""
82 self.complete_from_to('watchpoint set variable -w', 'watchpoint set variable -w ')
84 @expectedFailureHostWindows("llvm.org/pr24679")
85 @skipIfFreeBSD # timing out on the FreeBSD buildbot
87 def test_watchpoint_set_variable_dash_w_space(self):
88 """Test that 'watchpoint set variable -w ' completes to ['Available completions:', 'read', 'write', 'read_write']."""
89 self.complete_from_to('watchpoint set variable -w ', ['Available completions:', 'read', 'write', 'read_write'])
91 @expectedFailureHostWindows("llvm.org/pr24679")
92 @skipIfFreeBSD # timing out on the FreeBSD buildbot
94 def test_watchpoint_set_ex(self):
95 """Test that 'watchpoint set ex' completes to 'watchpoint set expression '."""
96 self.complete_from_to('watchpoint set ex', 'watchpoint set expression ')
98 @expectedFailureHostWindows("llvm.org/pr24679")
99 @skipIfFreeBSD # timing out on the FreeBSD buildbot
101 def test_watchpoint_set_var(self):
102 """Test that 'watchpoint set var' completes to 'watchpoint set variable '."""
103 self.complete_from_to('watchpoint set var', 'watchpoint set variable ')
105 @expectedFailureHostWindows("llvm.org/pr24679")
106 @skipIfFreeBSD # timing out on the FreeBSD buildbot
108 def test_watchpoint_set_variable_dash_w_read_underbar(self):
109 """Test that 'watchpoint set variable -w read_' completes to 'watchpoint set variable -w read_write'."""
110 self.complete_from_to('watchpoint set variable -w read_', 'watchpoint set variable -w read_write')
112 @expectedFailureHostWindows("llvm.org/pr24679")
113 @skipIfFreeBSD # timing out on the FreeBSD buildbot
115 def test_help_fi(self):
116 """Test that 'help fi' completes to ['Available completions:', 'file', 'finish']."""
117 self.complete_from_to('help fi', ['Available completions:', 'file', 'finish'])
119 @expectedFailureHostWindows("llvm.org/pr24679")
120 @skipIfFreeBSD # timing out on the FreeBSD buildbot
122 def test_help_watchpoint_s(self):
123 """Test that 'help watchpoint s' completes to 'help watchpoint set '."""
124 self.complete_from_to('help watchpoint s', 'help watchpoint set ')
126 @expectedFailureHostWindows("llvm.org/pr24679")
127 @skipIfFreeBSD # timing out on the FreeBSD buildbot
129 def test_settings_append_target_er(self):
130 """Test that 'settings append target.er' completes to 'settings append target.error-path'."""
131 self.complete_from_to('settings append target.er', 'settings append target.error-path')
133 @expectedFailureHostWindows("llvm.org/pr24679")
134 @skipIfFreeBSD # timing out on the FreeBSD buildbot
136 def test_settings_insert_after_target_en(self):
137 """Test that 'settings insert-after target.env' completes to 'settings insert-after target.env-vars'."""
138 self.complete_from_to('settings insert-after target.env', 'settings insert-after target.env-vars')
140 @expectedFailureHostWindows("llvm.org/pr24679")
141 @skipIfFreeBSD # timing out on the FreeBSD buildbot
143 def test_settings_insert_before_target_en(self):
144 """Test that 'settings insert-before target.env' completes to 'settings insert-before target.env-vars'."""
145 self.complete_from_to('settings insert-before target.env', 'settings insert-before target.env-vars')
147 @expectedFailureHostWindows("llvm.org/pr24679")
148 @skipIfFreeBSD # timing out on the FreeBSD buildbot
150 def test_settings_replace_target_ru(self):
151 """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'."""
152 self.complete_from_to('settings replace target.ru', 'settings replace target.run-args')
154 @expectedFailureHostWindows("llvm.org/pr24679")
155 @skipIfFreeBSD # timing out on the FreeBSD buildbot
157 def test_settings_s(self):
158 """Test that 'settings s' completes to ['Available completions:', 'set', 'show']."""
159 self.complete_from_to('settings s', ['Available completions:', 'set', 'show'])
161 @expectedFailureHostWindows("llvm.org/pr24679")
162 @skipIfFreeBSD # timing out on the FreeBSD buildbot
164 def test_settings_set_th(self):
165 """Test that 'settings set th' completes to 'settings set thread-format'."""
166 self.complete_from_to('settings set th', 'settings set thread-format')
168 @expectedFailureHostWindows("llvm.org/pr24679")
169 @skipIfFreeBSD # timing out on the FreeBSD buildbot
171 def test_settings_s_dash(self):
172 """Test that 'settings set -' completes to 'settings set -g'."""
173 self.complete_from_to('settings set -', 'settings set -g')
175 @expectedFailureHostWindows("llvm.org/pr24679")
176 @skipIfFreeBSD # timing out on the FreeBSD buildbot
178 def test_settings_clear_th(self):
179 """Test that 'settings clear th' completes to 'settings clear thread-format'."""
180 self.complete_from_to('settings clear th', 'settings clear thread-format')
182 @expectedFailureHostWindows("llvm.org/pr24679")
183 @skipIfFreeBSD # timing out on the FreeBSD buildbot
185 def test_settings_set_ta(self):
186 """Test that 'settings set ta' completes to 'settings set target.'."""
187 self.complete_from_to('settings set target.ma', 'settings set target.max-')
189 @expectedFailureHostWindows("llvm.org/pr24679")
190 @skipIfFreeBSD # timing out on the FreeBSD buildbot
192 def test_settings_set_target_exec(self):
193 """Test that 'settings set target.exec' completes to 'settings set target.exec-search-paths '."""
194 self.complete_from_to('settings set target.exec', 'settings set target.exec-search-paths')
196 @expectedFailureHostWindows("llvm.org/pr24679")
197 @skipIfFreeBSD # timing out on the FreeBSD buildbot
199 def test_settings_set_target_pr(self):
200 """Test that 'settings set target.pr' completes to ['Available completions:',
201 'target.prefer-dynamic-value', 'target.process.']."""
202 self.complete_from_to('settings set target.pr',
203 ['Available completions:',
204 'target.prefer-dynamic-value',
207 @expectedFailureHostWindows("llvm.org/pr24679")
208 @skipIfFreeBSD # timing out on the FreeBSD buildbot
210 def test_settings_set_target_process(self):
211 """Test that 'settings set target.process' completes to 'settings set target.process.'."""
212 self.complete_from_to('settings set target.process', 'settings set target.process.')
214 @expectedFailureHostWindows("llvm.org/pr24679")
215 @skipIfFreeBSD # timing out on the FreeBSD buildbot
217 def test_settings_set_target_process_dot(self):
218 """Test that 'settings set target.process.t' completes to 'settings set target.process.thread.'."""
219 self.complete_from_to('settings set target.process.t', 'settings set target.process.thread.')
221 @expectedFailureHostWindows("llvm.org/pr24679")
222 @skipIfFreeBSD # timing out on the FreeBSD buildbot
224 def test_settings_set_target_process_thread_dot(self):
225 """Test that 'settings set target.process.thread.' completes to ['Available completions:',
226 'target.process.thread.step-avoid-regexp', 'target.process.thread.trace-thread']."""
227 self.complete_from_to('settings set target.process.thread.',
228 ['Available completions:',
229 'target.process.thread.step-avoid-regexp',
230 'target.process.thread.trace-thread'])
232 @expectedFailureHostWindows("llvm.org/pr24679")
233 @skipIfFreeBSD # timing out on the FreeBSD buildbot
235 def test_target_space(self):
236 """Test that 'target ' completes to ['Available completions:', 'create', 'delete', 'list',
237 'modules', 'select', 'stop-hook', 'variable']."""
238 self.complete_from_to('target ',
239 ['Available completions:', 'create', 'delete', 'list',
240 'modules', 'select', 'stop-hook', 'variable'])
242 @expectedFailureHostWindows("llvm.org/pr24679")
243 @skipIfFreeBSD # timing out on the FreeBSD buildbot
245 def test_target_create_dash_co(self):
246 """Test that 'target create --co' completes to 'target variable --core '."""
247 self.complete_from_to('target create --co', 'target create --core ')
249 @expectedFailureHostWindows("llvm.org/pr24679")
250 @skipIfFreeBSD # timing out on the FreeBSD buildbot
252 def test_target_va(self):
253 """Test that 'target va' completes to 'target variable '."""
254 self.complete_from_to('target va', 'target variable ')
256 @expectedFailureHostWindows("llvm.org/pr24679")
257 @expectedFailureDarwin("llvm.org/pr25485")
258 def test_symbol_name(self):
260 self.complete_from_to('''file a.out
261 breakpoint set -n Fo''',
262 'breakpoint set -n Foo::Bar(int,\\ int)',
263 turn_off_re_match=True)
265 def complete_from_to(self, str_input, patterns, turn_off_re_match=False):
266 """Test that the completion mechanism completes str_input to patterns,
267 where patterns could be a pattern-string or a list of pattern-strings"""
269 # Patterns should not be None in order to proceed.
270 self.assertFalse(patterns is None)
271 # And should be either a string or list of strings. Check for list type
272 # below, if not, make a list out of the singleton string. If patterns
273 # is not a string or not a list of strings, there'll be runtime errors
275 if not isinstance(patterns, list):
276 patterns = [patterns]
278 # The default lldb prompt.
281 # So that the child gets torn down after the test.
282 self.child = pexpect.spawn(lldbtest_config.lldbExec,
283 [self.lldbOption] + ['--no-use-colors'])
285 # Turn on logging for input/output to/from the child.
286 with open('child_send.txt', 'w') as f_send:
287 with open('child_read.txt', 'w') as f_read:
288 child.logfile_send = f_send
289 child.logfile_read = f_read
291 child.expect_exact(prompt)
293 # Sends str_input and a Tab to invoke the completion machinery.
294 child.send("%s\t" % str_input)
296 child.expect_exact(prompt)
298 child.expect_exact(prompt)
300 # Now that the necessary logging is done, restore logfile to None to
301 # stop further logging.
302 child.logfile_send = None
303 child.logfile_read = None
305 with open('child_send.txt', 'r') as fs:
307 print("\n\nContents of child_send.txt:")
309 with open('child_read.txt', 'r') as fr:
310 from_child = fr.read()
312 print("\n\nContents of child_read.txt:")
315 # The matching could be verbatim or using generic re pattern.
317 # Test that str_input completes to our patterns or substrings.
318 # If each pattern/substring matches from_child, the completion mechanism works!
319 if turn_off_re_match:
320 self.expect(from_child, msg=COMPLETION_MSG(str_input, p), exe=False,
323 self.expect(from_child, msg=COMPLETION_MSG(str_input, p), exe=False,