Make test_symbols.py compare files line-by-line

We currently feed full files to Python's unified_diff.
It's not quite what we want though -
line-by-line comparison makes more sense
(we want to be able to identify missing/unnecessary lines)
and is also easier to parse for humans.
This patch makes sure that we compare one line at a time.

This change pretties up the output formatting in the script.
Output before:

```
!DEF:/m/s/xINTENT(IN)(Implicit)ObjectEntityREAL(4)
!DEF:/m/s/yINTENT(INOUT)(Implicit)ObjectEntityREAL(4)
-!-D-E-F-:-f-o-o-b-a-r-
puresubroutines(x,y)bind(c)
!REF:/m/s/x
intent(in)::x
```
Proposed output after:

```
!DEF:/m/s/xINTENT(IN)(Implicit)ObjectEntityREAL(4)
!DEF:/m/s/yINTENT(INOUT)(Implicit)ObjectEntityREAL(4)
-!DEF:foobar
puresubroutines(x,y)bind(c)
!REF:/m/s/x
intent(in)::x
```

Reviewed By: Meinersbur, awarzynski

Differential Revision: https://reviews.llvm.org/D107954
This commit is contained in:
Ivan Zhechev 2021-08-20 18:14:59 +01:00 committed by Kiran Chandramohan
parent 3a244fcf29
commit 0d1a0f7e8d
1 changed files with 3 additions and 4 deletions

View File

@ -4,7 +4,7 @@
we get the right symbols in the output, i.e. the output should be
the same as the input, except for the copyright comment.
Expects a source file passed as the first argument;
Expects the Flang frontdriver with options as second argument."""
Expects the Flang frontend driver with options as second argument."""
import sys
import re
@ -44,9 +44,8 @@ diff3 = diff3.replace(" ", "")
diff_check = ""
# Compares the input with the output
for line in unified_diff(diff1, diff3, n=999999,
fromfile="Expected output", tofile="Actual output"):
diff_check += line
diff_check = "\n".join(unified_diff(diff1.split("\n"), diff3.split("\n"), n=999999,
fromfile="Expected_output", tofile="Actual_output"))
if diff_check != "":
print(diff_check.replace(" ", ""))