Skip to content

Commit eea1eb0

Browse files
authored
Replace usage of all the FileID/FilePath/line/column macros with SourceLocation (#1185)
1 parent def883e commit eea1eb0

15 files changed

+213
-270
lines changed

Sources/Nimble/Adapters/AssertionRecorder+Async.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
///
99
/// @see AssertionHandler
1010
public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
11-
fileID: String = #fileID,
12-
file: FileString = #filePath,
13-
line: UInt = #line,
14-
column: UInt = #column,
11+
location: SourceLocation = SourceLocation(),
1512
closure: () async throws -> Void) async {
1613
let environment = NimbleEnvironment.activeInstance
1714
let oldRecorder = environment.assertionHandler
@@ -27,7 +24,6 @@ public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
2724
} catch {
2825
let failureMessage = FailureMessage()
2926
failureMessage.stringValue = "unexpected error thrown: <\(error)>"
30-
let location = SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
3127
tempAssertionHandler.assert(false, message: failureMessage, location: location)
3228
}
3329
}

Sources/Nimble/Adapters/AssertionRecorder.swift

+1-9
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ extension NMBExceptionCapture {
7171
///
7272
/// @see AssertionHandler
7373
public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
74-
fileID: String = #fileID,
75-
file: FileString = #filePath,
76-
line: UInt = #line,
77-
column: UInt = #column,
74+
location: SourceLocation = SourceLocation(),
7875
closure: () throws -> Void) {
7976
let environment = NimbleEnvironment.activeInstance
8077
let oldRecorder = environment.assertionHandler
@@ -92,11 +89,6 @@ public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
9289
} catch {
9390
let failureMessage = FailureMessage()
9491
failureMessage.stringValue = "unexpected error thrown: <\(error)>"
95-
let location = SourceLocation(
96-
fileID: fileID,
97-
filePath: file,
98-
line: line, column: column
99-
)
10092
tempAssertionHandler.assert(false, message: failureMessage, location: location)
10193
}
10294
}

Sources/Nimble/Adapters/NMBExpectation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final class NMBExpectation: NSObject, Sendable {
3737
}
3838

3939
private var expectValue: SyncExpectation<NSObject> {
40-
return expect(file: _file, line: _line, self._actualBlock() as NSObject?)
40+
return expect(location: SourceLocation(fileID: "unknown/\(_file)", filePath: _file, line: _line, column: 0), self._actualBlock() as NSObject?)
4141
}
4242

4343
@objc public var withTimeout: (TimeInterval) -> NMBExpectation {

Sources/Nimble/DSL+AsyncAwait.swift

+24-42
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,78 @@ import Dispatch
33
#endif
44

55
/// Make an ``AsyncExpectation`` on a given actual value. The value given is lazily evaluated.
6-
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @escaping @Sendable () async throws -> T?) -> AsyncExpectation<T> {
6+
public func expect<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @escaping @Sendable () async throws -> T?) -> AsyncExpectation<T> {
77
return AsyncExpectation(
88
expression: AsyncExpression(
99
expression: expression,
10-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
10+
location: location,
1111
isClosure: true))
1212
}
1313

1414
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
15-
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> T)) -> AsyncExpectation<T> {
15+
public func expect<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @Sendable () -> (@Sendable () async throws -> T)) -> AsyncExpectation<T> {
1616
return AsyncExpectation(
1717
expression: AsyncExpression(
1818
expression: expression(),
19-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
19+
location: location,
2020
isClosure: true))
2121
}
2222

2323
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
24-
public func expect<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> T?)) -> AsyncExpectation<T> {
24+
public func expect<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @Sendable () -> (@Sendable () async throws -> T?)) -> AsyncExpectation<T> {
2525
return AsyncExpectation(
2626
expression: AsyncExpression(
2727
expression: expression(),
28-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
28+
location: location,
2929
isClosure: true))
3030
}
3131

3232
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
33-
public func expect(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @Sendable () -> (@Sendable () async throws -> Void)) -> AsyncExpectation<Void> {
33+
public func expect(location: SourceLocation = SourceLocation(), _ expression: @Sendable () -> (@Sendable () async throws -> Void)) -> AsyncExpectation<Void> {
3434
return AsyncExpectation(
3535
expression: AsyncExpression(
3636
expression: expression(),
37-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
37+
location: location,
3838
isClosure: true))
3939
}
4040

4141
/// Make an ``AsyncExpectation`` on a given actual value. The value given is lazily evaluated.
4242
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`.
43-
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @escaping @Sendable () async throws -> T?) async -> AsyncExpectation<T> {
43+
public func expecta<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @escaping @Sendable () async throws -> T?) async -> AsyncExpectation<T> {
4444
return AsyncExpectation(
4545
expression: AsyncExpression(
4646
expression: expression,
47-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
47+
location: location,
4848
isClosure: true))
4949
}
5050

5151
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
5252
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
53-
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T)) async -> AsyncExpectation<T> {
53+
public func expecta<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T)) async -> AsyncExpectation<T> {
5454
return AsyncExpectation(
5555
expression: AsyncExpression(
5656
expression: expression(),
57-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
57+
location: location,
5858
isClosure: true))
5959
}
6060

6161
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
6262
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
63-
public func expecta<T: Sendable>(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T?)) async -> AsyncExpectation<T> {
63+
public func expecta<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T?)) async -> AsyncExpectation<T> {
6464
return AsyncExpectation(
6565
expression: AsyncExpression(
6666
expression: expression(),
67-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
67+
location: location,
6868
isClosure: true))
6969
}
7070

7171
/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
7272
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
73-
public func expecta(fileID: String = #fileID, file: FileString = #filePath, line: UInt = #line, column: UInt = #column, _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> Void)) async -> AsyncExpectation<Void> {
73+
public func expecta(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> Void)) async -> AsyncExpectation<Void> {
7474
return AsyncExpectation(
7575
expression: AsyncExpression(
7676
expression: expression(),
77-
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
77+
location: location,
7878
isClosure: true))
7979
}
8080

@@ -89,15 +89,12 @@ public func expecta(fileID: String = #fileID, file: FileString = #filePath, line
8989
/// Unlike the synchronous version of this call, this does not support catching Objective-C exceptions.
9090
public func waitUntil(
9191
timeout: NimbleTimeInterval = PollingDefaults.timeout,
92-
fileID: String = #fileID,
93-
file: FileString = #filePath,
94-
line: UInt = #line,
95-
column: UInt = #column,
92+
location: SourceLocation = SourceLocation(),
9693
action: @escaping @Sendable (@escaping @Sendable () -> Void) async -> Void
9794
) async {
9895
await throwableUntil(
9996
timeout: timeout,
100-
sourceLocation: SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
97+
sourceLocation: location
10198
) { done in
10299
await action(done)
103100
}
@@ -112,15 +109,12 @@ public func waitUntil(
112109
/// Unlike the synchronous version of this call, this does not support catching Objective-C exceptions.
113110
public func waitUntil(
114111
timeout: NimbleTimeInterval = PollingDefaults.timeout,
115-
fileID: String = #fileID,
116-
file: FileString = #filePath,
117-
line: UInt = #line,
118-
column: UInt = #column,
112+
location: SourceLocation = SourceLocation(),
119113
action: @escaping @Sendable (@escaping @Sendable () -> Void) -> Void
120114
) async {
121115
await throwableUntil(
122116
timeout: timeout,
123-
sourceLocation: SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
117+
sourceLocation: location
124118
) { done in
125119
action(done)
126120
}
@@ -154,34 +148,22 @@ private func throwableUntil(
154148
case .blockedRunLoop:
155149
fail(
156150
blockedRunLoopErrorMessageFor("-waitUntil()", leeway: leeway),
157-
fileID: sourceLocation.fileID,
158-
file: sourceLocation.filePath,
159-
line: sourceLocation.line,
160-
column: sourceLocation.column
151+
location: sourceLocation
161152
)
162153
case .timedOut:
163154
fail(
164155
"Waited more than \(timeout.description)",
165-
fileID: sourceLocation.fileID,
166-
file: sourceLocation.filePath,
167-
line: sourceLocation.line,
168-
column: sourceLocation.column
156+
location: sourceLocation
169157
)
170158
case let .errorThrown(error):
171159
fail(
172160
"Unexpected error thrown: \(error)",
173-
fileID: sourceLocation.fileID,
174-
file: sourceLocation.filePath,
175-
line: sourceLocation.line,
176-
column: sourceLocation.column
161+
location: sourceLocation
177162
)
178163
case .completed(.error(let error)):
179164
fail(
180165
"Unexpected error thrown: \(error)",
181-
fileID: sourceLocation.fileID,
182-
file: sourceLocation.filePath,
183-
line: sourceLocation.line,
184-
column: sourceLocation.column
166+
location: sourceLocation
185167
)
186168
case .completed(.none): // success
187169
break

0 commit comments

Comments
 (0)