xref: /llvm-project/lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py (revision 0f339e6567bffb290e409ef5de272fb75ce70234)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest completion in our IOHandlers.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprechtimport os
699451b44SJordan Rupprecht
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1099451b44SJordan Rupprechtfrom lldbsuite.test.lldbpexpect import PExpectTest
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprecht
132238dcc3SJonas Devlieghereclass IOHandlerCompletionTest(PExpectTest):
1499451b44SJordan Rupprecht    # PExpect uses many timeouts internally and doesn't play well
1599451b44SJordan Rupprecht    # under ASAN on a loaded machine..
1699451b44SJordan Rupprecht    @skipIfAsan
1799451b44SJordan Rupprecht    @skipIfEditlineSupportMissing
182238dcc3SJonas Devlieghere    @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr49408")
198f30db87SMuhammad Omair Javaid    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])
2099451b44SJordan Rupprecht    def test_completion(self):
21ffcf5711SHiroki        self.build()
22ffcf5711SHiroki        self.launch(dimensions=(100, 500), executable=self.getBuildArtifact("a.out"))
2399451b44SJordan Rupprecht
2499451b44SJordan Rupprecht        # Start tab completion, go to the next page and then display all with 'a'.
2599451b44SJordan Rupprecht        self.child.send("\t\ta")
2699451b44SJordan Rupprecht        self.child.expect_exact("register")
2799451b44SJordan Rupprecht
2899451b44SJordan Rupprecht        # Try tab completing regi to register.
2999451b44SJordan Rupprecht        self.child.send("regi\t")
30de9e8502SShu Anzai        # editline might move the cursor back to the start of the line and
31de9e8502SShu Anzai        # then back to its original position.
322238dcc3SJonas Devlieghere        self.child.expect(
332238dcc3SJonas Devlieghere            re.compile(
342238dcc3SJonas Devlieghere                b"regi(\r"
352238dcc3SJonas Devlieghere                + self.cursor_forward_escape_seq(len(self.PROMPT + "regi"))
362238dcc3SJonas Devlieghere                + b")?ster"
372238dcc3SJonas Devlieghere            )
382238dcc3SJonas Devlieghere        )
3999451b44SJordan Rupprecht        self.child.send("\n")
4099451b44SJordan Rupprecht        self.expect_prompt()
4199451b44SJordan Rupprecht
4299451b44SJordan Rupprecht        # Try tab completing directories and files. Also tests the partial
4399451b44SJordan Rupprecht        # completion where LLDB shouldn't print a space after the directory
4499451b44SJordan Rupprecht        # completion (as it didn't completed the full token).
4599451b44SJordan Rupprecht        dir_without_slashes = os.path.realpath(os.path.dirname(__file__)).rstrip("/")
4699451b44SJordan Rupprecht        self.child.send("file " + dir_without_slashes + "\t")
4799451b44SJordan Rupprecht        self.child.expect_exact("iohandler/completion/")
4899451b44SJordan Rupprecht        # If we get a correct partial completion without a trailing space, then this
4999451b44SJordan Rupprecht        # should complete the current test file.
5099451b44SJordan Rupprecht        self.child.send("TestIOHandler\t")
51de9e8502SShu Anzai        # As above, editline might move the cursor to the start of the line and
52de9e8502SShu Anzai        # then back to its original position. We only care about the fact
53de9e8502SShu Anzai        # that this is completing a partial completion, so skip the exact cursor
54de9e8502SShu Anzai        # position calculation.
552238dcc3SJonas Devlieghere        self.child.expect(
562238dcc3SJonas Devlieghere            re.compile(
572238dcc3SJonas Devlieghere                b"TestIOHandler(\r"
582238dcc3SJonas Devlieghere                + self.cursor_forward_escape_seq("\d+")
592238dcc3SJonas Devlieghere                + b")?Completion.py"
602238dcc3SJonas Devlieghere            )
612238dcc3SJonas Devlieghere        )
6299451b44SJordan Rupprecht        self.child.send("\n")
6399451b44SJordan Rupprecht        self.expect_prompt()
6499451b44SJordan Rupprecht
65ffcf5711SHiroki        # Complete a file path.
66ffcf5711SHiroki        # FIXME: This should complete to './main.c' and not 'main.c'
67ffcf5711SHiroki        self.child.send("breakpoint set --file ./main\t")
68ffcf5711SHiroki        self.child.expect_exact("main.c")
69ffcf5711SHiroki        self.child.send("\n")
70ffcf5711SHiroki        self.expect_prompt()
71ffcf5711SHiroki
7299451b44SJordan Rupprecht        # Start tab completion and abort showing more commands with 'n'.
7399451b44SJordan Rupprecht        self.child.send("\t")
7499451b44SJordan Rupprecht        self.child.expect_exact("More (Y/n/a)")
7599451b44SJordan Rupprecht        self.child.send("n")
7699451b44SJordan Rupprecht        self.expect_prompt()
7799451b44SJordan Rupprecht
78*0f339e65SJim Ingham        # Start tab completion and abort showing more commands with '^C'.
79*0f339e65SJim Ingham        self.child.send("\t")
80*0f339e65SJim Ingham        self.child.expect_exact("More (Y/n/a)")
81*0f339e65SJim Ingham        self.child.sendcontrol("c")
82*0f339e65SJim Ingham        self.expect_prompt()
83*0f339e65SJim Ingham
8499451b44SJordan Rupprecht        # Shouldn't crash or anything like that.
8599451b44SJordan Rupprecht        self.child.send("regoinvalid\t")
8699451b44SJordan Rupprecht        self.expect_prompt()
8799451b44SJordan Rupprecht
8899451b44SJordan Rupprecht        self.quit()
89