From 8e3f419c44371f3d279b78058059089575718e34 Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Wed, 8 Aug 2012 19:33:07 -0400 Subject: [PATCH] Fix tests to work with new version of screen Debian unstable currently has a pre-release version of screen 4.1.0. This version changes the "stuff" command so that special characters get parsed, breaking many of the tests. Detect if the version of screen being used to run tests does this parsing, and if so do additional escaping of characters so that tests again work. With this change, all tests pass with both old and new versions of screen. --- test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test.py b/test.py index 35ea68c..68aeccc 100755 --- a/test.py +++ b/test.py @@ -92,14 +92,35 @@ class VimInterface: class VimInterfaceScreen(VimInterface): def __init__(self, session): self.session = session + self.need_screen_escapes = 0 + self.detect_parsing() def send(self, s): + if self.need_screen_escapes: + # escape characters that are special to some versions of screen + repl = lambda m: '\\' + m.group(0) + s = re.sub( r"[$^#\\']", repl, s ) + + # Escape single quotes in command to protect from shell s = s.replace("'", r"'\''") cmd = "screen -x %s -X stuff '%s'" % (self.session, s) if sys.version_info >= (3,0): cmd = cmd.encode("utf-8") os.system(cmd) + def detect_parsing(self): + # Clear the buffer + self.send("bggVGd") + + # Send a string where the interpretation will depend on version of screen + string = "$TERM" + self.send("i" + string + ESC) + output = self.get_buffer_data() + + # If the output doesn't match the input, need to do additional escaping + if output != string: + self.need_screen_escapes = 1 + class VimInterfaceWindows(VimInterface): BRACES = re.compile("([}{])") WIN_ESCAPES = ["+", "^", "%", "~", "[", "]", "<", ">", "(", ")"]