tests/heredoctest.py
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 23 Jan 2015 14:09:49 -0800
changeset 24004 8a5267cd5286
parent 22565 8d45a42b0c0f
child 25032 1db2127d2373
permissions -rw-r--r--
parsers: rewrite index_ancestors() in terms of index_commonancestorsheads() The first 80% of index_ancestors() is identical to index_commonancestorsheads(), so just call that function instead.

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)