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