Skip to content

Commit d71c8cc

Browse files
committed
[utils] run the formatter on update-verify-tests (NFC)
1 parent 3891080 commit d71c8cc

File tree

2 files changed

+147
-34
lines changed

2 files changed

+147
-34
lines changed

utils/update-verify-tests.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030

3131
def main():
3232
parser = argparse.ArgumentParser(description=__doc__)
33-
parser.add_argument(
34-
"--prefix", default="", help="The prefix passed to -verify"
35-
)
33+
parser.add_argument("--prefix", default="", help="The prefix passed to -verify")
3634
args = parser.parse_args()
3735
(ret_code, output) = check_expectations(sys.stdin.readlines(), args.prefix)
3836
print(output)
@@ -41,4 +39,3 @@ def main():
4139

4240
if __name__ == "__main__":
4341
main()
44-

utils/update_verify_tests/core.py

Lines changed: 146 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ def render(self):
159159
standard single space, let it be to avoid disrupting manual formatting.
160160
"""
161161
whitespace2_s = ""
162-
col_s = f":{self.col}" if self.col and (self.category == "expansion" or self.is_from_source_file) else ""
162+
col_s = (
163+
f":{self.col}"
164+
if self.col and (self.category == "expansion" or self.is_from_source_file)
165+
else ""
166+
)
163167
base_s = f"//{whitespace1_s}expected-{self.prefix}{self.category}{re_s}{line_location_s}{col_s}{whitespace2_s}{count_s}"
164168
if self.category == "expansion":
165169
return base_s + "{{"
@@ -175,7 +179,7 @@ def __init__(self, whitespace, line):
175179
self.category = "closing"
176180

177181
def render(self):
178-
return "//"+self.whitespace+"}}"
182+
return "//" + self.whitespace + "}}"
179183

180184

181185
expected_diag_re = re.compile(
@@ -184,9 +188,7 @@ def render(self):
184188
expected_expansion_diag_re = re.compile(
185189
r"//(\s*)expected-([a-zA-Z-]*)(expansion)(-re)?(@[+-]?\d+)(:\d+)(\s*)(\d+)?\{\{(.*)"
186190
)
187-
expected_expansion_close_re = re.compile(
188-
r"//(\s*)\}\}"
189-
)
191+
expected_expansion_close_re = re.compile(r"//(\s*)\}\}")
190192

191193

192194
def parse_diag(line, filename, prefix):
@@ -317,7 +319,16 @@ def infer_line_context(target, line_n):
317319
return (prev_line, total_offset, new_line_n)
318320

319321

320-
def add_diag(orig_target_line_n, col, diag_s, diag_category, lines, orig_lines, prefix, nested_context):
322+
def add_diag(
323+
orig_target_line_n,
324+
col,
325+
diag_s,
326+
diag_category,
327+
lines,
328+
orig_lines,
329+
prefix,
330+
nested_context,
331+
):
321332
if nested_context:
322333
prev_line = None
323334
for line in lines:
@@ -339,7 +350,11 @@ def add_diag(orig_target_line_n, col, diag_s, diag_category, lines, orig_lines,
339350

340351
whitespace_strings = None
341352
if prev_line.diag:
342-
whitespace_strings = prev_line.diag.whitespace_strings.copy() if prev_line.diag.whitespace_strings else None
353+
whitespace_strings = (
354+
prev_line.diag.whitespace_strings.copy()
355+
if prev_line.diag.whitespace_strings
356+
else None
357+
)
343358
if prev_line.diag == nested_context:
344359
if not whitespace_strings:
345360
whitespace_strings = [" ", "", ""]
@@ -425,12 +440,21 @@ def expand_expansions(lines):
425440
def error_refers_to_diag(diag_error, diag, target_line_n):
426441
if diag_error.col and diag.col and diag_error.col != diag.col:
427442
return False
428-
return target_line_n == diag.absolute_target() and diag_error.category == diag.category and (diag.category == "expansion" or diag_error.content == diag.diag_content)
443+
return (
444+
target_line_n == diag.absolute_target()
445+
and diag_error.category == diag.category
446+
and (diag.category == "expansion" or diag_error.content == diag.diag_content)
447+
)
429448

430449

431450
def find_other_targeting(lines, orig_lines, is_nested, diag_error):
432451
if is_nested:
433-
other_diags = [line.diag for line in lines if line.diag and error_refers_to_diag(diag_error, line.diag, diag_error.line)]
452+
other_diags = [
453+
line.diag
454+
for line in lines
455+
if line.diag
456+
and error_refers_to_diag(diag_error, line.diag, diag_error.line)
457+
]
434458
else:
435459
target = orig_lines[diag_error.line - 1]
436460
other_diags = [
@@ -460,19 +484,43 @@ def update_lines(diag_errors, lines, orig_lines, prefix, filename, nested_contex
460484

461485
diag_errors.sort(reverse=True, key=lambda diag_error: diag_error.line)
462486
for diag_error in diag_errors:
463-
if not isinstance(diag_error, ExtraDiag) and not isinstance(diag_error, NestedDiag):
487+
if not isinstance(diag_error, ExtraDiag) and not isinstance(
488+
diag_error, NestedDiag
489+
):
464490
continue
465-
other_diags = find_other_targeting(lines, orig_lines, bool(nested_context), diag_error)
491+
other_diags = find_other_targeting(
492+
lines, orig_lines, bool(nested_context), diag_error
493+
)
466494
diag = other_diags[0] if other_diags else None
467495
if diag:
468496
diag.increment_count()
469497
else:
470-
diag = add_diag(diag_error.line, diag_error.col, diag_error.content, diag_error.category, lines, orig_lines, diag_error.prefix, nested_context)
498+
diag = add_diag(
499+
diag_error.line,
500+
diag_error.col,
501+
diag_error.content,
502+
diag_error.category,
503+
lines,
504+
orig_lines,
505+
diag_error.prefix,
506+
nested_context,
507+
)
471508
if isinstance(diag_error, NestedDiag):
472509
if not diag.closer:
473-
whitespace = diag.whitespace_strings[0] if diag.whitespace_strings else " "
474-
diag.closer = Line(get_indent(diag.line.content) + "//" + whitespace + "}}\n", None)
475-
update_lines([diag_error.nested], diag.nested_lines, orig_lines, prefix, diag_error.file, diag)
510+
whitespace = (
511+
diag.whitespace_strings[0] if diag.whitespace_strings else " "
512+
)
513+
diag.closer = Line(
514+
get_indent(diag.line.content) + "//" + whitespace + "}}\n", None
515+
)
516+
update_lines(
517+
[diag_error.nested],
518+
diag.nested_lines,
519+
orig_lines,
520+
prefix,
521+
diag_error.file,
522+
diag,
523+
)
476524

477525

478526
def update_test_file(filename, diag_errors, prefix, updated_test_files):
@@ -482,7 +530,7 @@ def update_test_file(filename, diag_errors, prefix, updated_test_files):
482530
else:
483531
updated_test_files.add(filename)
484532
with open(filename, "r") as f:
485-
lines = [Line(line, i + 1) for i, line in enumerate(f.readlines() + [''])]
533+
lines = [Line(line, i + 1) for i, line in enumerate(f.readlines() + [""])]
486534
orig_lines = list(lines)
487535

488536
expansion_context = []
@@ -544,7 +592,9 @@ def update_test_files(errors, prefix):
544592
a = 2
545593
^
546594
"""
547-
diag_error_re2 = re.compile(r"(\S+):(\d+):(\d+): error: unexpected (\S+) produced: (.*)")
595+
diag_error_re2 = re.compile(
596+
r"(\S+):(\d+):(\d+): error: unexpected (\S+) produced: (.*)"
597+
)
548598

549599

550600
"""
@@ -634,35 +684,102 @@ def check_expectations(tool_output, prefix):
634684
if not "error:" in line:
635685
pass
636686
elif m := diag_error_re.match(line):
637-
diag = parse_diag(Line(tool_output[i+1], int(m.group(2))), m.group(1), prefix)
687+
diag = parse_diag(
688+
Line(tool_output[i + 1], int(m.group(2))), m.group(1), prefix
689+
)
638690
i += 2
639-
curr.append(NotFoundDiag(m.group(1), int(m.group(2)), int(m.group(3)), m.group(4), diag.diag_content, diag.prefix))
691+
curr.append(
692+
NotFoundDiag(
693+
m.group(1),
694+
int(m.group(2)),
695+
int(m.group(3)),
696+
m.group(4),
697+
diag.diag_content,
698+
diag.prefix,
699+
)
700+
)
640701
elif m := diag_error_re2.match(line):
641-
curr.append(ExtraDiag(m.group(1), int(m.group(2)), int(m.group(3)), m.group(4), m.group(5), prefix))
702+
curr.append(
703+
ExtraDiag(
704+
m.group(1),
705+
int(m.group(2)),
706+
int(m.group(3)),
707+
m.group(4),
708+
m.group(5),
709+
prefix,
710+
)
711+
)
642712
i += 2
643713
# Create two mirroring mismatches when the compiler reports that the category or diagnostic is incorrect.
644714
# This makes it easier to handle cases where the same diagnostic is mentioned both in an incorrect message/category
645715
# diagnostic, as well as in an error not produced diagnostic. This can happen for things like 'expected-error 2{{foo}}'
646716
# if only one diagnostic is emitted on that line, and the content of that diagnostic is actually 'bar'.
647717
elif m := diag_error_re3.match(line):
648-
diag = parse_diag(Line(tool_output[i+1], int(m.group(2))), m.group(1), prefix)
649-
curr.append(NotFoundDiag(m.group(1), int(m.group(2)), int(m.group(3)), diag.category, diag.diag_content, diag.prefix))
650-
curr.append(ExtraDiag(m.group(1), diag.absolute_target(), int(m.group(3)), diag.category, tool_output[i+3].strip(), diag.prefix))
718+
diag = parse_diag(
719+
Line(tool_output[i + 1], int(m.group(2))), m.group(1), prefix
720+
)
721+
curr.append(
722+
NotFoundDiag(
723+
m.group(1),
724+
int(m.group(2)),
725+
int(m.group(3)),
726+
diag.category,
727+
diag.diag_content,
728+
diag.prefix,
729+
)
730+
)
731+
curr.append(
732+
ExtraDiag(
733+
m.group(1),
734+
diag.absolute_target(),
735+
int(m.group(3)),
736+
diag.category,
737+
tool_output[i + 3].strip(),
738+
diag.prefix,
739+
)
740+
)
651741
i += 3
652742
elif m := diag_error_re4.match(line):
653-
diag = parse_diag(Line(tool_output[i+1], int(m.group(2))), m.group(1), prefix)
743+
diag = parse_diag(
744+
Line(tool_output[i + 1], int(m.group(2))), m.group(1), prefix
745+
)
654746
assert diag.category == m.group(4)
655-
assert tool_output[i+3].strip() == m.group(5)
656-
curr.append(NotFoundDiag(m.group(1), int(m.group(2)), int(m.group(3)), diag.category, diag.diag_content, diag.prefix))
657-
curr.append(ExtraDiag(m.group(1), diag.absolute_target(), int(m.group(3)), m.group(5), diag.diag_content, diag.prefix))
747+
assert tool_output[i + 3].strip() == m.group(5)
748+
curr.append(
749+
NotFoundDiag(
750+
m.group(1),
751+
int(m.group(2)),
752+
int(m.group(3)),
753+
diag.category,
754+
diag.diag_content,
755+
diag.prefix,
756+
)
757+
)
758+
curr.append(
759+
ExtraDiag(
760+
m.group(1),
761+
diag.absolute_target(),
762+
int(m.group(3)),
763+
m.group(5),
764+
diag.diag_content,
765+
diag.prefix,
766+
)
767+
)
658768
i += 3
659769
else:
660770
dprint("no match")
661771
dprint(line.strip())
662772
i += 1
663773

664-
while curr and i < len(tool_output) and (m := diag_expansion_note_re.match(tool_output[i].strip())):
665-
curr = [NestedDiag(m.group(1), int(m.group(2)), int(m.group(3)), e) for e in curr]
774+
while (
775+
curr
776+
and i < len(tool_output)
777+
and (m := diag_expansion_note_re.match(tool_output[i].strip()))
778+
):
779+
curr = [
780+
NestedDiag(m.group(1), int(m.group(2)), int(m.group(3)), e)
781+
for e in curr
782+
]
666783
i += 3
667784
top_level.extend(curr)
668785

@@ -672,4 +789,3 @@ def check_expectations(tool_output, prefix):
672789
return (0, update_test_files(top_level, prefix))
673790
else:
674791
return (1, "no mismatching diagnostics found")
675-

0 commit comments

Comments
 (0)