2011-04-20 21:51:31 +00: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-10 23:19:29 +00:00
mydir = TestBase . compute_mydir ( __file__ )
2011-04-20 21:51:31 +00:00
2015-05-08 14:20:25 +00:00
@expectedFailureFreeBSD ( " llvm.org/pr22784: pexpect failing on the FreeBSD buildbot " )
2015-01-20 22:36:03 +00:00
@expectedFailureWindows ( " llvm.org/pr22274: need a pexpect replacement for windows " )
2011-04-20 21:51:31 +00:00
def test_command_regex ( self ) :
2014-01-27 23:43:24 +00:00
""" Test a simple scenario of ' command regex ' invocation and subsequent use. """
2014-07-18 01:02:02 +00:00
import pexpect
2011-05-03 22:14:19 +00:00
prompt = " (lldb) "
2014-01-27 23:43:24 +00: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-20 21:51:31 +00:00
regex_prompt1 = " \r \n "
2011-10-07 19:21:09 +00:00
child = pexpect . spawn ( ' %s %s ' % ( self . lldbHere , self . lldbOption ) )
2011-04-20 21:51:31 +00:00
# Turn on logging for what the child sends back.
2011-04-20 22:01:48 +00:00
if self . TraceOn ( ) :
2011-04-20 21:51:31 +00:00
child . logfile_read = sys . stdout
2011-04-22 21:47:07 +00:00
# So that the spawned lldb session gets shutdown durng teardown.
self . child = child
2011-04-20 21:51:31 +00:00
2011-05-03 22:14:19 +00:00
# Substitute 'Help!' for 'help' using the 'commands regex' mechanism.
child . expect_exact ( prompt )
2011-10-31 22:22:06 +00:00
child . sendline ( " command regex ' Help__ ' " )
2011-05-03 22:14:19 +00:00
child . expect_exact ( regex_prompt )
2011-04-20 21:51:31 +00:00
child . sendline ( ' s/^$/help/ ' )
2011-05-03 22:14:19 +00:00
child . expect_exact ( regex_prompt1 )
2011-04-20 21:51:31 +00:00
child . sendline ( ' ' )
2014-11-18 00:39:31 +00:00
child . expect_exact ( prompt )
2011-04-20 21:51:31 +00:00
# Help!
2011-10-31 22:22:06 +00:00
child . sendline ( ' Help__ ' )
2011-04-20 21:51:31 +00:00
# If we see the familiar 'help' output, the test is done.
2015-01-15 22:52:17 +00:00
child . expect ( ' Debugger commands: ' )
2015-01-09 19:08:20 +00: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-20 21:51:31 +00:00
if __name__ == ' __main__ ' :
import atexit
lldb . SBDebugger . Initialize ( )
atexit . register ( lambda : lldb . SBDebugger . Terminate ( ) )
unittest2 . main ( )