[PATCH] D27746: [lit] Fix TestRunner unit test on Windows
Brian Gesiak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 20:50:14 PST 2016
modocache created this revision.
modocache added reviewers: ddunbar, echristo, beanz, delcypher.
modocache added a subscriber: llvm-commits.
Herald added a subscriber: mehdi_amini.
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.
https://reviews.llvm.org/D27746
Files:
utils/lit/lit/TestRunner.py
Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py
+++ utils/lit/lit/TestRunner.py
@@ -656,9 +656,13 @@
# 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()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27746.81343.patch
Type: text/x-patch
Size: 865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161214/cf9eb6b9/attachment.bin>
More information about the llvm-commits
mailing list