brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 4696b1e Raw
121 lines · python
1"""2Test that the lldb editline handling is configured correctly.3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9from lldbsuite.test.lldbpexpect import PExpectTest10 11 12class EditlineTest(PExpectTest):13    @skipIfAsan14    @skipIfEditlineSupportMissing15    @skipIf(oslist=["linux"], archs=["arm$", "aarch64"])16    def test_left_right_arrow(self):17        """Test that ctrl+left/right arrow navigates words correctly.18 19        Note: just sending escape characters to pexpect and checking the buffer20        doesn't work well, so we run real commands. We want to type21        "help command" while exercising word-navigation, so type it as below,22        where [] indicates cursor position.23 24        1. Send "el rint"  -> "el rint[]"25        2. Ctrl+left once  -> "el []rint"26        3. Send "p"        -> "el p[]rint"27        4. Ctrl+left twice -> "[]el print"28        5. Send "h"        -> "h[]el print"29        6. Ctrl+right      -> "hel[] print"30        7. Send "p"        -> "help print"31        """32        self.launch()33 34        escape_pairs = [35            ("\x1b[1;5D", "\x1b[1;5C"),36            ("\x1b[5D", "\x1b[5C"),37            ("\x1b\x1b[D", "\x1b\x1b[C"),38        ]39        for l_escape, r_escape in escape_pairs:40            self.expect(41                "el rint{L}p{L}{L}h{R}p".format(L=l_escape, R=r_escape),42                substrs=["Syntax: print"],43            )44 45        self.quit()46 47    @skipIfAsan48    @skipIfEditlineSupportMissing49    @skipIfEditlineWideCharSupportMissing50    def test_prompt_unicode(self):51        """Test that we can use Unicode in the LLDB prompt."""52        self.launch(use_colors=True, encoding="utf-8")53        self.child.send('settings set prompt "🐛 "\n')54        # Check that the cursor is at position 4 ([4G)55        # Prompt: 🐛 _56        # Column: 1..457        self.child.expect(re.escape("🐛 \x1b[0m\x1b[4G"))58 59    @skipIfAsan60    @skipIfEditlineSupportMissing61    def test_prompt_color(self):62        """Test that we can change the prompt color with prompt-ansi-prefix."""63        self.launch(use_colors=True)64        self.child.send('settings set prompt-ansi-prefix "${ansi.fg.red}"\n')65        # Make sure this change is reflected immediately. Check that the color66        # is set (31) and the cursor position (8) is correct.67        # Prompt: (lldb) _68        # Column: 1....6.869        self.child.expect(re.escape("\x1b[31m(lldb) \x1b[0m\x1b[8G"))70 71    @skipIfAsan72    @skipIfEditlineSupportMissing73    def test_prompt_format_color(self):74        """Test that we can change the prompt color with a format string."""75        self.launch(use_colors=True)76        # Clear the prefix and suffix setting to simplify the output.77        self.expect('settings set prompt-ansi-prefix ""')78        self.expect('settings set prompt-ansi-suffix ""')79        self.expect('settings set prompt "${ansi.fg.red}(lldb) ${ansi.normal}"')80        self.child.send("foo")81        # Make sure this change is reflected immediately. Check that the color82        # is set (31) and the cursor position (8) is correct.83        # Prompt: (lldb) _84        # Column: 1....6.885        self.child.expect(re.escape("\x1b[31m(lldb) \x1b[0m\x1b[8Gfoo"))86 87    @skipIfAsan88    @skipIfEditlineSupportMissing89    def test_prompt_no_color(self):90        """Test that prompt-ansi-prefix doesn't color the prompt when colors are off."""91        self.launch(use_colors=False)92        self.child.send('settings set prompt-ansi-prefix "${ansi.fg.red}"\n')93        # Send foo so we can match the newline before the prompt and the foo94        # after the prompt.95        self.child.send("foo")96        # Check that there are no escape codes.97        self.child.expect(re.escape("\n\r\x1b[K(lldb) foo"))98 99    @skipIfAsan100    @skipIfEditlineSupportMissing101    def test_enable_and_disable_color(self):102        """Test that when we change the color during debugging it applies the changes"""103        # launch with colors enabled.104        self.launch(use_colors=True)105        self.child.send('settings set prompt-ansi-prefix "${ansi.fg.red}"\n')106        self.child.expect(re.escape("\x1b[31m(lldb) \x1b[0m\x1b[8G"))107 108        # set use color to false.109        self.child.send("settings set use-color false\n")110 111        # check that there is no color.112        self.child.send("foo\n")113        self.child.expect(re.escape("(lldb) foo"))114 115        # set use-color to true116        self.child.send("settings set use-color true\n")117 118        # check that there is colors;119        self.child.send("foo")120        self.child.expect(re.escape("\x1b[31m(lldb) \x1b[0m\x1b[8Gfoo"))121