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
14 changes: 12 additions & 2 deletions Sources/DevTesting/Stubbing/Stub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extension ThrowingStub where ReturnType == Void {
/// - Parameters:
/// - defaultError: The error that the stub will throw when the error queue is empty.
/// - errorQueue: A queue of errors to throw. If empty, `defaultError` is used instead.
public convenience init(defaultError: ErrorType? = nil, errorQueue: [ErrorType?] = []) {
public convenience init(defaultError: ErrorType?, errorQueue: [ErrorType?] = []) {
self.init(
defaultResult: defaultError.map(Result.failure(_:)) ?? .success(()),
resultQueue: errorQueue.map { $0.map(Result.failure(_:)) ?? .success(()) }
Expand Down Expand Up @@ -257,7 +257,7 @@ extension ThrowingStub where ErrorType == Never {
/// - Parameters:
/// - defaultReturnValue: The return value of the stub when the return value queue is empty.
/// - returnValueQueue: A queue of values to return. If empty, `defaultReturnValue` is used.
public convenience init(defaultReturnValue: ReturnType, returnValueQueue: [ReturnType] = []) {
public convenience init(defaultReturnValue: ReturnType, returnValueQueue: [ReturnType]) {
self.init(
defaultResult: .success(defaultReturnValue),
resultQueue: returnValueQueue.map(Result.success(_:))
Expand Down Expand Up @@ -306,3 +306,13 @@ extension ThrowingStub.Call where ErrorType == Never {
}
}
}


// MARK: - ReturnType is Void and ErrorType is Never

extension ThrowingStub where ReturnType == Void, ErrorType == Never {
/// Creates a new stub with an empty tuple as the default return value.
public convenience init() {
self.init(defaultReturnValue: ())
}
}
5 changes: 4 additions & 1 deletion Tests/DevTestingTests/Stubbing/StubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@


@Test
func convenenienceInitWhenReturnTypeIsVoidAndErrorTypeIsNever() {
func convenenienceInitsOverloadWithoutColision() {
let stub = Stub<Void, Void>()
let stub2 = Stub<Void, Int>(defaultReturnValue: 3)

Check warning on line 190 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub2' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 190 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub2' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 190 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub2' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 190 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub2' was never used; consider replacing with assignment to '_' or removing it
let stub4 = ThrowingStub<Void, Void, any Error>(defaultError: nil)

Check warning on line 191 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub4' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 191 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub4' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 191 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub4' was never used; consider replacing with assignment to '_' or removing it
let stub3 = ThrowingStub<Void, Int, any Error>(defaultError: HashableError(id: 2))

Check warning on line 192 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub3' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 192 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub3' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 192 in Tests/DevTestingTests/Stubbing/StubTests.swift

View workflow job for this annotation

GitHub Actions / Build and Test (macOS)

initialization of immutable value 'stub3' was never used; consider replacing with assignment to '_' or removing it

// There’s nothing to actually test here, as the compiler guarantees everything we would test. Check the result
// queue just for posterity
Expand Down