Changed TestBase.expect() to allow default 'msg' arg. Converted TestHelp.py.

llvm-svn: 111671
This commit is contained in:
Johnny Chen 2010-08-20 19:17:39 +00:00
parent 7110941d68
commit 74f26b8188
2 changed files with 10 additions and 19 deletions

View File

@ -15,23 +15,14 @@ class TestHelpCommand(TestBase):
def test_simplehelp(self):
"""A simple test of 'help' command and its output."""
res = lldb.SBCommandReturnObject()
self.ci.HandleCommand("help", res)
self.assertTrue(res.Succeeded() and
res.GetOutput().startswith(
'The following is a list of built-in, permanent debugger commands'),
CMD_MSG('help'))
self.expect("help",
startstr = 'The following is a list of built-in, permanent debugger commands')
def test_help_should_not_hang_emacsshell(self):
"""Command 'set term-width 0' should not hang the help command."""
res = lldb.SBCommandReturnObject()
self.ci.HandleCommand("set term-width 0", res)
self.assertTrue(res.Succeeded(), CMD_MSG('set term-width 0'))
self.ci.HandleCommand("help", res)
self.assertTrue(res.Succeeded() and
res.GetOutput().startswith(
'The following is a list of built-in, permanent debugger commands'),
CMD_MSG('help'))
self.runCmd("set term-width 0")
self.expect("help",
startstr = 'The following is a list of built-in, permanent debugger commands')
if __name__ == '__main__':

View File

@ -141,7 +141,7 @@ class TestBase(unittest2.TestCase):
self.assertTrue(self.res.Succeeded(),
msg if msg else CMD_MSG(cmd))
def expect(self, cmd, msg, startstr=None, substrs=None, verbose=False):
def expect(self, cmd, msg=None, startstr=None, substrs=None, verbose=False):
"""
Similar to runCmd; with additional expect style output matching ability.
@ -150,11 +150,11 @@ class TestBase(unittest2.TestCase):
message. We expect the output from running the command to start with
'startstr' and matches the substrings contained in 'substrs'.
"""
# Fail fast if 'msg' is not meaningful.
if not msg or len(msg) == 0:
raise Exception("Bad 'msg' parameter encountered")
# First run the command.
self.runCmd(cmd, verbose = (True if verbose else False))
# Then compare the output against expected strings.
output = self.res.GetOutput()
matched = output.startswith(startstr) if startstr else True
@ -169,5 +169,5 @@ class TestBase(unittest2.TestCase):
print "Substring not matched:", str
break
self.assertTrue(matched, msg)
self.assertTrue(matched, msg if msg else CMD_MSG(cmd))