blob: 77142e19dbebdaefe2a4c168751825a75332f8fd [file] [log] [blame]
Johnny Chen7f5f2802010-08-02 21:26:00 +00001"""
Johnny Chen65045f22010-10-08 17:21:27 +00002Test some lldb help commands.
Johnny Chen7f5f2802010-08-02 21:26:00 +00003
4See also CommandInterpreter::OutputFormattedHelpText().
5"""
Johnny Chen9320d4a2010-06-25 23:15:47 +00006
Johnny Chen8c3f9182010-07-01 00:18:39 +00007import os, time
Johnny Chen73258832010-08-05 23:42:46 +00008import unittest2
Johnny Chenbf6ffa32010-07-03 03:41:59 +00009import lldb
Johnny Chen17941842010-08-09 23:44:24 +000010from lldbtest import *
Johnny Chen9320d4a2010-06-25 23:15:47 +000011
Johnny Chencbb4be02010-09-01 19:59:58 +000012class HelpCommandTestCase(TestBase):
Johnny Chen119b53e2010-07-01 22:52:57 +000013
Johnny Chenbf6ffa32010-07-03 03:41:59 +000014 mydir = "help"
Johnny Chen9320d4a2010-06-25 23:15:47 +000015
16 def test_simplehelp(self):
17 """A simple test of 'help' command and its output."""
Johnny Chen74f26b82010-08-20 19:17:39 +000018 self.expect("help",
19 startstr = 'The following is a list of built-in, permanent debugger commands')
Johnny Chen7e363f52010-06-28 20:55:57 +000020
Johnny Chen84939892011-01-06 00:03:01 +000021 def version_number_string(self):
22 """Helper function to find the version number string of lldb."""
23 plist = os.path.join(os.getcwd(), os.pardir, os.pardir, "resources", "LLDB-info.plist")
24 try:
25 CFBundleVersionSegFound = False
26 with open(plist, 'r') as f:
27 for line in f:
28 if CFBundleVersionSegFound:
29 version_line = line.strip()
30 import re
31 m = re.match("<string>(.*)</string>", version_line)
32 if m:
33 version = m.group(1)
34 return version
35 else:
36 # Unsuccessful, let's juts break out of the for loop.
37 break
38
39 if line.find("<key>CFBundleVersion</key>") != -1:
40 # Found our match. The next line contains our version
41 # string, for example:
42 #
43 # <string>38</string>
44 CFBundleVersionSegFound = True
45
46 except:
47 # Just fallthrough...
Johnny Chenb13ee842011-01-07 00:17:44 +000048 import traceback
49 traceback.print_exc()
Johnny Chen84939892011-01-06 00:03:01 +000050 pass
51
52 # Use None to signify that we are not able to grok the version number.
53 return None
54
55
Johnny Chen31c39da2010-12-23 20:21:44 +000056 def test_help_version(self):
57 """Test 'help version' and 'version' commands."""
58 self.expect("help version",
59 substrs = ['Show version of LLDB debugger.'])
Johnny Chen84939892011-01-06 00:03:01 +000060 version_str = self.version_number_string()
Johnny Chen31c39da2010-12-23 20:21:44 +000061 self.expect("version",
Johnny Chen84939892011-01-06 00:03:01 +000062 patterns = ['LLDB-' + (version_str if version_str else '[0-9]+')])
Johnny Chen31c39da2010-12-23 20:21:44 +000063
Johnny Chen7e363f52010-06-28 20:55:57 +000064 def test_help_should_not_hang_emacsshell(self):
Johnny Chenecf9ded2010-09-07 16:19:35 +000065 """Command 'settings set term-width 0' should not hang the help command."""
66 self.runCmd("settings set term-width 0")
Johnny Chen74f26b82010-08-20 19:17:39 +000067 self.expect("help",
68 startstr = 'The following is a list of built-in, permanent debugger commands')
Johnny Chen9320d4a2010-06-25 23:15:47 +000069
Johnny Chen65045f22010-10-08 17:21:27 +000070 def test_help_image_dump_symtab_should_not_crash(self):
71 """Command 'help image dump symtab' should not crash lldb."""
Johnny Chen24f34902011-05-03 23:55:05 +000072 # 'image' is an alias for 'target modules'.
Johnny Chen65045f22010-10-08 17:21:27 +000073 self.expect("help image dump symtab",
Johnny Chen5aceec32011-05-03 23:18:45 +000074 substrs = ['dump symtab',
Johnny Chen65045f22010-10-08 17:21:27 +000075 'sort-order'])
76
Johnny Chen5237e902010-12-01 19:10:59 +000077 def test_help_image_du_sym_is_ambiguous(self):
78 """Command 'help image du sym' is ambiguous and spits out the list of candidates."""
79 self.expect("help image du sym",
80 COMMAND_FAILED_AS_EXPECTED, error=True,
81 substrs = ['error: ambiguous command image du sym',
82 'symfile',
83 'symtab'])
84
85 def test_help_image_du_line_should_work(self):
86 """Command 'help image du line' is not ambiguous and should work."""
Johnny Chen24f34902011-05-03 23:55:05 +000087 # 'image' is an alias for 'target modules'.
Johnny Chen5237e902010-12-01 19:10:59 +000088 self.expect("help image du line",
Johnny Chen5aceec32011-05-03 23:18:45 +000089 substrs = ['Dump the debug symbol file for one or more target modules'])
Johnny Chen5237e902010-12-01 19:10:59 +000090
Johnny Chen9320d4a2010-06-25 23:15:47 +000091
92if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +000093 import atexit
Johnny Chen4657be62010-06-29 19:44:16 +000094 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +000095 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +000096 unittest2.main()