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