This is an archive of the discontinued LLVM Phabricator instance.

[lit] Fix TestRunner unit test on Windows
ClosedPublic

Authored by modocache on Dec 13 2016, 8:50 PM.

Details

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.

Event Timeline

modocache updated this revision to Diff 81343.Dec 13 2016, 8:50 PM
modocache retitled this revision from to [lit] Fix TestRunner unit test on Windows.
modocache updated this object.
modocache added a subscriber: llvm-commits.

Friendly ping! Just re-tested this: utils/lit/tests/unit/TestRunner.py still fails on Windows, and this diff fixes it. Is anything in particular holding this back?

rnk accepted this revision.Jul 27 2017, 10:11 AM

lgtm

I think I don't observe this failure because the git repos don't auto-convert LF to CRLF on Windows, but SVN does.

This revision is now accepted and ready to land.Jul 27 2017, 10:11 AM
modocache closed this revision.Jul 27 2017, 12:27 PM