diff options
| author | Brian Gesiak <modocache@gmail.com> | 2017-07-27 19:27:10 +0000 |
|---|---|---|
| committer | Brian Gesiak <modocache@gmail.com> | 2017-07-27 19:27:10 +0000 |
| commit | 8c44b033c195d1c059bb73ef317335451b523995 (patch) | |
| tree | af91be7101eae635c86f050b2854c7176a1034e0 /llvm/utils | |
| parent | 8c022ca783ea3eff96fd11993664198c35cd7fc1 (diff) | |
| download | bcm5719-llvm-8c44b033c195d1c059bb73ef317335451b523995.tar.gz bcm5719-llvm-8c44b033c195d1c059bb73ef317335451b523995.zip | |
[lit] Fix TestRunner unit test on Windows
Summary:
Normally Python converts all newline characters, Windows or Unix,
to Unix newlines when opening a file. However, lit opens files in
binary mode, which does not perform this conversion. As a result,
trailing Windows newlines are not stripped from test input, which
caused a failure in the TestRunner unit test:
```
FAIL: test_custom (__main__.TestIntegratedTestKeywordParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\bgesiak\src\llvm\llvm\utils\lit\tests\unit\TestRunner.py", line 109, in test_custom
self.assertItemsEqual(value, ['a', 'b', 'c'])
AssertionError: Element counts were not equal:
First has 1, Second has 0: 'c\r'
First has 0, Second has 1: 'c'
```
Fix the discrepancy in behavior across the two platforms by
manually stripping Windows newlines before yielding each line in
the test file.
Reviewers: echristo, beanz, ddunbar, delcypher, rnk
Reviewed By: rnk
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D27746
llvm-svn: 309312
Diffstat (limited to 'llvm/utils')
| -rw-r--r-- | llvm/utils/lit/lit/TestRunner.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index a60a0f85487..404b8f6581b 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -787,9 +787,13 @@ def parseIntegratedTestScriptCommands(source_path, keywords): # command. Note that we take care to return regular strings in # Python 2, to avoid other code having to differentiate between the # str and unicode types. + # + # Opening the file in binary mode prevented Windows \r newline + # characters from being converted to Unix \n newlines, so manually + # strip those from the yielded lines. keyword,ln = match.groups() yield (line_number, to_string(keyword.decode('utf-8')), - to_string(ln.decode('utf-8'))) + to_string(ln.decode('utf-8').rstrip('\r'))) finally: f.close() |

