1""" 2Test completion for multiline expressions. 3""" 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test.lldbpexpect import PExpectTest 9 10 11class MultilineCompletionTest(PExpectTest): 12 def start_expression_editor(self): 13 """Starts the multiline expression editor.""" 14 self.child.send("expression\n") 15 self.child.expect_exact("terminate with an empty line to evaluate") 16 17 def exit_expression_editor(self): 18 """Exits the multiline expression editor.""" 19 # Send a newline to finish the current line. The second newline will 20 # finish the new empty line which will exit the editor. The space at the 21 # start prevents that the first newline already exits the editor (in 22 # case the current line of the editor is already empty when this 23 # function is called). 24 self.child.send(" \n\n") 25 self.expect_prompt() 26 27 # PExpect uses many timeouts internally and doesn't play well 28 # under ASAN on a loaded machine.. 29 @skipIfAsan 30 @skipIfEditlineSupportMissing 31 @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr49408") 32 @skipIf(oslist=["linux"], archs=["arm", "aarch64"]) 33 def test_basic_completion(self): 34 """Test that we can complete a simple multiline expression""" 35 self.build() 36 37 self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100, 500)) 38 self.expect("b main", substrs=["Breakpoint 1", "address ="]) 39 self.expect("run", substrs=["stop reason = breakpoint 1"]) 40 41 self.start_expression_editor() 42 self.child.send("to_\t") 43 # editline might move the cursor back to the start of the line via \r 44 # and then back to its original position. 45 self.child.expect( 46 re.compile( 47 b"to_(\r" 48 + self.cursor_forward_escape_seq(len(" 1: to_")) 49 + b")?complete" 50 ) 51 ) 52 self.exit_expression_editor() 53 54 # Check that completion empty input in a function with only one 55 # local variable works. 56 self.expect( 57 "breakpoint set -p 'break in single_local_func'", substrs=["Breakpoint 2"] 58 ) 59 self.expect("continue", substrs=["stop reason = breakpoint 2"]) 60 self.start_expression_editor() 61 self.child.send("\t") 62 # Only one local, so this will directly insert 'only_local' with a 63 # trailing space to signal a final completion. 64 self.child.expect_exact("only_local ") 65 self.exit_expression_editor() 66 67 self.quit() 68