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