Commit a0f03f74 authored by Jose Lopes's avatar Jose Lopes Committed by Commit Bot

Fix garbled diff output in clang test tool.

The function splitlines consumes the trailing newlines so the resulting
diff lines are printed in a single line and the diff is not readable.
This CL implements the recommendation from the difflib library, which
is to use readlines and writelines for a correct diff output:
* https://docs.python.org/3/library/difflib.html#difflib.unified_diff

Change-Id: I88b9bf1a1ff8f4c1f75c9cb1aca82e209f72abdf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2139699
Commit-Queue: Jose Lopes <jabolopes@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757801}
parent 4abe3886
......@@ -203,15 +203,15 @@ def main(argv):
print('[ RUN ] %s' % os.path.relpath(actual))
expected_output = actual_output = None
with open(expected, 'r') as f:
expected_output = f.read().splitlines()
expected_output = f.readlines()
with open(actual, 'r') as f:
actual_output = f.read().splitlines()
actual_output = f.readlines()
if actual_output != expected_output:
failed += 1
for line in difflib.unified_diff(expected_output, actual_output,
fromfile=os.path.relpath(expected),
tofile=os.path.relpath(actual)):
sys.stdout.write(line)
lines = difflib.unified_diff(expected_output, actual_output,
fromfile=os.path.relpath(expected),
tofile=os.path.relpath(actual))
sys.stdout.writelines(lines)
print('[ FAILED ] %s' % os.path.relpath(actual))
# Don't clean up the file on failure, so the results can be referenced
# more easily.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment