[llvm-branch-commits] [lldb] r270138 - Fixed the failing test TestCommandScriptImmediateOutput on MacOSX. Turns out that there are few things to watch out for when writing pexpect tests:
Francis Ricci via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 19 14:09:04 PDT 2016
Author: fjricci
Date: Thu May 19 16:09:04 2016
New Revision: 270138
URL: http://llvm.org/viewvc/llvm-project?rev=270138&view=rev
Log:
Fixed the failing test TestCommandScriptImmediateOutput on MacOSX. Turns out that there are few things to watch out for when writing pexpect tests:
1 - If you plan on looking for the "(lldb) " prompt as a regular expression, look for "\(lldb\) " so you don't just find "lldb".
2 - Make sure to not use colors (specify --no-use-colors as an option to lldb when launching it) as our editline will print:
"(lldb) <color junk>(lldb) "
where "<color junk>" is a work around that is used to allow us to colorize our prompts. The bad thing is this will make pexepct code like this not execute as you would expect:
prompt = "\(lldb\) "
self.child.sendline("breakpoint set ...", prompt)
self.child.sendline("breakpoint clear ...", prompt)
The problem is the first "sendline" will create two lldb prompts and will match both the first and second prompts and you output will get off. So be sure to disable colors if you need to.
Fixed a case where "TestCommandScriptImmediateOutput.py" would fail if you have spaces in your directory names. I modified custom_command.py to use shlex to parse arguments and I quoted the file path we sent down to the custom_command.write_file function.
Author: Greg Clayton <gclayton at apple.com>
Date: Wed Mar 30 00:02:13 2016 +0000
This is a cherry-pick of r264810
Modified:
lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
lldb/branches/release_38/packages/Python/lldbsuite/test/lldbpexpect.py
Modified: lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py?rev=270138&r1=270137&r2=270138&view=diff
==============================================================================
--- lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py (original)
+++ lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py Thu May 19 16:09:04 2016
@@ -28,8 +28,8 @@ class CommandScriptImmediateOutputTestCa
self.launch(timeout=60)
script = os.path.join(os.getcwd(), 'custom_command.py')
- prompt = "(lldb)"
-
+ prompt = "\(lldb\) "
+
self.sendline('command script import %s' % script, patterns=[prompt])
self.sendline('command script add -f custom_command.command_function mycommand', patterns=[prompt])
self.sendline('mycommand', patterns='this is a test string, just a test string')
@@ -51,7 +51,7 @@ class CommandScriptImmediateOutputTestCa
self.sendline('command script add -f custom_command.write_file mywrite', patterns=[prompt])
for path, mode in test_files.iteritems():
- command = 'mywrite ' + path + ' ' + mode
+ command = 'mywrite "' + path + '" ' + mode
self.sendline(command, patterns=[prompt])
Modified: lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py?rev=270138&r1=270137&r2=270138&view=diff
==============================================================================
--- lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py (original)
+++ lldb/branches/release_38/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py Thu May 19 16:09:04 2016
@@ -1,16 +1,16 @@
from __future__ import print_function
import sys
+import shlex
def command_function(debugger, command, exe_ctx, result, internal_dict):
result.SetImmediateOutputFile(sys.__stdout__)
print('this is a test string, just a test string', file=result)
def write_file(debugger, command, exe_ctx, result, internal_dict):
- args = command.split(' ')
+ args = shlex.split(command)
path = args[0]
mode = args[1]
-
with open(path, mode) as f:
result.SetImmediateOutputFile(f)
if not mode in ['r']:
Modified: lldb/branches/release_38/packages/Python/lldbsuite/test/lldbpexpect.py
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_38/packages/Python/lldbsuite/test/lldbpexpect.py?rev=270138&r1=270137&r2=270138&view=diff
==============================================================================
--- lldb/branches/release_38/packages/Python/lldbsuite/test/lldbpexpect.py (original)
+++ lldb/branches/release_38/packages/Python/lldbsuite/test/lldbpexpect.py Thu May 19 16:09:04 2016
@@ -26,7 +26,7 @@ class PExpectTest(TestBase):
def launch(self, timeout=None):
if timeout is None: timeout = 30
logfile = sys.stdout if self.TraceOn() else None
- self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.launchArgs()), logfile=logfile)
+ self.child = pexpect.spawn('%s --no-use-colors %s' % (lldbtest_config.lldbExec, self.launchArgs()), logfile=logfile)
self.child.timeout = timeout
self.timeout = timeout
More information about the llvm-branch-commits
mailing list