]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/help/TestHelp.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / help / TestHelp.py
1 """
2 Test some lldb help commands.
3
4 See also CommandInterpreter::OutputFormattedHelpText().
5 """
6
7 from __future__ import print_function
8
9
10
11 import os, time
12 import lldb
13 from lldbsuite.test.decorators import *
14 from lldbsuite.test.lldbtest import *
15 from lldbsuite.test import lldbutil
16
17 class HelpCommandTestCase(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     @no_debug_info_test
22     def test_simplehelp(self):
23         """A simple test of 'help' command and its output."""
24         self.expect("help",
25             startstr = 'Debugger commands:')
26
27         self.expect("help -a", matching=False,
28                     substrs = ['next'])
29         
30         self.expect("help", matching=True,
31                     substrs = ['next'])
32     
33     @no_debug_info_test
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'])
39
40     @no_debug_info_test
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")
44         try:
45             CFBundleVersionSegFound = False
46             with open(plist, 'r') as f:
47                 for line in f:
48                     if CFBundleVersionSegFound:
49                         version_line = line.strip()
50                         import re
51                         m = re.match("<string>(.*)</string>", version_line)
52                         if m:
53                             version = m.group(1)
54                             return version
55                         else:
56                             # Unsuccessful, let's juts break out of the for loop.
57                             break
58
59                     if line.find("<key>CFBundleVersion</key>") != -1:
60                         # Found our match.  The next line contains our version
61                         # string, for example:
62                         # 
63                         #     <string>38</string>
64                         CFBundleVersionSegFound = True
65
66         except:
67             # Just fallthrough...
68             import traceback
69             traceback.print_exc()
70             pass
71
72         # Use None to signify that we are not able to grok the version number.
73         return None
74
75     @no_debug_info_test
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'])
80
81     @no_debug_info_test
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()
87         import re
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]+')]
91         else:
92             search_regexp = ['lldb version (\d|\.)+.*$']
93
94         self.expect("version",
95             patterns = search_regexp)
96
97     @no_debug_info_test
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")
102
103     @no_debug_info_test
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")
110         self.expect("help",
111             startstr = 'Debugger commands:')
112
113     @no_debug_info_test
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>]'])
119
120     @no_debug_info_test
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',
126                        'sort-order'])
127
128     @no_debug_info_test
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',
134                        'symfile',
135                        'symtab'])
136
137     @no_debug_info_test
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'])
143
144     @no_debug_info_test
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> [...]]'])
149
150     @no_debug_info_test
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>'])
159
160     @no_debug_info_test
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 +--',
167                         'variable +--'])
168
169     @no_debug_info_test
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)
174
175     @no_debug_info_test
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)
180
181     @no_debug_info_test
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)
186
187     @no_debug_info_test
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)
195
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."])
201
202     @no_debug_info_test
203     def test_custom_help_alias(self):
204         """Test that aliases pick up custom help text."""
205         def cleanup():
206             self.runCmd('command unalias afriendlyalias', check=False)
207             self.runCmd('command unalias averyfriendlyalias', check=False)
208         
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'])