comparison tests/testlib/heredoctest.py @ 52594:b0ecab6773cf

run-tests: call heredoctest.py directly Since we know exactly where it is, there is not need to use `python -m heredoctest` to call it, we can just call that script. We more the script in "testlib" to reduce the test directory clutter. We might want to create a "tooling" directory in the future for this kind of utility.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 02 Jan 2025 16:22:14 +0100
parents tests/heredoctest.py@6000f5b25c9b
children
comparison
equal deleted inserted replaced
52593:eef540baab65 52594:b0ecab6773cf
1 import sys
2
3
4 def flush():
5 sys.stdout.flush()
6 sys.stderr.flush()
7
8
9 globalvars = {}
10 lines = sys.stdin.readlines()
11 while lines:
12 l = lines.pop(0)
13 if l.startswith('SALT'):
14 print(l[:-1])
15 elif l.startswith('>>> '):
16 snippet = l[4:]
17 while lines and lines[0].startswith('... '):
18 l = lines.pop(0)
19 snippet += l[4:]
20 c = compile(snippet, '<heredoc>', 'single')
21 try:
22 flush()
23 exec(c, globalvars)
24 flush()
25 except Exception as inst:
26 flush()
27 print(repr(inst))