[Lldb-commits] [lldb] r264810 - Fixed the failing test TestCommandScriptImmediateOutput on MacOSX. Turns out that there are few things to watch out for when writing pexpect tests:
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 29 17:02:14 PDT 2016
Author: gclayton
Date: Tue Mar 29 19:02:13 2016
New Revision: 264810
URL: http://llvm.org/viewvc/llvm-project?rev=264810&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.
Modified:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
lldb/trunk/packages/Python/lldbsuite/test/lldbpexpect.py
Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py?rev=264810&r1=264809&r2=264810&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py Tue Mar 29 19:02:13 2016
@@ -29,8 +29,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')
@@ -52,7 +52,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/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py?rev=264810&r1=264809&r2=264810&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py Tue Mar 29 19:02:13 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/trunk/packages/Python/lldbsuite/test/lldbpexpect.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbpexpect.py?rev=264810&r1=264809&r2=264810&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lldbpexpect.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/lldbpexpect.py Tue Mar 29 19:02:13 2016
@@ -32,7 +32,7 @@ else:
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 lldb-commits
mailing list