[PATCH] D107041: [Flang] Ported test_symbols to Python

Ivan Zhechev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 19 02:11:35 PDT 2021


ijan1 added a comment.

In D107041#2953476 <https://reviews.llvm.org/D107041#2953476>, @ashe wrote:

> Thanks, that fixes the weird diff formatting. But why are all of the spaces removed?

A file might have a line with whitespace, such as `real x(100, 100)`, whereas the output would have stripped some of the whitespace and have it as `real x(100,100)`. However, Python's `difflib` library[1] unfortunately doesn't have support for ignoring whitespace, unlike `diff` which was used in the shell scripts. There are some threads[2][3] asking about `charjunk` mentioned in the Python docs but it's poorly documented and it doesn't actually ignore characters.

[1] https://docs.python.org/3/library/difflib.html
[2] https://stackoverflow.com/questions/63893283/difflib-ignore-whitespace-diffs-w-ndiff
[3] https://stackoverflow.com/questions/65780782/how-to-do-a-diff-in-python-of-two-text-files-and-ignore-white-space-and-blank-li



================
Comment at: flang/test/Semantics/test_symbols.py:46-50
+diff_check = ""
+
+# Compares the input with the output
+for line in unified_diff(diff1, diff3, n=999999, fromfile="1.90", tofile="3.f90"):
+    diff_check += line
----------------
Meinersbur wrote:
> Isn't this identical to:
> ```
> diff_check = unified_diff(diff1, diff3, n=999999, fromfile="1.90", tofile="3.f90")
> ```
> ?
"unified_diff" returns a generator.
An alternative would be

```
diff_check = "".join(list(unified_diff(diff1, diff3, n=999999, fromfile="1.90", tofile="3.f90")))
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107041/new/

https://reviews.llvm.org/D107041



More information about the llvm-commits mailing list