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
12class IOHandlerCompletionTest(PExpectTest):
13
14    mydir = TestBase.compute_mydir(__file__)
15
16    # PExpect uses many timeouts internally and doesn't play well
17    # under ASAN on a loaded machine..
18    @skipIfAsan
19    @skipIfEditlineSupportMissing
20    def test_completion(self):
21        self.launch(dimensions=(100,500))
22
23        # Start tab completion, go to the next page and then display all with 'a'.
24        self.child.send("\t\ta")
25        self.child.expect_exact("register")
26
27        # Try tab completing regi to register.
28        self.child.send("regi\t")
29        self.child.expect_exact(self.PROMPT + "register")
30        self.child.send("\n")
31        self.expect_prompt()
32
33        # Try tab completing directories and files. Also tests the partial
34        # completion where LLDB shouldn't print a space after the directory
35        # completion (as it didn't completed the full token).
36        dir_without_slashes = os.path.realpath(os.path.dirname(__file__)).rstrip("/")
37        self.child.send("file " + dir_without_slashes + "\t")
38        self.child.expect_exact("iohandler/completion/")
39        # If we get a correct partial completion without a trailing space, then this
40        # should complete the current test file.
41        self.child.send("TestIOHandler\t")
42        self.child.expect_exact("TestIOHandlerCompletion.py")
43        self.child.send("\n")
44        self.expect_prompt()
45
46        # Start tab completion and abort showing more commands with 'n'.
47        self.child.send("\t")
48        self.child.expect_exact("More (Y/n/a)")
49        self.child.send("n")
50        self.expect_prompt()
51
52        # Shouldn't crash or anything like that.
53        self.child.send("regoinvalid\t")
54        self.expect_prompt()
55
56        self.quit()
57