File: TestMultilineNavigation.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (104 lines) | stat: -rw-r--r-- 4,259 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Tests navigating in the multiline expression editor.
"""

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test.lldbpexpect import PExpectTest


class TestCase(PExpectTest):
    arrow_up = "\033[A"
    arrow_down = "\033[B"

    # PExpect uses many timeouts internally and doesn't play well
    # under ASAN on a loaded machine..
    @skipIfAsan
    @skipIfEditlineSupportMissing
    @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48316")
    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
    def test_nav_arrow_up(self):
        """Tests that we can navigate back to the previous line with the up arrow"""
        self.launch()

        # Start multiline expression mode by just running 'expr'
        self.child.sendline("expr")
        self.child.expect_exact("terminate with an empty line to evaluate")
        # Create a simple integer expression '123' and press enter.
        self.child.send("123\n")
        # We should see the prompt for the second line of our expression.
        self.child.expect_exact("2: ")
        # Go back to the first line and change 123 to 124.
        # Then press enter twice to evaluate our expression.
        self.child.send(self.arrow_up + "\b4\n\n")
        # The result of our expression should be 124 (our edited expression)
        # and not 123 (the one we initially typed).
        self.child.expect_exact("(int) $0 = 124")

        self.quit()

    @skipIfAsan
    @skipIfEditlineSupportMissing
    @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48316")
    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
    def test_nav_arrow_down(self):
        """Tests that we can navigate to the next line with the down arrow"""
        self.launch()

        # Start multiline expression mode by just running 'expr'
        self.child.sendline("expr")
        self.child.expect_exact("terminate with an empty line to evaluate")
        # Create a simple integer expression '111' and press enter.
        self.child.send("111\n")
        # We should see the prompt for the second line of our expression.
        self.child.expect_exact("2: ")
        # Create another simple integer expression '222'.
        self.child.send("222")
        # Go back to the first line and change '111' to '111+' to make
        # an addition operation that spans two lines. We need to go up to
        # test that we can go back down again.
        self.child.send(self.arrow_up + "+")
        # Go back down to our second line and change '222' to '223'
        # so that the full expression is now '111+\n223'.
        # Then press enter twice to evaluate the expression.
        self.child.send(self.arrow_down + "\b3\n\n")
        # The result of our expression '111 + 223' should be '334'.
        # If the expression is '333' then arrow down failed to get
        # us back to the second line.
        self.child.expect_exact("(int) $0 = 334")

        self.quit()

    @skipIfAsan
    @skipIfEditlineSupportMissing
    @skipIf(oslist=["linux"], archs=["arm", "aarch64"])  # Randomly fails on buildbot
    def test_nav_arrow_up_empty(self):
        """
        Tests that navigating with the up arrow doesn't crash and skips
        empty history entries.
        """
        self.launch()

        # Create a real history entry '456' and then follow up with an
        # empty entry (that shouldn't be saved).
        self.child.sendline("expr")
        self.child.expect_exact("terminate with an empty line to evaluate")
        self.child.send("456\n\n")
        self.expect_prompt()

        self.child.sendline("expr")
        self.child.expect_exact("terminate with an empty line to evaluate")
        self.child.send("\n")
        self.expect_prompt()

        # The up arrow should recall the actual history entry and not the
        # the empty entry (as that one shouldn't have been saved).
        self.child.sendline("expr")
        self.child.expect_exact("terminate with an empty line to evaluate")
        self.child.send(self.arrow_up)
        self.child.expect_exact("456")
        self.child.send("\n\n")
        self.expect_prompt()

        self.quit()