Skip to content

Commit 7663e48

Browse files
authored
Add _:file:line: arguments to assert functions (#80)
This improves line reporting, by pointing Xcode (or your IDE of choice) at the assert's use place, rather than definition place
1 parent 34c2f07 commit 7663e48

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

Tests/BenchmarkTests/BenchmarkReporterTests.swift

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,59 @@ import XCTest
1717
@testable import Benchmark
1818

1919
final class BenchmarkReporterTests: XCTestCase {
20-
func assertConsoleReported(_ results: [BenchmarkResult], _ expected: String) {
20+
func assertConsoleReported(
21+
_ results: [BenchmarkResult],
22+
_ expected: String,
23+
_ message: @autoclosure () -> String = "",
24+
file: StaticString = #filePath,
25+
line: UInt = #line
26+
) {
2127
let output = MockTextOutputStream()
2228
var reporter = ConsoleReporter(output: output)
2329
reporter.report(results: results)
24-
assertReported(output.result(), expected)
30+
assertReported(output.result(), expected, message(), file: file, line: line)
2531
}
2632

27-
func assertJSONReported(_ results: [BenchmarkResult], _ expected: String) {
33+
func assertJSONReported(
34+
_ results: [BenchmarkResult],
35+
_ expected: String,
36+
_ message: @autoclosure () -> String = "",
37+
file: StaticString = #filePath,
38+
line: UInt = #line
39+
) {
2840
let output = MockTextOutputStream()
2941
var reporter = JSONReporter(output: output)
3042
reporter.report(results: results)
31-
assertReported(output.result(), expected)
43+
assertReported(output.result(), expected, message(), file: file, line: line)
3244
}
3345

3446
func assertCSVReported(
35-
_ results: [BenchmarkResult], _ expected: String
47+
_ results: [BenchmarkResult],
48+
_ expected: String,
49+
_ message: @autoclosure () -> String = "",
50+
file: StaticString = #filePath,
51+
line: UInt = #line
3652
) {
3753
let output = MockTextOutputStream()
3854
var reporter = CSVReporter(output: output)
3955
reporter.report(results: results)
40-
assertReported(output.result(), expected)
56+
assertReported(output.result(), expected, message(), file: file, line: line)
4157
}
4258

43-
func assertReported(_ got: String, _ expected: String) {
59+
func assertReported(
60+
_ got: String,
61+
_ expected: String,
62+
_ message: @autoclosure () -> String = "",
63+
file: StaticString = #filePath,
64+
line: UInt = #line
65+
) {
4466
let lines = Array(got.split(separator: "\n").map { String($0) })
4567
let expectedLines = expected.split(separator: "\n").map { String($0) }
4668
let actual = lines.map { $0.trimmingCharacters(in: .newlines) }
4769
.filter { !$0.isEmpty }
48-
XCTAssertEqual(expectedLines.count, actual.count)
70+
XCTAssertEqual(expectedLines.count, actual.count, message(), file: file, line: line)
4971
for (expectedLine, actualLine) in zip(expectedLines, actual) {
50-
XCTAssertEqual(expectedLine, actualLine)
72+
XCTAssertEqual(expectedLine, actualLine, message(), file: file, line: line)
5173
}
5274
}
5375

0 commit comments

Comments
 (0)