TestHelp.py revision 7e0dbcf32a381c73d95cd69766462027a8dae0cd
1""" 2Test some lldb help commands. 3 4See also CommandInterpreter::OutputFormattedHelpText(). 5""" 6 7import os, time 8import unittest2 9import lldb 10from lldbtest import * 11 12class HelpCommandTestCase(TestBase): 13 14 mydir = "help" 15 16 def test_simplehelp(self): 17 """A simple test of 'help' command and its output.""" 18 self.expect("help", 19 startstr = 'The following is a list of built-in, permanent debugger commands') 20 21 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... 48 import traceback 49 traceback.print_exc() 50 pass 51 52 # Use None to signify that we are not able to grok the version number. 53 return None 54 55 56 def test_help_version(self): 57 """Test 'help version' and 'version' commands.""" 58 self.expect("help version", 59 substrs = ['Show version of LLDB debugger.']) 60 version_str = self.version_number_string() 61 self.expect("version", 62 patterns = ['LLDB-' + (version_str if version_str else '[0-9]+')]) 63 64 def test_help_should_not_hang_emacsshell(self): 65 """Command 'settings set term-width 0' should not hang the help command.""" 66 self.runCmd("settings set term-width 0") 67 self.expect("help", 68 startstr = 'The following is a list of built-in, permanent debugger commands') 69 70 def test_help_image_dump_symtab_should_not_crash(self): 71 """Command 'help image dump symtab' should not crash lldb.""" 72 self.expect("help image dump symtab", 73 substrs = ['dump symtab', 74 'sort-order']) 75 76 def test_help_image_du_sym_is_ambiguous(self): 77 """Command 'help image du sym' is ambiguous and spits out the list of candidates.""" 78 self.expect("help image du sym", 79 COMMAND_FAILED_AS_EXPECTED, error=True, 80 substrs = ['error: ambiguous command image du sym', 81 'symfile', 82 'symtab']) 83 84 def test_help_image_du_line_should_work(self): 85 """Command 'help image du line' is not ambiguous and should work.""" 86 self.expect("help image du line", 87 substrs = ['Dump the debug symbol file for one or more target modules']) 88 89 90if __name__ == '__main__': 91 import atexit 92 lldb.SBDebugger.Initialize() 93 atexit.register(lambda: lldb.SBDebugger.Terminate()) 94 unittest2.main() 95