parser: reorder tests, fix check_test_order.py for new file layout
Update check_test_order.py to handle header/footer split correctly when infrastructure code is at both start and end of file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,20 +14,23 @@ def extract_test_names(path):
|
||||
|
||||
|
||||
def extract_test_blocks(path):
|
||||
"""Split file into infrastructure + list of (name, content) test blocks."""
|
||||
"""Split file into: header, list of (name, content) test blocks, footer."""
|
||||
with open(path) as f:
|
||||
lines = f.readlines()
|
||||
|
||||
infra = []
|
||||
header = []
|
||||
footer = []
|
||||
blocks = []
|
||||
current_name = None
|
||||
current_lines = []
|
||||
brace_depth = 0
|
||||
in_test = False
|
||||
found_first_test = False
|
||||
|
||||
for line in lines:
|
||||
m = re.match(r'^test "(.+?)" \{', line)
|
||||
if m and not in_test:
|
||||
found_first_test = True
|
||||
if current_name is not None:
|
||||
blocks.append((current_name, "".join(current_lines)))
|
||||
current_name = m.group(1)
|
||||
@@ -41,13 +44,35 @@ def extract_test_blocks(path):
|
||||
brace_depth += line.count("{") - line.count("}")
|
||||
if brace_depth == 0:
|
||||
in_test = False
|
||||
elif current_name is None:
|
||||
infra.append(line)
|
||||
elif not found_first_test:
|
||||
header.append(line)
|
||||
else:
|
||||
# Non-test content after tests started — could be blank lines
|
||||
# between tests or footer content
|
||||
if current_name is not None:
|
||||
# Append to previous test block as trailing content
|
||||
current_lines.append(line)
|
||||
else:
|
||||
footer.append(line)
|
||||
|
||||
if current_name is not None:
|
||||
blocks.append((current_name, "".join(current_lines)))
|
||||
|
||||
return "".join(infra), blocks
|
||||
# Anything after the last test block is footer
|
||||
# Split last block's trailing non-test content into footer
|
||||
if blocks:
|
||||
last_name, last_content = blocks[-1]
|
||||
last_lines = last_content.split('\n')
|
||||
# Find where the test block ends (} at column 0)
|
||||
test_end = len(last_lines)
|
||||
for i, line in enumerate(last_lines):
|
||||
if line == '}' and i > 0:
|
||||
test_end = i + 1
|
||||
if test_end < len(last_lines):
|
||||
blocks[-1] = (last_name, '\n'.join(last_lines[:test_end]) + '\n')
|
||||
footer = ['\n'.join(last_lines[test_end:]) + '\n'] + footer
|
||||
|
||||
return "".join(header), blocks, "".join(footer)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -88,7 +113,7 @@ def main():
|
||||
return 1
|
||||
|
||||
# Fix: reorder
|
||||
infra, blocks = extract_test_blocks(OURS)
|
||||
header, blocks, footer = extract_test_blocks(OURS)
|
||||
block_map = {name: content for name, content in blocks}
|
||||
|
||||
# Reorder: upstream-ordered first, then extras
|
||||
@@ -104,11 +129,11 @@ def main():
|
||||
seen.add(name)
|
||||
|
||||
with open(OURS, "w") as f:
|
||||
f.write(infra)
|
||||
f.write(header)
|
||||
for _, content in ordered:
|
||||
f.write("\n")
|
||||
f.write(content)
|
||||
f.write("\n")
|
||||
f.write(footer)
|
||||
|
||||
print(f"Fixed: {len(ordered)} tests reordered")
|
||||
return 0
|
||||
|
||||
589
parser_test.zig
589
parser_test.zig
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user