Skip to content

Commit bd5e3f8

Browse files
committed
Merge pull request #72 from briancroom/highlight-test-failures
Allow Xcode to highlight failing functional test expectations
2 parents 8fa8823 + 4c01ccf commit bd5e3f8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Tests/Functional/xctest_checker/tests/test_compare.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ def test_match_does_not_raise(self):
4646
expected = _tmpfile('c: foo\nc: bar\nc: baz\n')
4747
compare.compare(actual, expected, check_prefix='c: ')
4848

49+
def test_includes_file_name_and_line_of_expected_in_error(self):
50+
actual = _tmpfile('foo\nbar\nbaz\n')
51+
expected = _tmpfile('c: foo\nc: baz\nc: bar\n')
52+
with self.assertRaises(AssertionError) as cm:
53+
compare.compare(actual, expected, check_prefix='c: ')
54+
55+
self.assertIn("{}:{}:".format(expected, 2), cm.exception.message)
4956

5057
if __name__ == "__main__":
5158
unittest.main()

Tests/Functional/xctest_checker/xctest_checker/compare.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def _actual_lines(path):
2020
yield line
2121

2222

23-
def _expected_lines(path, check_prefix):
23+
def _expected_lines_and_line_numbers(path, check_prefix):
2424
"""
2525
Returns a generator that yields each line in the file at the given path
2626
that begins with the given prefix.
2727
"""
2828
with open(path) as f:
29-
for line in f:
29+
for line_number, line in enumerate(f):
3030
if line.startswith(check_prefix):
31-
yield line[len(check_prefix):]
31+
yield line[len(check_prefix):], line_number+1
3232

3333

3434
def compare(actual, expected, check_prefix):
@@ -38,19 +38,23 @@ def compare(actual, expected, check_prefix):
3838
file, raises an AssertionError. Also raises an AssertionError if the number
3939
of lines in the two files differ.
4040
"""
41-
for actual_line, expected_line in map(
41+
for actual_line, expected_line_and_line_number in map(
4242
None,
4343
_actual_lines(actual),
44-
_expected_lines(expected, check_prefix)):
44+
_expected_lines_and_line_numbers(expected, check_prefix)):
45+
4546
if actual_line is None:
4647
raise AssertionError('There were more lines expected to appear '
4748
'than there were lines in the actual input.')
48-
if expected_line is None:
49+
if expected_line_and_line_number is None:
4950
raise AssertionError('There were more lines than expected to '
5051
'appear.')
52+
53+
(expected_line, expectation_source_line_number) = expected_line_and_line_number
54+
5155
if not re.match(expected_line, actual_line):
5256
raise AssertionError('Actual line did not match the expected '
5357
'regular expression.\n'
54-
'Actual: {}\n'
58+
'{}:{}: Actual: {}\n'
5559
'Expected: {}\n'.format(
56-
repr(actual_line), repr(expected_line)))
60+
expected, expectation_source_line_number, repr(actual_line), repr(expected_line)))

0 commit comments

Comments
 (0)