Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of all the FileID/FilePath/line/column macros with SourceLocation #1185

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}

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 Expand Up @@ -188,7 +188,7 @@
return toAlwaysWithDescription
}

@objc public class func failWithMessage(_ message: String, file: FileString, line: UInt) {

Check warning on line 191 in Sources/Nimble/Adapters/NMBExpectation.swift

View workflow job for this annotation

GitHub Actions / lint

Static Over Final Class Violation: Prefer `static` over `class` in a final class (static_over_final_class)
fail(message, location: SourceLocation(fileID: "Unknown/\(file)", filePath: file, line: line, column: 0))
}
}
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
Loading