2 Test some lldb help commands.
4 See also CommandInterpreter::OutputFormattedHelpText().
7 from __future__ import print_function
13 from lldbsuite.test.decorators import *
14 from lldbsuite.test.lldbtest import *
15 from lldbsuite.test import lldbutil
17 class HelpCommandTestCase(TestBase):
19 mydir = TestBase.compute_mydir(__file__)
22 def test_simplehelp(self):
23 """A simple test of 'help' command and its output."""
25 startstr = 'Debugger commands:')
27 self.expect("help -a", matching=False,
30 self.expect("help", matching=True,
34 def test_help_on_help(self):
35 """Testing the help on the help facility."""
36 self.expect("help help", matching=True,
37 substrs = ['--hide-aliases',
38 '--hide-user-commands'])
41 def version_number_string(self):
42 """Helper function to find the version number string of lldb."""
43 plist = os.path.join(os.environ["LLDB_SRC"], "resources", "LLDB-Info.plist")
45 CFBundleVersionSegFound = False
46 with open(plist, 'r') as f:
48 if CFBundleVersionSegFound:
49 version_line = line.strip()
51 m = re.match("<string>(.*)</string>", version_line)
56 # Unsuccessful, let's juts break out of the for loop.
59 if line.find("<key>CFBundleVersion</key>") != -1:
60 # Found our match. The next line contains our version
61 # string, for example:
64 CFBundleVersionSegFound = True
72 # Use None to signify that we are not able to grok the version number.
76 def test_help_arch(self):
77 """Test 'help arch' which should list of supported architectures."""
78 self.expect("help arch",
79 substrs = ['arm', 'x86_64', 'i386'])
82 def test_help_version(self):
83 """Test 'help version' and 'version' commands."""
84 self.expect("help version",
85 substrs = ['Show the LLDB debugger version.'])
86 version_str = self.version_number_string()
88 match = re.match('[0-9]+', version_str)
89 if sys.platform.startswith("darwin"):
90 search_regexp = ['lldb-' + (version_str if match else '[0-9]+')]
92 search_regexp = ['lldb version (\d|\.)+.*$']
94 self.expect("version",
95 patterns = search_regexp)
98 def test_help_should_not_crash_lldb(self):
99 """Command 'help disasm' should not crash lldb."""
100 self.runCmd("help disasm", check=False)
101 self.runCmd("help unsigned-integer")
104 def test_help_should_not_hang_emacsshell(self):
105 """Command 'settings set term-width 0' should not hang the help command."""
106 self.expect("settings set term-width 0",
107 COMMAND_FAILED_AS_EXPECTED, error=True,
108 substrs = ['error: 0 is out of range, valid values must be between'])
109 # self.runCmd("settings set term-width 0")
111 startstr = 'Debugger commands:')
114 def test_help_breakpoint_set(self):
115 """Test that 'help breakpoint set' does not print out redundant lines of:
116 'breakpoint set [-s <shlib-name>] ...'."""
117 self.expect("help breakpoint set", matching=False,
118 substrs = ['breakpoint set [-s <shlib-name>]'])
121 def test_help_image_dump_symtab_should_not_crash(self):
122 """Command 'help image dump symtab' should not crash lldb."""
123 # 'image' is an alias for 'target modules'.
124 self.expect("help image dump symtab",
125 substrs = ['dump symtab',
129 def test_help_image_du_sym_is_ambiguous(self):
130 """Command 'help image du sym' is ambiguous and spits out the list of candidates."""
131 self.expect("help image du sym",
132 COMMAND_FAILED_AS_EXPECTED, error=True,
133 substrs = ['error: ambiguous command image du sym',
138 def test_help_image_du_line_should_work(self):
139 """Command 'help image du line-table' is not ambiguous and should work."""
140 # 'image' is an alias for 'target modules'.
141 self.expect("help image du line",
142 substrs = ['Dump the line table for one or more compilation units'])
145 def test_help_target_variable_syntax(self):
146 """Command 'help target variable' should display <variable-name> ..."""
147 self.expect("help target variable",
148 substrs = ['<variable-name> [<variable-name> [...]]'])
151 def test_help_watchpoint_and_its_args(self):
152 """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work."""
153 self.expect("help watchpoint",
154 substrs = ['delete', 'disable', 'enable', 'list'])
155 self.expect("help watchpt-id",
156 substrs = ['<watchpt-id>'])
157 self.expect("help watchpt-id-list",
158 substrs = ['<watchpt-id-list>'])
161 def test_help_watchpoint_set(self):
162 """Test that 'help watchpoint set' prints out 'expression' and 'variable'
163 as the possible subcommands."""
164 self.expect("help watchpoint set",
165 substrs = ['The following subcommands are supported:'],
166 patterns = ['expression +--',
170 def test_help_po_hides_options(self):
171 """Test that 'help po' does not show all the options for expression"""
172 self.expect("help po",
173 substrs = ['--show-all-children', '--object-description'], matching=False)
176 def test_help_run_hides_options(self):
177 """Test that 'help run' does not show all the options for process launch"""
178 self.expect("help run",
179 substrs = ['--arch', '--environment'], matching=False)
182 def test_help_next_shows_options(self):
183 """Test that 'help next' shows all the options for thread step-over"""
184 self.expect("help next",
185 substrs = ['--python-class','--run-mode'], matching=True)
188 def test_help_provides_alternatives(self):
189 """Test that help on commands that don't exist provides information on additional help avenues"""
190 self.expect("help thisisnotadebuggercommand",
191 substrs = ["'thisisnotadebuggercommand' is not a known command.",
192 "Try 'help' to see a current list of commands.",
193 "Try 'apropos thisisnotadebuggercommand' for a list of related commands.",
194 "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."], error=True)
196 self.expect("help process thisisnotadebuggercommand",
197 substrs = ["'process thisisnotadebuggercommand' is not a known command.",
198 "Try 'help' to see a current list of commands.",
199 "Try 'apropos thisisnotadebuggercommand' for a list of related commands.",
200 "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."])
203 def test_custom_help_alias(self):
204 """Test that aliases pick up custom help text."""
206 self.runCmd('command unalias afriendlyalias', check=False)
207 self.runCmd('command unalias averyfriendlyalias', check=False)
209 self.addTearDownHook(cleanup)
210 self.runCmd('command alias --help "I am a friendly alias" -- afriendlyalias help')
211 self.expect("help afriendlyalias", matching=True, substrs = ['I am a friendly alias'])
212 self.runCmd('command alias --long-help "I am a very friendly alias" -- averyfriendlyalias help')
213 self.expect("help averyfriendlyalias", matching=True, substrs = ['I am a very friendly alias'])