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.
This commit is contained in:
parent
2ab17b6cca
commit
8e3f419c44
21
test.py
21
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 = ["+", "^", "%", "~", "[", "]", "<", ">", "(", ")"]
|
||||
|
Loading…
Reference in New Issue
Block a user