]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/abbreviation/TestAbbreviations.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / abbreviation / TestAbbreviations.py
1 """
2 Test some lldb command abbreviations and aliases for proper resolution.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class AbbreviationsTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     @no_debug_info_test
21     def test_command_abbreviations_and_aliases(self):
22         command_interpreter = self.dbg.GetCommandInterpreter()
23         self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER)
24         result = lldb.SBCommandReturnObject()
25
26         # Check that abbreviations are expanded to the full command.
27         command_interpreter.ResolveCommand("ap script", result)
28         self.assertTrue(result.Succeeded())
29         self.assertEqual("apropos script", result.GetOutput())
30
31         command_interpreter.ResolveCommand("h", result)
32         self.assertTrue(result.Succeeded())
33         self.assertEqual("help", result.GetOutput())
34
35         # Check resolution of abbreviations for multi-word commands.
36         command_interpreter.ResolveCommand("lo li", result)
37         self.assertTrue(result.Succeeded())
38         self.assertEqual("log list", result.GetOutput())
39
40         command_interpreter.ResolveCommand("br s", result)
41         self.assertTrue(result.Succeeded())
42         self.assertEqual("breakpoint set", result.GetOutput())
43
44         # Try an ambiguous abbreviation.
45         # "pl" could be "platform" or "plugin".
46         command_interpreter.ResolveCommand("pl", result)
47         self.assertFalse(result.Succeeded())
48         self.assertTrue(result.GetError().startswith("Ambiguous command"))
49
50         # Make sure an unabbreviated command is not mangled.
51         command_interpreter.ResolveCommand(
52             "breakpoint set --name main --line 123", result)
53         self.assertTrue(result.Succeeded())
54         self.assertEqual(
55             "breakpoint set --name main --line 123",
56             result.GetOutput())
57
58         # Create some aliases.
59         self.runCmd("com a alias com al")
60         self.runCmd("alias gurp help")
61
62         # Check that an alias is replaced with the actual command
63         command_interpreter.ResolveCommand("gurp target create", result)
64         self.assertTrue(result.Succeeded())
65         self.assertEqual("help target create", result.GetOutput())
66
67         # Delete the alias and make sure it no longer has an effect.
68         self.runCmd("com u gurp")
69         command_interpreter.ResolveCommand("gurp", result)
70         self.assertFalse(result.Succeeded())
71
72         # Check aliases with text replacement.
73         self.runCmd("alias pltty process launch -s -o %1 -e %1")
74         command_interpreter.ResolveCommand("pltty /dev/tty0", result)
75         self.assertTrue(result.Succeeded())
76         self.assertEqual(
77             "process launch -s -o /dev/tty0 -e /dev/tty0",
78             result.GetOutput())
79
80         self.runCmd("alias xyzzy breakpoint set -n %1 -l %2")
81         command_interpreter.ResolveCommand("xyzzy main 123", result)
82         self.assertTrue(result.Succeeded())
83         self.assertEqual(
84             "breakpoint set -n main -l 123",
85             result.GetOutput().strip())
86
87         # And again, without enough parameters.
88         command_interpreter.ResolveCommand("xyzzy main", result)
89         self.assertFalse(result.Succeeded())
90
91         # Check a command that wants the raw input.
92         command_interpreter.ResolveCommand(
93             r'''sc print("\n\n\tHello!\n")''', result)
94         self.assertTrue(result.Succeeded())
95         self.assertEqual(
96             r'''script print("\n\n\tHello!\n")''',
97             result.GetOutput())
98
99         # Prompt changing stuff should be tested, but this doesn't seem like the
100         # right test to do it in.  It has nothing to do with aliases or abbreviations.
101         #self.runCmd("com sou ./change_prompt.lldb")
102         # self.expect("settings show prompt",
103         #            startstr = 'prompt (string) = "[with-three-trailing-spaces]   "')
104         #self.runCmd("settings clear prompt")
105         # self.expect("settings show prompt",
106         #            startstr = 'prompt (string) = "(lldb) "')
107         #self.runCmd("se se prompt 'Sycamore> '")
108         # self.expect("se sh prompt",
109         #            startstr = 'prompt (string) = "Sycamore> "')
110         #self.runCmd("se cl prompt")
111         # self.expect("set sh prompt",
112         #            startstr = 'prompt (string) = "(lldb) "')