tests/heredoctest.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 17 Feb 2018 11:19:52 -0700
changeset 36481 1fa35ca345a5
parent 29485 6a98f9408a50
child 40318 55fd0fefbec4
permissions -rw-r--r--
internals: document bundle2 format It seems like a good idea to have thorough documentation of the bundle2 data format, including the format of each part and the capabilities. The added documentation is far from complete. For example, we don't fully capture the semantics of each capability and part. But a start is better than nothing, which was pretty much where we were before. Differential Revision: https://phab.mercurial-scm.org/D2298

from __future__ import absolute_import, print_function

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, globalvars)
        except Exception as inst:
            print(repr(inst))