[Android] Ignore trailing whitespace in expectation diff-patch lines
We should not care about trailing whitespace in expectation files, since R8 doesn't either. Change-Id: Ief57c4c260083f662ca5b791edf7504de2e40428 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363259 Commit-Queue: Mohamed Heikal <mheikal@chromium.org> Reviewed-by: Andrew Grieve <agrieve@chromium.org> Cr-Commit-Position: refs/heads/master@{#799804} GitOrigin-RevId: 099807e92294b0d2aafc478319e83b0e666d5056
This commit is contained in:
Родитель
79d8cef662
Коммит
c8df6fe574
|
@ -19,7 +19,7 @@ def _SkipOmitted(line):
|
|||
a line that changes from build to build because - for instance - it contains
|
||||
version information.
|
||||
"""
|
||||
if line.endswith('# OMIT FROM EXPECTATIONS\n'):
|
||||
if line.rstrip().endswith('# OMIT FROM EXPECTATIONS'):
|
||||
return '# THIS LINE WAS OMITTED\n'
|
||||
return line
|
||||
|
||||
|
@ -27,10 +27,14 @@ def _SkipOmitted(line):
|
|||
def _GenerateDiffWithOnlyAdditons(expected_path, actual_data):
|
||||
"""Generate a diff that only contains additions"""
|
||||
# Ignore blank lines when creating the diff to cut down on whitespace-only
|
||||
# lines in the diff.
|
||||
# lines in the diff. Also remove trailing whitespaces and add the new lines
|
||||
# manually (ndiff expects new lines but we don't care about trailing
|
||||
# whitespace).
|
||||
with open(expected_path) as expected:
|
||||
expected_lines = [l for l in expected.readlines() if l.strip()]
|
||||
actual_lines = [l for l in actual_data.splitlines(True) if l.strip()]
|
||||
actual_lines = [
|
||||
'{}\n'.format(l.rstrip()) for l in actual_data.splitlines() if l.strip()
|
||||
]
|
||||
|
||||
diff = difflib.ndiff(expected_lines, actual_lines)
|
||||
filtered_diff = (l for l in diff if l.startswith('+'))
|
||||
|
@ -39,9 +43,12 @@ def _GenerateDiffWithOnlyAdditons(expected_path, actual_data):
|
|||
|
||||
def _DiffFileContents(expected_path, actual_data):
|
||||
"""Check file contents for equality and return the diff or None."""
|
||||
# Remove all trailing whitespace and add it explicitly in the end.
|
||||
with open(expected_path) as f_expected:
|
||||
expected_lines = f_expected.readlines()
|
||||
actual_lines = [_SkipOmitted(line) for line in actual_data.splitlines(True)]
|
||||
expected_lines = [l.rstrip() for l in f_expected.readlines()]
|
||||
actual_lines = [
|
||||
_SkipOmitted(line).rstrip() for line in actual_data.splitlines()
|
||||
]
|
||||
|
||||
if expected_lines == actual_lines:
|
||||
return None
|
||||
|
@ -53,9 +60,11 @@ def _DiffFileContents(expected_path, actual_data):
|
|||
actual_lines,
|
||||
fromfile=os.path.join('before', expected_path),
|
||||
tofile=os.path.join('after', expected_path),
|
||||
n=0)
|
||||
n=0,
|
||||
lineterm='',
|
||||
)
|
||||
|
||||
return ''.join(diff).rstrip()
|
||||
return '\n'.join(diff)
|
||||
|
||||
|
||||
def AddCommandLineFlags(parser):
|
||||
|
|
Загрузка…
Ссылка в новой задаче