1import lldb 2from lldbsuite.test.decorators import * 3from lldbsuite.test.lldbtest import * 4from lldbsuite.test.lldbpexpect import PExpectTest 5 6class TestCase(PExpectTest): 7 8 mydir = TestBase.compute_mydir(__file__) 9 10 def expect_repl(self, expr, substrs=[]): 11 """ Evaluates the expression in the REPL and verifies that the list 12 of substrs is in the REPL output.""" 13 # Only single line expressions supported. 14 self.assertNotIn("\n", expr) 15 self.child.send(expr + "\n") 16 for substr in substrs: 17 self.child.expect_exact(substr) 18 # Look for the start of the next REPL input line. 19 self.current_repl_line_number += 1 20 self.child.expect_exact(str(self.current_repl_line_number) + ">") 21 22 # PExpect uses many timeouts internally and doesn't play well 23 # under ASAN on a loaded machine.. 24 @skipIfAsan 25 @skipIfEditlineSupportMissing 26 def test_basic_completion(self): 27 """Test that we can complete a simple multiline expression""" 28 self.build() 29 self.current_repl_line_number = 1 30 31 self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500)) 32 # Try launching the REPL before we have a running target. 33 self.expect("expression --repl -l c --", substrs=["REPL requires a running target process."]) 34 35 self.expect("b main", substrs=["Breakpoint 1", "address ="]) 36 self.expect("run", substrs=["stop reason = breakpoint 1"]) 37 38 # Start the REPL. 39 self.child.send("expression --repl -l c --\n") 40 self.child.expect_exact("1>") 41 42 # Try evaluating a simple expression. 43 self.expect_repl("3 + 3", substrs=["(int) $0 = 6"]) 44 45 # Try declaring a persistent variable. 46 self.expect_repl("long $persistent = 7; 5", 47 substrs=["(int) $1 = 5", 48 "(long) $persistent = 7"]) 49 50 # Try using the persistent variable from before. 51 self.expect_repl("$persistent + 10", 52 substrs=["(long) $2 = 17"]) 53 54 self.quit() 55