1""" 2Test completion in our IOHandlers. 3""" 4 5import os 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test.lldbpexpect import PExpectTest 11 12 13class IOHandlerCompletionTest(PExpectTest): 14 # PExpect uses many timeouts internally and doesn't play well 15 # under ASAN on a loaded machine.. 16 @skipIfAsan 17 @skipIfEditlineSupportMissing 18 @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr49408") 19 @skipIf(oslist=["linux"], archs=["arm", "aarch64"]) 20 def test_completion(self): 21 self.build() 22 self.launch(dimensions=(100, 500), executable=self.getBuildArtifact("a.out")) 23 24 # Start tab completion, go to the next page and then display all with 'a'. 25 self.child.send("\t\ta") 26 self.child.expect_exact("register") 27 28 # Try tab completing regi to register. 29 self.child.send("regi\t") 30 # editline might move the cursor back to the start of the line and 31 # then back to its original position. 32 self.child.expect( 33 re.compile( 34 b"regi(\r" 35 + self.cursor_forward_escape_seq(len(self.PROMPT + "regi")) 36 + b")?ster" 37 ) 38 ) 39 self.child.send("\n") 40 self.expect_prompt() 41 42 # Try tab completing directories and files. Also tests the partial 43 # completion where LLDB shouldn't print a space after the directory 44 # completion (as it didn't completed the full token). 45 dir_without_slashes = os.path.realpath(os.path.dirname(__file__)).rstrip("/") 46 self.child.send("file " + dir_without_slashes + "\t") 47 self.child.expect_exact("iohandler/completion/") 48 # If we get a correct partial completion without a trailing space, then this 49 # should complete the current test file. 50 self.child.send("TestIOHandler\t") 51 # As above, editline might move the cursor to the start of the line and 52 # then back to its original position. We only care about the fact 53 # that this is completing a partial completion, so skip the exact cursor 54 # position calculation. 55 self.child.expect( 56 re.compile( 57 b"TestIOHandler(\r" 58 + self.cursor_forward_escape_seq("\d+") 59 + b")?Completion.py" 60 ) 61 ) 62 self.child.send("\n") 63 self.expect_prompt() 64 65 # Complete a file path. 66 # FIXME: This should complete to './main.c' and not 'main.c' 67 self.child.send("breakpoint set --file ./main\t") 68 self.child.expect_exact("main.c") 69 self.child.send("\n") 70 self.expect_prompt() 71 72 # Start tab completion and abort showing more commands with 'n'. 73 self.child.send("\t") 74 self.child.expect_exact("More (Y/n/a)") 75 self.child.send("n") 76 self.expect_prompt() 77 78 # Start tab completion and abort showing more commands with '^C'. 79 self.child.send("\t") 80 self.child.expect_exact("More (Y/n/a)") 81 self.child.sendcontrol("c") 82 self.expect_prompt() 83 84 # Shouldn't crash or anything like that. 85 self.child.send("regoinvalid\t") 86 self.expect_prompt() 87 88 self.quit() 89