2011-04-21 05:51:31 +08:00
"""
Test lldb ' commands regex ' command which allows the user to create a regular expression command .
"""
import os
import unittest2
import lldb
from lldbtest import *
class CommandRegexTestCase ( TestBase ) :
2013-12-11 07:19:29 +08:00
mydir = TestBase . compute_mydir ( __file__ )
2011-04-21 05:51:31 +08:00
def test_command_regex ( self ) :
2014-01-28 07:43:24 +08:00
""" Test a simple scenario of ' command regex ' invocation and subsequent use. """
2014-07-18 09:02:02 +08:00
import pexpect
2011-05-04 06:14:19 +08:00
prompt = " (lldb) "
2014-01-28 07:43:24 +08:00
regex_prompt = " Enter one of more sed substitution commands in the form: ' s/<regex>/<subst>/ ' . \r \n Terminate the substitution list with an empty line. \r \n "
2011-04-21 05:51:31 +08:00
regex_prompt1 = " \r \n "
2011-10-08 03:21:09 +08:00
child = pexpect . spawn ( ' %s %s ' % ( self . lldbHere , self . lldbOption ) )
2011-04-21 05:51:31 +08:00
# Turn on logging for what the child sends back.
2011-04-21 06:01:48 +08:00
if self . TraceOn ( ) :
2011-04-21 05:51:31 +08:00
child . logfile_read = sys . stdout
2011-04-23 05:47:07 +08:00
# So that the spawned lldb session gets shutdown durng teardown.
self . child = child
2011-04-21 05:51:31 +08:00
2011-05-04 06:14:19 +08:00
# Substitute 'Help!' for 'help' using the 'commands regex' mechanism.
child . expect_exact ( prompt )
2011-11-01 06:22:06 +08:00
child . sendline ( " command regex ' Help__ ' " )
2011-05-04 06:14:19 +08:00
child . expect_exact ( regex_prompt )
2011-04-21 05:51:31 +08:00
child . sendline ( ' s/^$/help/ ' )
2011-05-04 06:14:19 +08:00
child . expect_exact ( regex_prompt1 )
2011-04-21 05:51:31 +08:00
child . sendline ( ' ' )
2014-11-18 08:39:31 +08:00
child . expect_exact ( prompt )
2011-04-21 05:51:31 +08:00
# Help!
2011-11-01 06:22:06 +08:00
child . sendline ( ' Help__ ' )
2011-04-21 05:51:31 +08:00
# If we see the familiar 'help' output, the test is done.
2011-04-23 05:47:07 +08:00
child . expect ( ' The following is a list of built-in, permanent debugger commands: ' )
2015-01-10 03:08:20 +08:00
# Try and incorrectly remove "Help__" using "command unalias" and verify we fail
child . sendline ( ' command unalias Help__ ' )
child . expect_exact ( " error: ' Help__ ' is not an alias, it is a debugger command which can be removed using the ' command delete ' command " )
child . expect_exact ( prompt )
# Delete the regex command using "command delete"
child . sendline ( ' command delete Help__ ' )
child . expect_exact ( prompt )
# Verify the command was removed
child . sendline ( ' Help__ ' )
child . expect_exact ( " error: ' Help__ ' is not a valid command " )
child . expect_exact ( prompt )
2011-04-21 05:51:31 +08:00
if __name__ == ' __main__ ' :
import atexit
lldb . SBDebugger . Initialize ( )
atexit . register ( lambda : lldb . SBDebugger . Terminate ( ) )
unittest2 . main ( )