2 Test user added container commands
8 from lldbsuite
.test
.decorators
import *
9 from lldbsuite
.test
.lldbtest
import *
12 class TestCmdContainer(TestBase
):
13 NO_DEBUG_INFO_TESTCASE
= True
15 def test_container_add(self
):
18 def check_command_tree_exists(self
):
19 """This makes sure we can still run the command tree we added."""
20 self
.runCmd("test-multi")
21 self
.runCmd("test-multi test-multi-sub")
22 self
.runCmd("test-multi test-multi-sub welcome")
24 def container_add(self
):
25 # Make sure we can't overwrite built-in commands:
27 "command container add process",
28 "Can't replace builtin container command",
29 substrs
=["can't replace builtin command"],
33 "command container add process non_such_subcommand",
34 "Can't add to built-in subcommand",
35 substrs
=["Path component: 'process' is not a user command"],
39 "command container add process launch",
40 "Can't replace builtin subcommand",
41 substrs
=["Path component: 'process' is not a user command"],
45 # Now lets make a container command:
46 self
.runCmd("command container add -h 'A test container command' test-multi")
47 # Make sure the help works:
50 "Help works for top-level multi",
51 substrs
=["A test container command"],
55 "command container add -h 'A test container sub-command' test-multi test-multi-sub"
57 # Make sure the help works:
60 "Help shows sub-multi",
62 "A test container command",
63 "test-multi-sub -- A test container sub-command",
67 "help test-multi test-multi-sub",
68 "Help shows sub-multi",
69 substrs
=["A test container sub-command"],
72 # Now add a script based command to the container command:
73 self
.runCmd("command script import welcome.py")
75 "command script add -c welcome.WelcomeCommand test-multi test-multi-sub welcome"
77 # Make sure the help still works:
79 "help test-multi test-multi-sub",
80 "Listing subcommands works",
82 "A test container sub-command",
83 "welcome -- Just a docstring for Welcome",
87 "help test-multi test-multi-sub welcome",
88 "Subcommand help works",
89 substrs
=["Just a docstring for Welcome"],
91 # And make sure it actually works:
93 "test-multi test-multi-sub welcome friend",
95 substrs
=["Hello friend, welcome to LLDB"],
98 # Make sure we can make an alias to this:
100 "command alias my-welcome test-multi test-multi-sub welcome",
101 "We can make an alias to multi-word",
105 "Test command works",
106 substrs
=["Hello friend, welcome to LLDB"],
108 self
.runCmd("command unalias my-welcome")
110 # Make sure overwriting works on the leaf command. First using the
111 # explicit option so we should not be able to remove extant commands by default:
114 "command script add -c welcome.WelcomeCommand2 test-multi test-multi-sub welcome",
115 "overwrite command w/o -o",
116 substrs
=["cannot add command: sub-command already exists"],
119 # But we can with the -o option:
121 "command script add -c welcome.WelcomeCommand2 -o test-multi test-multi-sub welcome"
123 # Make sure we really did overwrite:
125 "test-multi test-multi-sub welcome friend",
126 "Used the new command class",
127 substrs
=["Hello friend, welcome again to LLDB"],
131 "welcome should show up in apropos",
132 substrs
=["A docstring for the second Welcome"],
135 "help test-multi test-multi-sub welcome",
136 "welcome should show up in help",
137 substrs
=["A docstring for the second Welcome"],
139 self
.expect("help", "test-multi should show up in help", substrs
=["test-multi"])
141 # Now switch the default and make sure we can now delete w/o the overwrite option:
142 self
.runCmd("settings set interpreter.require-overwrite 0")
144 "command script add -c welcome.WelcomeCommand test-multi test-multi-sub welcome"
146 # Make sure we really did overwrite:
148 "test-multi test-multi-sub welcome friend",
149 "Used the new command class",
150 substrs
=["Hello friend, welcome to LLDB"],
153 # Make sure we give good errors when the input is wrong:
155 "command script delete test-mult test-multi-sub welcome",
156 "Delete script command - wrong first path component",
157 substrs
=["'test-mult' not found"],
162 "command script delete test-multi test-multi-su welcome",
163 "Delete script command - wrong second path component",
164 substrs
=["'test-multi-su' not found"],
167 self
.check_command_tree_exists()
170 "command script delete test-multi test-multi-sub welcom",
171 "Delete script command - wrong leaf component",
172 substrs
=["'welcom' not found"],
175 self
.check_command_tree_exists()
178 "command script delete test-multi test-multi-sub",
179 "Delete script command - no leaf component",
180 substrs
=["subcommand 'test-multi-sub' is not a user command"],
183 self
.check_command_tree_exists()
185 # You can't use command script delete to delete container commands:
187 "command script delete test-multi",
188 "Delete script - can't delete container",
189 substrs
=["command 'test-multi' is a multi-word command."],
193 "command script delete test-multi test-multi-sub",
194 "Delete script - can't delete container",
195 substrs
=["subcommand 'test-multi-sub' is not a user command"],
199 # You can't use command container delete to delete scripted commands:
201 "command container delete test-multi test-multi-sub welcome",
202 "command container can't delete user commands",
203 substrs
=["subcommand 'welcome' is not a container command"],
207 # Also make sure you can't alias on top of container commands:
209 "command alias test-multi process launch",
210 "Tried to alias on top of a container command",
212 "'test-multi' is a user container command and cannot be overwritten."
216 self
.check_command_tree_exists()
218 # Also assert that we can't delete builtin commands:
220 "command script delete process launch",
221 "Delete builtin command fails",
222 substrs
=["command 'process' is not a user command"],
225 # Now let's do the version that works
227 "command script delete test-multi test-multi-sub welcome",
228 "Delete script command by path",
229 substrs
=["Deleted command: test-multi test-multi-sub welcome"],
232 # Now overwrite the sub-command, it should end up empty:
234 "command container add -h 'A different help string' -o test-multi test-multi-sub"
236 # welcome should be gone:
238 "test-multi test-multi-sub welcome friend",
239 "did remove subcommand",
240 substrs
=["'test-multi-sub' does not have any subcommands."],
243 # We should have the new help:
245 "help test-multi test-multi-sub",
247 substrs
=["A different help string"],
250 # Now try deleting commands.
251 self
.runCmd("command container delete test-multi test-multi-sub")
253 "test-multi test-multi-sub",
254 "Command is not active",
256 substrs
=["'test-multi' does not have any subcommands"],
258 self
.expect("help test-multi", matching
=False, substrs
=["test-multi-sub"])
260 # Next the root command:
261 self
.runCmd("command container delete test-multi")
265 substrs
=["'test-multi' is not a valid command."],