tests/heredoctest.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 13 Mar 2024 11:34:21 +0100
changeset 51596 6378d57562af
parent 48875 6000f5b25c9b
permissions -rw-r--r--
tags-cache: add a dedicated warm cache function to hgtagsfnodescache Having a dedicated API point will help to optimize that specific usage. Right doing a full phases weam takes a long time, even when the cache is already filled.

import sys


def flush():
    sys.stdout.flush()
    sys.stderr.flush()


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