Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ public final class MockReturningNonParameterizedAsyncMethod<ReturnValue> {
/// - Returns: A value, if ``implementation-swift.property`` returns a
/// value.
private func invoke() async -> ReturnValue {
self.callCount += 1
self._callCount.withLockUnchecked { callCount in
callCount += 1
}

guard let returnValue = await self.implementation() else {
fatalError("Unimplemented: \(self.exposedMethodDescription)")
}

self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}

return returnValue
}
Expand All @@ -118,9 +122,15 @@ public final class MockReturningNonParameterizedAsyncMethod<ReturnValue> {

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public final class MockReturningNonParameterizedAsyncThrowingMethod<ReturnValue>
/// - Returns: A value, if ``implementation-swift.property`` returns a
/// value.
private func invoke() async throws -> ReturnValue {
self.callCount += 1
self._callCount.withLockUnchecked { callCount in
callCount += 1
}

let returnValue = await Result {
guard let returnValue = try await self.implementation() else {
Expand All @@ -115,7 +117,9 @@ public final class MockReturningNonParameterizedAsyncThrowingMethod<ReturnValue>
return returnValue
}

self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}

return try returnValue.get()
}
Expand All @@ -124,9 +128,15 @@ public final class MockReturningNonParameterizedAsyncThrowingMethod<ReturnValue>

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ public final class MockReturningNonParameterizedMethod<ReturnValue> {
/// - Returns: A value, if ``implementation-swift.property`` returns a
/// value.
private func invoke() -> ReturnValue {
self.callCount += 1
self._callCount.withLockUnchecked { callCount in
callCount += 1
}

guard let returnValue = self.implementation() else {
fatalError("Unimplemented: \(self.exposedMethodDescription)")
}

self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}

return returnValue
}
Expand All @@ -116,9 +120,15 @@ public final class MockReturningNonParameterizedMethod<ReturnValue> {

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public final class MockReturningNonParameterizedThrowingMethod<ReturnValue> {
/// - Returns: A value, if ``implementation-swift.property`` returns a
/// value.
private func invoke() throws -> ReturnValue {
self.callCount += 1
self._callCount.withLockUnchecked { callCount in
callCount += 1
}

let returnValue = Result {
guard let returnValue = try self.implementation() else {
Expand All @@ -115,7 +117,9 @@ public final class MockReturningNonParameterizedThrowingMethod<ReturnValue> {
return returnValue
}

self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}

return try returnValue.get()
}
Expand All @@ -124,9 +128,15 @@ public final class MockReturningNonParameterizedThrowingMethod<ReturnValue> {

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ public final class MockReturningParameterizedAsyncMethod<
/// - Parameter arguments: The arguments with which the method is being
/// invoked.
private func recordInput(arguments: Arguments) {
self.callCount += 1
self.invocations.append(arguments)
self._callCount.withLockUnchecked { callCount in
callCount += 1
}
self._invocations.withLockUnchecked { invocations in
invocations.append(arguments)
}
}

/// Returns the method's implementation as a closure, or triggers a fatal
Expand All @@ -160,17 +164,27 @@ public final class MockReturningParameterizedAsyncMethod<
///
/// - Parameter returnValue: The value returned by the method.
private func recordOutput(returnValue: ReturnValue) {
self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}
}

// MARK: Reset

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.invocations.removeAll()
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._invocations.withLockUnchecked { invocations in
invocations.removeAll()
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,12 @@ public final class MockReturningParameterizedAsyncThrowingMethod<
/// - Parameter arguments: The arguments with which the method is being
/// invoked.
private func recordInput(arguments: Arguments) {
self.callCount += 1
self.invocations.append(arguments)
self._callCount.withLockUnchecked { callCount in
callCount += 1
}
self._invocations.withLockUnchecked { invocations in
invocations.append(arguments)
}
}

/// Returns the method's implementation as a closure, or triggers a fatal
Expand All @@ -168,17 +172,27 @@ public final class MockReturningParameterizedAsyncThrowingMethod<
///
/// - Parameter returnValue: The value returned by the method.
private func recordOutput(returnValue: Result<ReturnValue, Error>) {
self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}
}

// MARK: Reset

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.invocations.removeAll()
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._invocations.withLockUnchecked { invocations in
invocations.removeAll()
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ public final class MockReturningParameterizedMethod<
/// - Parameter arguments: The arguments with which the method is being
/// invoked.
private func recordInput(arguments: Arguments) {
self.callCount += 1
self.invocations.append(arguments)
self._callCount.withLockUnchecked { callCount in
callCount += 1
}
self._invocations.withLockUnchecked { invocations in
invocations.append(arguments)
}
}

/// Returns the method's implementation as a closure, or triggers a fatal
Expand All @@ -160,17 +164,27 @@ public final class MockReturningParameterizedMethod<
///
/// - Parameter returnValue: The value returned by the method.
private func recordOutput(returnValue: ReturnValue) {
self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}
}

// MARK: Reset

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.invocations.removeAll()
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._invocations.withLockUnchecked { invocations in
invocations.removeAll()
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ public final class MockReturningParameterizedThrowingMethod<
/// - Parameter arguments: The arguments with which the method is being
/// invoked.
private func recordInput(arguments: Arguments) {
self.callCount += 1
self.invocations.append(arguments)
self._callCount.withLockUnchecked { callCount in
callCount += 1
}
self._invocations.withLockUnchecked { invocations in
invocations.append(arguments)
}
}

/// Returns the method's implementation as a closure, or triggers a fatal
Expand All @@ -167,17 +171,27 @@ public final class MockReturningParameterizedThrowingMethod<
///
/// - Parameter returnValue: The value returned by the method.
private func recordOutput(returnValue: Result<ReturnValue, Error>) {
self.returnedValues.append(returnValue)
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.append(returnValue)
}
}

// MARK: Reset

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self.invocations.removeAll()
self.returnedValues.removeAll()
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
self._invocations.withLockUnchecked { invocations in
invocations.removeAll()
}
self._returnedValues.withLockUnchecked { returnedValues in
returnedValues.removeAll()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,21 @@ public final class MockVoidNonParameterizedAsyncMethod: Sendable {
/// Records the invocation of the method and invokes
/// ``implementation-swift.property``.
private func invoke() async {
self.callCount += 1
self._callCount.withLockUnchecked { callCount in
callCount += 1
}
await self.implementation()
}

// MARK: Reset

/// Resets the method's implementation and invocation records.
private func reset() {
self.implementation = .unimplemented
self.callCount = .zero
self._implementation.withLockUnchecked { implementation in
implementation = .unimplemented
}
self._callCount.withLockUnchecked { callCount in
callCount = .zero
}
}
}
Loading
Loading