Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 1 | """Test lldb help command.""" |
| 2 | |
Johnny Chen | 8c3f918 | 2010-07-01 00:18:39 +0000 | [diff] [blame] | 3 | import os, time |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 4 | import lldb |
| 5 | import unittest |
| 6 | |
Johnny Chen | 119b53e | 2010-07-01 22:52:57 +0000 | [diff] [blame^] | 7 | main = False |
| 8 | |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 9 | class TestHelpCommand(unittest.TestCase): |
| 10 | |
| 11 | def setUp(self): |
Johnny Chen | 119b53e | 2010-07-01 22:52:57 +0000 | [diff] [blame^] | 12 | global main |
| 13 | |
Johnny Chen | cb9b857 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 14 | # Save old working directory. |
| 15 | self.oldcwd = os.getcwd() |
| 16 | # Change current working directory if ${LLDB_TEST} is defined. |
| 17 | if ("LLDB_TEST" in os.environ): |
| 18 | os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); |
Johnny Chen | 119b53e | 2010-07-01 22:52:57 +0000 | [diff] [blame^] | 19 | self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG |
Johnny Chen | 8c3f918 | 2010-07-01 00:18:39 +0000 | [diff] [blame] | 20 | if not self.dbg.IsValid(): |
| 21 | raise Exception('Invalid debugger instance') |
Johnny Chen | cb9b857 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 22 | self.dbg.SetAsync(False) |
| 23 | self.ci = self.dbg.GetCommandInterpreter() |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 24 | if not self.ci: |
| 25 | raise Exception('Could not get the command interpreter') |
| 26 | |
| 27 | def tearDown(self): |
Johnny Chen | cb9b857 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 28 | # Restore old working directory. |
| 29 | os.chdir(self.oldcwd) |
Johnny Chen | 119b53e | 2010-07-01 22:52:57 +0000 | [diff] [blame^] | 30 | del self.dbg |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 31 | |
| 32 | def test_simplehelp(self): |
| 33 | """A simple test of 'help' command and its output.""" |
| 34 | res = lldb.SBCommandReturnObject() |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 35 | self.ci.HandleCommand("help", res) |
Johnny Chen | 8c3f918 | 2010-07-01 00:18:39 +0000 | [diff] [blame] | 36 | time.sleep(0.1) |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 37 | self.assertTrue(res.Succeeded()) |
| 38 | self.assertTrue(res.GetOutput().startswith( |
| 39 | 'The following is a list of built-in, permanent debugger commands')) |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 40 | |
| 41 | def test_help_should_not_hang_emacsshell(self): |
Johnny Chen | 94a6899 | 2010-06-29 23:17:15 +0000 | [diff] [blame] | 42 | """Command 'set term-width 0' should not hang the help command.""" |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 43 | res = lldb.SBCommandReturnObject() |
| 44 | self.ci.HandleCommand("set term-width 0", res) |
Johnny Chen | 8c3f918 | 2010-07-01 00:18:39 +0000 | [diff] [blame] | 45 | time.sleep(0.1) |
Johnny Chen | 7e363f5 | 2010-06-28 20:55:57 +0000 | [diff] [blame] | 46 | self.assertTrue(res.Succeeded()) |
| 47 | self.ci.HandleCommand("help", res) |
Johnny Chen | 8c3f918 | 2010-07-01 00:18:39 +0000 | [diff] [blame] | 48 | time.sleep(0.1) |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 49 | self.assertTrue(res.Succeeded()) |
| 50 | self.assertTrue(res.GetOutput().startswith( |
| 51 | 'The following is a list of built-in, permanent debugger commands')) |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
Johnny Chen | 4657be6 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 55 | lldb.SBDebugger.Initialize() |
Johnny Chen | 119b53e | 2010-07-01 22:52:57 +0000 | [diff] [blame^] | 56 | main = True |
Johnny Chen | 9320d4a | 2010-06-25 23:15:47 +0000 | [diff] [blame] | 57 | unittest.main() |
Johnny Chen | 4657be6 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 58 | lldb.SBDebugger.Terminate() |