-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorRegenExpect
More file actions
executable file
·60 lines (47 loc) · 2.18 KB
/
Copy pathcorRegenExpect
File metadata and controls
executable file
·60 lines (47 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Generic --EXPECT-- regenerator for corTest.
Fills a test's --EXPECT-- block verbatim from its captured .out content. This
is the repo-agnostic default used by `corTest --regen` when the consuming repo
does NOT provide its own regen tool.
Output-aware smart regeneration (wrapping process-/run-volatile tokens in
REGEX(...) so regenerated expectations stay stable) is inherently specific to
the program under test, so it lives in the consuming repo, not here. corTest's
--regen prefers a repo-provided tool at:
test/funcTests/tools/corRegenExpect
and only falls back to this verbatim version when that file is absent. After a
verbatim regen, hand-edit any volatile lines (timestamps, ids, …) into
REGEX(...) / #SORT blocks as needed.
Usage: corRegenExpect <testBaseName> [<testBaseName> ...]
Reads test/funcTests/cases/<base>.out and rewrites the --EXPECT-- block of
test/funcTests/cases/<base>.test.
"""
import re, sys, pathlib
CASES = pathlib.Path("test/funcTests/cases")
def update_test(base):
out_path = CASES / f"{base}.out"
test_path = CASES / f"{base}.test"
if not out_path.exists() or not test_path.exists():
print(f"SKIP {base}: missing files")
return False
new_expect = out_path.read_text()
test = test_path.read_text()
#
# The lookahead anchors on a section marker at the START OF A LINE, and does not
# eat the newline before it - so an EMPTY --EXPECT-- block (what --regen is handed)
# sitting directly above --TEARDOWN-- ends where it should. With '\n--[A-Z]+--' the
# zero-length match was impossible and '.*?' ran on to \Z, silently swallowing every
# section below EXPECT: the regenerated test lost its --TEARDOWN-- and from then on
# leaked a running broker into the next test.
#
pattern = re.compile(r'(--EXPECT--\n)(.*?)(?=^--[A-Z]+--|\Z)', re.DOTALL | re.MULTILINE)
if not pattern.search(test):
print(f"SKIP {base}: no --EXPECT-- block")
return False
new_test = pattern.sub(lambda m: m.group(1) + new_expect, test)
test_path.write_text(new_test)
print(f"OK {base}")
return True
if __name__ == "__main__":
for b in sys.argv[1:]:
update_test(b)