Skip to content

Commit

Permalink
Replace usage of all the FileID/FilePath/line/column macros with Sour…
Browse files Browse the repository at this point in the history
…ceLocation (#1185)
  • Loading branch information
younata authored Dec 20, 2024
1 parent def883e commit eea1eb0
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 270 deletions.
6 changes: 1 addition & 5 deletions Sources/Nimble/Adapters/AssertionRecorder+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
///
/// @see AssertionHandler
public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
fileID: String = #fileID,
file: FileString = #filePath,
line: UInt = #line,
column: UInt = #column,
location: SourceLocation = SourceLocation(),
closure: () async throws -> Void) async {
let environment = NimbleEnvironment.activeInstance
let oldRecorder = environment.assertionHandler
Expand All @@ -27,7 +24,6 @@ public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
} catch {
let failureMessage = FailureMessage()
failureMessage.stringValue = "unexpected error thrown: <\(error)>"
let location = SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
tempAssertionHandler.assert(false, message: failureMessage, location: location)
}
}
Expand Down
10 changes: 1 addition & 9 deletions Sources/Nimble/Adapters/AssertionRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ extension NMBExceptionCapture {
///
/// @see AssertionHandler
public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
fileID: String = #fileID,
file: FileString = #filePath,
line: UInt = #line,
column: UInt = #column,
location: SourceLocation = SourceLocation(),
closure: () throws -> Void) {
let environment = NimbleEnvironment.activeInstance
let oldRecorder = environment.assertionHandler
Expand All @@ -92,11 +89,6 @@ public func withAssertionHandler(_ tempAssertionHandler: AssertionHandler,
} catch {
let failureMessage = FailureMessage()
failureMessage.stringValue = "unexpected error thrown: <\(error)>"
let location = SourceLocation(
fileID: fileID,
filePath: file,
line: line, column: column
)
tempAssertionHandler.assert(false, message: failureMessage, location: location)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nimble/Adapters/NMBExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class NMBExpectation: NSObject, Sendable {
}

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

@objc public var withTimeout: (TimeInterval) -> NMBExpectation {
Expand Down
66 changes: 24 additions & 42 deletions Sources/Nimble/DSL+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,78 @@ import Dispatch
#endif

/// Make an ``AsyncExpectation`` on a given actual value. The value given is lazily evaluated.
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> {
public func expect<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @escaping @Sendable () async throws -> T?) -> AsyncExpectation<T> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression,
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
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> {
public func expect<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @Sendable () -> (@Sendable () async throws -> T)) -> AsyncExpectation<T> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression(),
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
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> {
public func expect<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @Sendable () -> (@Sendable () async throws -> T?)) -> AsyncExpectation<T> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression(),
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

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

/// Make an ``AsyncExpectation`` on a given actual value. The value given is lazily evaluated.
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`.
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> {
public func expecta<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @escaping @Sendable () async throws -> T?) async -> AsyncExpectation<T> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression,
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
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> {
public func expecta<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T)) async -> AsyncExpectation<T> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression(),
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
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> {
public func expecta<T: Sendable>(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> T?)) async -> AsyncExpectation<T> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression(),
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

/// Make an ``AsyncExpectation`` on a given actual value. The closure is lazily invoked.
/// This is provided to avoid confusion between `expect -> SyncExpectation` and `expect -> AsyncExpectation`
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> {
public func expecta(location: SourceLocation = SourceLocation(), _ expression: @autoclosure @Sendable () -> (@Sendable () async throws -> Void)) async -> AsyncExpectation<Void> {
return AsyncExpectation(
expression: AsyncExpression(
expression: expression(),
location: SourceLocation(fileID: fileID, filePath: file, line: line, column: column),
location: location,
isClosure: true))
}

Expand All @@ -89,15 +89,12 @@ public func expecta(fileID: String = #fileID, file: FileString = #filePath, line
/// Unlike the synchronous version of this call, this does not support catching Objective-C exceptions.
public func waitUntil(
timeout: NimbleTimeInterval = PollingDefaults.timeout,
fileID: String = #fileID,
file: FileString = #filePath,
line: UInt = #line,
column: UInt = #column,
location: SourceLocation = SourceLocation(),
action: @escaping @Sendable (@escaping @Sendable () -> Void) async -> Void
) async {
await throwableUntil(
timeout: timeout,
sourceLocation: SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
sourceLocation: location
) { done in
await action(done)
}
Expand All @@ -112,15 +109,12 @@ public func waitUntil(
/// Unlike the synchronous version of this call, this does not support catching Objective-C exceptions.
public func waitUntil(
timeout: NimbleTimeInterval = PollingDefaults.timeout,
fileID: String = #fileID,
file: FileString = #filePath,
line: UInt = #line,
column: UInt = #column,
location: SourceLocation = SourceLocation(),
action: @escaping @Sendable (@escaping @Sendable () -> Void) -> Void
) async {
await throwableUntil(
timeout: timeout,
sourceLocation: SourceLocation(fileID: fileID, filePath: file, line: line, column: column)
sourceLocation: location
) { done in
action(done)
}
Expand Down Expand Up @@ -154,34 +148,22 @@ private func throwableUntil(
case .blockedRunLoop:
fail(
blockedRunLoopErrorMessageFor("-waitUntil()", leeway: leeway),
fileID: sourceLocation.fileID,
file: sourceLocation.filePath,
line: sourceLocation.line,
column: sourceLocation.column
location: sourceLocation
)
case .timedOut:
fail(
"Waited more than \(timeout.description)",
fileID: sourceLocation.fileID,
file: sourceLocation.filePath,
line: sourceLocation.line,
column: sourceLocation.column
location: sourceLocation
)
case let .errorThrown(error):
fail(
"Unexpected error thrown: \(error)",
fileID: sourceLocation.fileID,
file: sourceLocation.filePath,
line: sourceLocation.line,
column: sourceLocation.column
location: sourceLocation
)
case .completed(.error(let error)):
fail(
"Unexpected error thrown: \(error)",
fileID: sourceLocation.fileID,
file: sourceLocation.filePath,
line: sourceLocation.line,
column: sourceLocation.column
location: sourceLocation
)
case .completed(.none): // success
break
Expand Down
Loading

0 comments on commit eea1eb0

Please sign in to comment.