sapling/tests/heredoctest.py
Yuya Nishihara 7c09e032d1 heredoctest: do not append extra newline character to continuation line
Trailing newline characters are kept in lines.
2014-09-28 15:13:35 +09:00

19 lines
467 B
Python

import sys
globalvars = {}
lines = sys.stdin.readlines()
while lines:
l = lines.pop(0)
if l.startswith('SALT'):
print l[:-1]
elif l.startswith('>>> '):
snippet = l[4:]
while lines and lines[0].startswith('... '):
l = lines.pop(0)
snippet += l[4:]
c = compile(snippet, '<heredoc>', 'single')
try:
exec c in globalvars
except Exception, inst:
print repr(inst)