2 Test some lldb command abbreviations and aliases for proper resolution.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class AbbreviationsTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
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()
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())
31 command_interpreter.ResolveCommand("h", result)
32 self.assertTrue(result.Succeeded())
33 self.assertEqual("help", result.GetOutput())
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())
40 command_interpreter.ResolveCommand("br s", result)
41 self.assertTrue(result.Succeeded())
42 self.assertEqual("breakpoint set", result.GetOutput())
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"))
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())
55 "breakpoint set --name main --line 123",
58 # Create some aliases.
59 self.runCmd("com a alias com al")
60 self.runCmd("alias gurp help")
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())
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())
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())
77 "process launch -s -o /dev/tty0 -e /dev/tty0",
80 self.runCmd("alias xyzzy breakpoint set -n %1 -l %2")
81 command_interpreter.ResolveCommand("xyzzy main 123", result)
82 self.assertTrue(result.Succeeded())
84 "breakpoint set -n main -l 123",
85 result.GetOutput().strip())
87 # And again, without enough parameters.
88 command_interpreter.ResolveCommand("xyzzy main", result)
89 self.assertFalse(result.Succeeded())
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())
96 r'''script print("\n\n\tHello!\n")''',
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) "')