Skip to content

Commit 2e5fbd7

Browse files
authored
Merge pull request #131 from modocache/xctest-checker-input-streams
[Tests] Allow xctest_checker to read from stdin
2 parents 759cb71 + 6ae5c1b commit 2e5fbd7

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

Tests/Functional/xctest_checker/tests/test_compare.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,69 +28,69 @@ def test_no_match_raises(self):
2828
actual = _tmpfile('foo\nbar\nbaz\n')
2929
expected = _tmpfile('c: foo\nc: baz\nc: bar\n')
3030
with self.assertRaises(XCTestCheckerError):
31-
compare.compare(actual, expected, check_prefix='c: ')
31+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
3232

3333
def test_too_few_expected_raises_and_first_line_in_error(self):
3434
actual = _tmpfile('foo\nbar\nbaz\n')
3535
expected = _tmpfile('c: foo\nc: bar\n')
3636
with self.assertRaises(XCTestCheckerError) as cm:
37-
compare.compare(actual, expected, check_prefix='c: ')
37+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
3838

3939
self.assertIn('{}:{}'.format(expected, 1), cm.exception.message)
4040

4141
def test_too_many_expected_raises_and_excess_check_line_in_error(self):
4242
actual = _tmpfile('foo\nbar\n')
4343
expected = _tmpfile('c: foo\nc: bar\nc: baz\n')
4444
with self.assertRaises(XCTestCheckerError) as cm:
45-
compare.compare(actual, expected, check_prefix='c: ')
45+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
4646

4747
self.assertIn('{}:{}'.format(expected, 3), cm.exception.message)
4848

4949
def test_match_does_not_raise(self):
5050
actual = _tmpfile('foo\nbar\nbaz\n')
5151
expected = _tmpfile('c: foo\nc: bar\nc: baz\n')
52-
compare.compare(actual, expected, check_prefix='c: ')
52+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
5353

5454
def test_match_with_inline_check_does_not_raise(self):
5555
actual = _tmpfile('bling\nblong\n')
5656
expected = _tmpfile('meep meep // c: bling\nmeep\n// c: blong\n')
57-
compare.compare(actual, expected, check_prefix='// c: ')
57+
compare.compare(open(actual, 'r'), expected, check_prefix='// c: ')
5858

5959
def test_check_prefix_twice_in_the_same_line_raises_with_line(self):
6060
actual = _tmpfile('blorp\nbleep\n')
6161
expected = _tmpfile('c: blorp\nc: bleep c: blammo\n')
6262
with self.assertRaises(XCTestCheckerError) as cm:
63-
compare.compare(actual, expected, check_prefix='c: ')
63+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
6464

6565
self.assertIn('{}:{}'.format(expected, 2), cm.exception.message)
6666

6767
def test_check_prefix_in_run_line_ignored(self):
6868
actual = _tmpfile('flim\n')
6969
expected = _tmpfile('// RUN: xctest_checker --prefix "c: "\nc: flim\n')
70-
compare.compare(actual, expected, check_prefix='c: ')
70+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
7171

7272
def test_includes_file_name_and_line_of_expected_in_error(self):
7373
actual = _tmpfile('foo\nbar\nbaz\n')
7474
expected = _tmpfile('c: foo\nc: baz\nc: bar\n')
7575
with self.assertRaises(XCTestCheckerError) as cm:
76-
compare.compare(actual, expected, check_prefix='c: ')
76+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
7777

7878
self.assertIn("{}:{}:".format(expected, 2), cm.exception.message)
7979

8080
def test_matching_ignores_leading_and_trailing_whitespace(self):
8181
actual = _tmpfile('foo\nbar\nbaz\n')
8282
expected = _tmpfile('c: foo\nc: bar \nc: baz\n')
83-
compare.compare(actual, expected, check_prefix='c:')
83+
compare.compare(open(actual, 'r'), expected, check_prefix='c:')
8484

8585
def test_can_explicitly_match_leading_and_trailing_whitespace(self):
8686
actual = _tmpfile('foo\n bar\nbaz \n')
8787
expected = _tmpfile('c: foo\nc: ^ bar \nc: baz $\n')
88-
compare.compare(actual, expected, check_prefix='c:')
88+
compare.compare(open(actual, 'r'), expected, check_prefix='c:')
8989

9090
def test_line_number_substitution(self):
9191
actual = _tmpfile('beep 1\nboop 5\n')
9292
expected = _tmpfile('c: beep [[@LINE]]\nc: boop [[@LINE+3]]')
93-
compare.compare(actual, expected, check_prefix='c: ')
93+
compare.compare(open(actual, 'r'), expected, check_prefix='c: ')
9494

9595
if __name__ == "__main__":
9696
unittest.main()

Tests/Functional/xctest_checker/xctest_checker/compare.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
from .line import replace_offsets
1515

1616

17-
def _actual_lines(path):
17+
def _actual_lines(file_handle):
1818
"""
19-
Returns a generator that yields each line in the file at the given path.
19+
Returns a generator that yields each line in the file.
2020
"""
21-
with open(path) as f:
22-
for line in f:
23-
yield line
21+
for line in file_handle:
22+
yield line
2423

2524

2625
def _expected_lines_and_line_numbers(path, check_prefix):

Tests/Functional/xctest_checker/xctest_checker/main.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,40 @@
1212
from __future__ import absolute_import
1313

1414
import argparse
15+
import textwrap
1516

1617
from . import compare
1718

1819

1920
def main():
20-
parser = argparse.ArgumentParser()
21-
parser.add_argument('actual', help='A path to a file containing the '
22-
'actual output of an XCTest run.')
21+
parser = argparse.ArgumentParser(
22+
formatter_class=argparse.RawDescriptionHelpFormatter,
23+
description=textwrap.dedent("""
24+
Compare the text output of an XCTest executable with the text
25+
that's expected."""),
26+
epilog=textwrap.dedent("""
27+
In general, %(prog)s should not be invoked directly. Instead,
28+
use the Swift built script to build swift-corelibs-xctest and run
29+
its tests, which in turn use %(prog)s.
30+
31+
However, you may find it useful to run %(prog)s directly when
32+
debugging the test suite. To compare the actual output of an
33+
executable against the expected output, you may run the following:
34+
35+
Tests/Functional/MyTestCase/Output/MyTestCase | \\
36+
%(prog)s - Tests/Functional/MyTestCase/main.swift
37+
38+
This pipes the output from the "MyTestCase" executable into
39+
%(prog)s, which compares that output to the expected output from
40+
"MyTestCase/main.swift".
41+
"""))
42+
parser.add_argument(
43+
'actual',
44+
type=argparse.FileType('r'),
45+
default='-',
46+
help='A path to a file containing the actual output of an XCTest '
47+
'run, or an input stream of the output. If no argument is '
48+
'specified, reads from stdin by default.')
2349
parser.add_argument('expected', help='A path to a file containing the '
2450
'expected output of an XCTest run.')
2551
parser.add_argument('-p', '--check-prefix',

0 commit comments

Comments
 (0)