From 3de2a90574cdf8b0a76afcb3d843219c1387a8ff Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Wed, 30 Mar 2016 00:02:13 +0000 Subject: [PATCH] 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) (lldb) " where "" 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. llvm-svn: 264810 --- .../TestCommandScriptImmediateOutput.py | 6 +++--- .../command_script_immediate_output/custom_command.py | 4 ++-- lldb/packages/Python/lldbsuite/test/lldbpexpect.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py index 570745e..010dcfa 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/TestCommandScriptImmediateOutput.py @@ -29,8 +29,8 @@ class CommandScriptImmediateOutputTestCase (PExpectTest): 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 CommandScriptImmediateOutputTestCase (PExpectTest): 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]) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py index 03d688a..30a3cfb 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/command_script_immediate_output/custom_command.py @@ -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']: diff --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py index 952e789..d37d6fa 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py +++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py @@ -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 -- 2.7.4