blob: 0cf7ddb2ba43cc3db0849296db2077afd268d600 [file] [log] [blame]
Johnny Chen9320d4a2010-06-25 23:15:47 +00001"""Test lldb help command."""
2
Johnny Chen8c3f9182010-07-01 00:18:39 +00003import os, time
Johnny Chen9320d4a2010-06-25 23:15:47 +00004import lldb
5import unittest
6
Johnny Chen119b53e2010-07-01 22:52:57 +00007main = False
8
Johnny Chen9320d4a2010-06-25 23:15:47 +00009class TestHelpCommand(unittest.TestCase):
10
11 def setUp(self):
Johnny Chen119b53e2010-07-01 22:52:57 +000012 global main
13
Johnny Chencb9b8572010-06-29 23:10:39 +000014 # 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 Chen119b53e2010-07-01 22:52:57 +000019 self.dbg = lldb.SBDebugger.Create() if main else lldb.DBG
Johnny Chen8c3f9182010-07-01 00:18:39 +000020 if not self.dbg.IsValid():
21 raise Exception('Invalid debugger instance')
Johnny Chencb9b8572010-06-29 23:10:39 +000022 self.dbg.SetAsync(False)
23 self.ci = self.dbg.GetCommandInterpreter()
Johnny Chen9320d4a2010-06-25 23:15:47 +000024 if not self.ci:
25 raise Exception('Could not get the command interpreter')
26
27 def tearDown(self):
Johnny Chencb9b8572010-06-29 23:10:39 +000028 # Restore old working directory.
29 os.chdir(self.oldcwd)
Johnny Chen119b53e2010-07-01 22:52:57 +000030 del self.dbg
Johnny Chen9320d4a2010-06-25 23:15:47 +000031
32 def test_simplehelp(self):
33 """A simple test of 'help' command and its output."""
34 res = lldb.SBCommandReturnObject()
Johnny Chen7e363f52010-06-28 20:55:57 +000035 self.ci.HandleCommand("help", res)
Johnny Chen8c3f9182010-07-01 00:18:39 +000036 time.sleep(0.1)
Johnny Chen7e363f52010-06-28 20:55:57 +000037 self.assertTrue(res.Succeeded())
38 self.assertTrue(res.GetOutput().startswith(
39 'The following is a list of built-in, permanent debugger commands'))
Johnny Chen7e363f52010-06-28 20:55:57 +000040
41 def test_help_should_not_hang_emacsshell(self):
Johnny Chen94a68992010-06-29 23:17:15 +000042 """Command 'set term-width 0' should not hang the help command."""
Johnny Chen7e363f52010-06-28 20:55:57 +000043 res = lldb.SBCommandReturnObject()
44 self.ci.HandleCommand("set term-width 0", res)
Johnny Chen8c3f9182010-07-01 00:18:39 +000045 time.sleep(0.1)
Johnny Chen7e363f52010-06-28 20:55:57 +000046 self.assertTrue(res.Succeeded())
47 self.ci.HandleCommand("help", res)
Johnny Chen8c3f9182010-07-01 00:18:39 +000048 time.sleep(0.1)
Johnny Chen9320d4a2010-06-25 23:15:47 +000049 self.assertTrue(res.Succeeded())
50 self.assertTrue(res.GetOutput().startswith(
51 'The following is a list of built-in, permanent debugger commands'))
Johnny Chen9320d4a2010-06-25 23:15:47 +000052
53
54if __name__ == '__main__':
Johnny Chen4657be62010-06-29 19:44:16 +000055 lldb.SBDebugger.Initialize()
Johnny Chen119b53e2010-07-01 22:52:57 +000056 main = True
Johnny Chen9320d4a2010-06-25 23:15:47 +000057 unittest.main()
Johnny Chen4657be62010-06-29 19:44:16 +000058 lldb.SBDebugger.Terminate()