xref: /llvm-project/lldb/test/API/commands/expression/multiline-completion/TestMultilineCompletion.py (revision 8f30db8794125db2a768fbb3b20b0b1511ea211c)
1"""
2Test completion for multiline expressions.
3"""
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test.lldbpexpect import PExpectTest
9
10class MultilineCompletionTest(PExpectTest):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    def start_expression_editor(self):
15        """ Starts the multiline expression editor. """
16        self.child.send("expression\n")
17        self.child.expect_exact("terminate with an empty line to evaluate")
18
19    def exit_expression_editor(self):
20        """ Exits the multiline expression editor. """
21        # Send a newline to finish the current line. The second newline will
22        # finish the new empty line which will exit the editor. The space at the
23        # start prevents that the first newline already exits the editor (in
24        # case the current line of the editor is already empty when this
25        # function is called).
26        self.child.send(" \n\n")
27        self.expect_prompt()
28
29    # PExpect uses many timeouts internally and doesn't play well
30    # under ASAN on a loaded machine..
31    @skipIfAsan
32    @skipIfEditlineSupportMissing
33    @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr49408')
34    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])
35    def test_basic_completion(self):
36        """Test that we can complete a simple multiline expression"""
37        self.build()
38
39        self.launch(executable=self.getBuildArtifact("a.out"), dimensions=(100,500))
40        self.expect("b main", substrs=["Breakpoint 1", "address ="])
41        self.expect("run", substrs=["stop reason = breakpoint 1"])
42
43        self.start_expression_editor()
44        self.child.send("to_\t")
45        # editline might move the cursor back to the start of the line via \r
46        # and then back to its original position.
47        self.child.expect(re.compile(b"to_(\r" + self.cursor_forward_escape_seq(len("  1: to_")) + b")?complete"))
48        self.exit_expression_editor()
49
50        # Check that completion empty input in a function with only one
51        # local variable works.
52        self.expect("breakpoint set -p 'break in single_local_func'",
53                    substrs=["Breakpoint 2"])
54        self.expect("continue", substrs=["stop reason = breakpoint 2"])
55        self.start_expression_editor()
56        self.child.send("\t")
57        # Only one local, so this will directly insert 'only_local' with a
58        # trailing space to signal a final completion.
59        self.child.expect_exact("only_local ")
60        self.exit_expression_editor()
61
62        self.quit()
63