Home | History | Annotate | Download | only in command_regex
      1 """
      2 Test lldb 'commands regex' command which allows the user to create a regular expression command.
      3 """
      4 
      5 import os
      6 import unittest2
      7 import lldb
      8 import pexpect
      9 from lldbtest import *
     10 
     11 class CommandRegexTestCase(TestBase):
     12 
     13     mydir = os.path.join("functionalities", "command_regex")
     14 
     15     def test_command_regex(self):
     16         """Test a simple scenario of 'command regexp' invocation and subsequent use."""
     17         prompt = "(lldb) "
     18         regex_prompt = "Enter regular expressions in the form 's/<regex>/<subst>/' and terminate with an empty line:\r\n"
     19         regex_prompt1 = "\r\n"
     20 
     21         child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption))
     22         # Turn on logging for what the child sends back.
     23         if self.TraceOn():
     24             child.logfile_read = sys.stdout
     25         # So that the spawned lldb session gets shutdown durng teardown.
     26         self.child = child
     27 
     28         # Substitute 'Help!' for 'help' using the 'commands regex' mechanism.
     29         child.expect_exact(prompt)
     30         child.sendline("command regex 'Help__'")
     31         child.expect_exact(regex_prompt)
     32         child.sendline('s/^$/help/')
     33         child.expect_exact(regex_prompt1)
     34         child.sendline('')
     35         # Help!
     36         child.sendline('Help__')
     37         # If we see the familiar 'help' output, the test is done.
     38         child.expect('The following is a list of built-in, permanent debugger commands:')
     39 
     40 if __name__ == '__main__':
     41     import atexit
     42     lldb.SBDebugger.Initialize()
     43     atexit.register(lambda: lldb.SBDebugger.Terminate())
     44     unittest2.main()
     45