mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[libSyntax] Enhance incremental re-parsing testing to also check whether unexpected diagnostics were emitted
Enhances `swift-syntax-test` to output the parser diagnostics so we can verify that if the incremental parse resulted in parser diagnostics, those diagnostics were also emitted during the full parse.
This commit is contained in:
@@ -67,6 +67,11 @@ def main():
|
||||
post_edit_serialized_file = temp_dir + '/' + test_file_name + '.' \
|
||||
+ test_case + '.post.json'
|
||||
|
||||
incremental_diags_file = temp_dir + '/' + test_file_name + '.' \
|
||||
+ test_case + '.diagsViaIncr.txt'
|
||||
post_edit_diags_file = temp_dir + '/' + test_file_name + '.' \
|
||||
+ test_case + '.post.diags.txt'
|
||||
|
||||
# Generate the syntax tree once incrementally and once from scratch
|
||||
try:
|
||||
serializeIncrParseMarkupFile(test_file=test_file,
|
||||
@@ -76,6 +81,7 @@ def main():
|
||||
serialization_format='json',
|
||||
omit_node_ids=True,
|
||||
output_file=incremental_serialized_file,
|
||||
diags_output_file=incremental_diags_file,
|
||||
temp_dir=temp_dir + '/temp',
|
||||
swift_syntax_test=swift_syntax_test,
|
||||
print_visual_reuse_info=visual_reuse_info)
|
||||
@@ -91,6 +97,7 @@ def main():
|
||||
serialization_format='json',
|
||||
omit_node_ids=True,
|
||||
output_file=post_edit_serialized_file,
|
||||
diags_output_file=post_edit_diags_file,
|
||||
temp_dir=temp_dir + '/temp',
|
||||
swift_syntax_test=swift_syntax_test,
|
||||
print_visual_reuse_info=visual_reuse_info)
|
||||
@@ -104,7 +111,7 @@ def main():
|
||||
lines = difflib.unified_diff(open(incremental_serialized_file).readlines(),
|
||||
open(post_edit_serialized_file).readlines(),
|
||||
fromfile=incremental_serialized_file,
|
||||
tofile=incremental_serialized_file)
|
||||
tofile=post_edit_serialized_file)
|
||||
diff = '\n'.join(line for line in lines)
|
||||
if diff:
|
||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||
@@ -114,6 +121,31 @@ def main():
|
||||
print(diff, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Verify that if the incremental parse resulted in parser diagnostics, those
|
||||
# diagnostics were also emitted during the full parse.
|
||||
# We can't just diff the outputs because the full parse includes diagnostics
|
||||
# from the whole file, while the incremental parse includes only a subset.
|
||||
# Each diagnostic is searched in the full parse diagnostics array but the
|
||||
# search for each diagnostic continues from where the previous search
|
||||
# stopped.
|
||||
incremental_diags = open(incremental_diags_file).readlines()
|
||||
post_edit_diags = open(post_edit_diags_file).readlines()
|
||||
full_idx = 0
|
||||
for diag in incremental_diags:
|
||||
while full_idx < len(post_edit_diags):
|
||||
if post_edit_diags[full_idx] == diag:
|
||||
break
|
||||
full_idx += 1
|
||||
if full_idx == len(post_edit_diags):
|
||||
print('Test case "%s" of %s FAILed' % (test_case, test_file),
|
||||
file=sys.stderr)
|
||||
print('Parser diagnostic of incremental parsing was not emitted '
|
||||
'during from-scratch parsing of post-edit file:',
|
||||
file=sys.stderr)
|
||||
print(diag, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
full_idx += 1 # continue searching from the next diagnostic line.
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user