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 @skipIf(oslist=["linux"], archs=["arm", "aarch64"]) # Randomly fails on buildbot 26 @skipIfEditlineSupportMissing 27 def test_basic_completion(self): 28 """Test that we can complete a simple multiline expression""" 29 self.build() 30 self.current_repl_line_number = 1 31 32 self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500)) 33 # Try launching the REPL before we have a running target. 34 self.expect("expression --repl -l c --", substrs=["REPL requires a running target process."]) 35 36 self.expect("b main", substrs=["Breakpoint 1", "address ="]) 37 self.expect("run", substrs=["stop reason = breakpoint 1"]) 38 39 # Start the REPL. 40 self.child.send("expression --repl -l c --\n") 41 self.child.expect_exact("1>") 42 43 # Try evaluating a simple expression. 44 self.expect_repl("3 + 3", substrs=["(int) $0 = 6"]) 45 46 # Try declaring a persistent variable. 47 self.expect_repl("long $persistent = 7; 5", 48 substrs=["(int) $1 = 5", 49 "(long) $persistent = 7"]) 50 51 # Try using the persistent variable from before. 52 self.expect_repl("$persistent + 10", 53 substrs=["(long) $2 = 17"]) 54 55 self.quit() 56