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

When using @DependencyClient macro, closures with mandatory return don't use the unimplemented version on tests #183

Open
3 tasks done
gpambrozio opened this issue Feb 9, 2024 · 0 comments
Labels
apple bug Something isn't working due to a bug on Apple's platforms.

Comments

@gpambrozio
Copy link

gpambrozio commented Feb 9, 2024

Description

When using @DependencyClient macro in a client that has closures with mandatory returns, when using these closures in a test without overriding them we don't get errors about the method not being implemented.

According to this message from Brandon this is related to a swift bug. Given that I'd suggest to at least add a note to the documentation mentioning that, instead of having a closure such as { _ in true }, we unfortunately still have to use { _ in unimplemented(placeholder: true) }

See also this Slack thread

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

The test shown should have 2 errors.

Actual behavior

The test only produces one error.

Steps to reproduce

Simple Client:

import Dependencies
import DependenciesMacros

@DependencyClient
struct SimpleClient {
    var noReturn: () -> Void
    var withBoolReturn: () -> Bool = { true }
}

extension SimpleClient: TestDependencyKey {
    public static let testValue = SimpleClient()
}

extension DependencyValues {
    var simpleClient: SimpleClient {
        get { self[SimpleClient.self] }
        set { self[SimpleClient.self] = newValue }
    }
}

This test should have 2 failures but only shows one:

import Dependencies
import XCTest
@testable import TCATest

final class TCATestTests: XCTestCase {
    func testExample() throws {
        @Dependency(\.simpleClient) var simpleClient
        _ = simpleClient.withBoolReturn()
        simpleClient.noReturn()
    }
}

Dependencies version information

1.2.1

Destination operating system

iOS

Xcode version information

15.2

Swift Compiler version information

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
@gpambrozio gpambrozio added the bug Something isn't working label Feb 9, 2024
@mbrandonw mbrandonw added apple bug Something isn't working due to a bug on Apple's platforms. and removed bug Something isn't working labels Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple bug Something isn't working due to a bug on Apple's platforms.
Projects
None yet
Development

No branches or pull requests

2 participants