1c5011aedSJim Ingham""" 2c5011aedSJim InghamTest user added container commands 3c5011aedSJim Ingham""" 4c5011aedSJim Ingham 5c5011aedSJim Ingham 6c5011aedSJim Inghamimport sys 7c5011aedSJim Inghamimport lldb 8c5011aedSJim Inghamfrom lldbsuite.test.decorators import * 9c5011aedSJim Inghamfrom lldbsuite.test.lldbtest import * 10c5011aedSJim Ingham 11c5011aedSJim Ingham 12c5011aedSJim Inghamclass TestCmdContainer(TestBase): 13c5011aedSJim Ingham NO_DEBUG_INFO_TESTCASE = True 14c5011aedSJim Ingham 15c5011aedSJim Ingham def test_container_add(self): 16c5011aedSJim Ingham self.container_add() 17c5011aedSJim Ingham 18c5011aedSJim Ingham def check_command_tree_exists(self): 19c5011aedSJim Ingham """This makes sure we can still run the command tree we added.""" 20c5011aedSJim Ingham self.runCmd("test-multi") 21c5011aedSJim Ingham self.runCmd("test-multi test-multi-sub") 22c5011aedSJim Ingham self.runCmd("test-multi test-multi-sub welcome") 23c5011aedSJim Ingham 24c5011aedSJim Ingham def container_add(self): 25c5011aedSJim Ingham # Make sure we can't overwrite built-in commands: 26c5011aedSJim Ingham self.expect("command container add process", "Can't replace builtin container command", 27c5011aedSJim Ingham substrs=["can't replace builtin command"], error=True) 28c5011aedSJim Ingham self.expect("command container add process non_such_subcommand", "Can't add to built-in subcommand", 29c5011aedSJim Ingham substrs=["Path component: 'process' is not a user command"], error=True) 30c5011aedSJim Ingham self.expect("command container add process launch", "Can't replace builtin subcommand", 31c5011aedSJim Ingham substrs=["Path component: 'process' is not a user command"], error=True) 32c5011aedSJim Ingham 33c5011aedSJim Ingham # Now lets make a container command: 34c5011aedSJim Ingham self.runCmd("command container add -h 'A test container command' test-multi") 35c5011aedSJim Ingham # Make sure the help works: 36c5011aedSJim Ingham self.expect("help test-multi", "Help works for top-level multi", 37c5011aedSJim Ingham substrs=["A test container command"]) 38c5011aedSJim Ingham # Add a subcommand: 39c5011aedSJim Ingham self.runCmd("command container add -h 'A test container sub-command' test-multi test-multi-sub") 40c5011aedSJim Ingham # Make sure the help works: 41c5011aedSJim Ingham self.expect("help test-multi", "Help shows sub-multi", 42c5011aedSJim Ingham substrs=["A test container command", "test-multi-sub -- A test container sub-command"]) 43c5011aedSJim Ingham self.expect("help test-multi test-multi-sub", "Help shows sub-multi", 44c5011aedSJim Ingham substrs=["A test container sub-command"]) 45c5011aedSJim Ingham 46c5011aedSJim Ingham # Now add a script based command to the container command: 47c5011aedSJim Ingham self.runCmd("command script import welcome.py") 48c5011aedSJim Ingham self.runCmd("command script add -c welcome.WelcomeCommand test-multi test-multi-sub welcome") 49c5011aedSJim Ingham # Make sure the help still works: 50c5011aedSJim Ingham self.expect("help test-multi test-multi-sub", "Listing subcommands works", 51c5011aedSJim Ingham substrs=["A test container sub-command", "welcome -- Just a docstring for Welcome"]) 52c5011aedSJim Ingham self.expect("help test-multi test-multi-sub welcome", "Subcommand help works", 53c5011aedSJim Ingham substrs=["Just a docstring for Welcome"]) 54c5011aedSJim Ingham # And make sure it actually works: 55c5011aedSJim Ingham self.expect("test-multi test-multi-sub welcome friend", "Test command works", 56c5011aedSJim Ingham substrs=["Hello friend, welcome to LLDB"]) 57c5011aedSJim Ingham 581f7b58f2SJim Ingham # Make sure overwriting works on the leaf command. First using the 591f7b58f2SJim Ingham # explicit option so we should not be able to remove extant commands by default: 601f7b58f2SJim Ingham 61c5011aedSJim Ingham self.expect("command script add -c welcome.WelcomeCommand2 test-multi test-multi-sub welcome", 62c5011aedSJim Ingham "overwrite command w/o -o", 63c5011aedSJim Ingham substrs=["cannot add command: sub-command already exists"], error=True) 64c5011aedSJim Ingham # But we can with the -o option: 65c5011aedSJim Ingham self.runCmd("command script add -c welcome.WelcomeCommand2 -o test-multi test-multi-sub welcome") 66c5011aedSJim Ingham # Make sure we really did overwrite: 67c5011aedSJim Ingham self.expect("test-multi test-multi-sub welcome friend", "Used the new command class", 68c5011aedSJim Ingham substrs=["Hello friend, welcome again to LLDB"]) 6939ea676dSDave Lee self.expect("apropos welcome", "welcome should show up in apropos", substrs=["A docstring for the second Welcome"]) 70*8c3a6fe3SJim Ingham self.expect("help test-multi test-multi-sub welcome", "welcome should show up in help", substrs=["A docstring for the second Welcome"]) 71*8c3a6fe3SJim Ingham self.expect("help", "test-multi should show up in help", substrs=["test-multi"]) 72c5011aedSJim Ingham 731f7b58f2SJim Ingham # Now switch the default and make sure we can now delete w/o the overwrite option: 741f7b58f2SJim Ingham self.runCmd("settings set interpreter.require-overwrite 0") 751f7b58f2SJim Ingham self.runCmd("command script add -c welcome.WelcomeCommand test-multi test-multi-sub welcome") 761f7b58f2SJim Ingham # Make sure we really did overwrite: 771f7b58f2SJim Ingham self.expect("test-multi test-multi-sub welcome friend", "Used the new command class", 781f7b58f2SJim Ingham substrs=["Hello friend, welcome to LLDB"]) 791f7b58f2SJim Ingham 80c5011aedSJim Ingham # Make sure we give good errors when the input is wrong: 81c5011aedSJim Ingham self.expect("command script delete test-mult test-multi-sub welcome", "Delete script command - wrong first path component", 82c5011aedSJim Ingham substrs=["'test-mult' not found"], error=True) 83c5011aedSJim Ingham 84c5011aedSJim Ingham self.expect("command script delete test-multi test-multi-su welcome", "Delete script command - wrong second path component", 85c5011aedSJim Ingham substrs=["'test-multi-su' not found"], error=True) 86c5011aedSJim Ingham self.check_command_tree_exists() 87c5011aedSJim Ingham 88c5011aedSJim Ingham self.expect("command script delete test-multi test-multi-sub welcom", "Delete script command - wrong leaf component", 89c5011aedSJim Ingham substrs=["'welcom' not found"], error=True) 90c5011aedSJim Ingham self.check_command_tree_exists() 91c5011aedSJim Ingham 92c5011aedSJim Ingham self.expect("command script delete test-multi test-multi-sub", "Delete script command - no leaf component", 93c5011aedSJim Ingham substrs=["subcommand 'test-multi-sub' is not a user command"], error=True) 94c5011aedSJim Ingham self.check_command_tree_exists() 95c5011aedSJim Ingham 96c5011aedSJim Ingham # You can't use command script delete to delete container commands: 97c5011aedSJim Ingham self.expect("command script delete test-multi", "Delete script - can't delete container", 98c5011aedSJim Ingham substrs=["command 'test-multi' is a multi-word command."], error=True) 99c5011aedSJim Ingham self.expect("command script delete test-multi test-multi-sub", "Delete script - can't delete container", 100c5011aedSJim Ingham substrs=["subcommand 'test-multi-sub' is not a user command"], error = True) 101c5011aedSJim Ingham 102c5011aedSJim Ingham # You can't use command container delete to delete scripted commands: 103c5011aedSJim Ingham self.expect("command container delete test-multi test-multi-sub welcome", "command container can't delete user commands", 104c5011aedSJim Ingham substrs=["subcommand 'welcome' is not a container command"], error = True) 105c5011aedSJim Ingham 106c5011aedSJim Ingham # Also make sure you can't alias on top of container commands: 107c5011aedSJim Ingham self.expect("command alias test-multi process launch", "Tried to alias on top of a container command", 108c5011aedSJim Ingham substrs=["'test-multi' is a user container command and cannot be overwritten."], error=True) 109c5011aedSJim Ingham self.check_command_tree_exists() 110c5011aedSJim Ingham 111c5011aedSJim Ingham # Also assert that we can't delete builtin commands: 112c5011aedSJim Ingham self.expect("command script delete process launch", "Delete builtin command fails", substrs=["command 'process' is not a user command"], error=True) 113c5011aedSJim Ingham # Now let's do the version that works 114c5011aedSJim Ingham self.expect("command script delete test-multi test-multi-sub welcome", "Delete script command by path", substrs=["Deleted command: test-multi test-multi-sub welcome"]) 115c5011aedSJim Ingham 116c5011aedSJim Ingham # Now overwrite the sub-command, it should end up empty: 117c5011aedSJim Ingham self.runCmd("command container add -h 'A different help string' -o test-multi test-multi-sub") 118c5011aedSJim Ingham # welcome should be gone: 119c5011aedSJim Ingham self.expect("test-multi test-multi-sub welcome friend", "did remove subcommand", 120c5011aedSJim Ingham substrs=["'test-multi-sub' does not have any subcommands."], error=True) 121c5011aedSJim Ingham # We should have the new help: 122c5011aedSJim Ingham self.expect("help test-multi test-multi-sub", "help changed", 123c5011aedSJim Ingham substrs=["A different help string"]) 124c5011aedSJim Ingham 125c5011aedSJim Ingham # Now try deleting commands. 126c5011aedSJim Ingham self.runCmd("command container delete test-multi test-multi-sub") 127c5011aedSJim Ingham self.expect("test-multi test-multi-sub", "Command is not active", error=True, 128c5011aedSJim Ingham substrs = ["'test-multi' does not have any subcommands"]) 129c5011aedSJim Ingham self.expect("help test-multi", matching=False, substrs=["test-multi-sub"]) 130c5011aedSJim Ingham 131c5011aedSJim Ingham 132c5011aedSJim Ingham # Next the root command: 133c5011aedSJim Ingham self.runCmd("command container delete test-multi") 134c5011aedSJim Ingham self.expect("test-multi", "Root command gone", substrs=["'test-multi' is not a valid command."], error=True) 135