Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 175 forks source link

Generated code not confirm to protocol #414

Closed bupojung closed 5 months ago

bupojung commented 2 years ago

this is the protocol

protocol PreviewVMOutput {
    typealias State = PreviewViewModel.State
    var previewState: Driver<State> { get }
    var previewAction: Signal<PreviewAction> { get }
}

generated code is:

class MockPreviewVMOutput: PreviewVMOutput, Cuckoo.ProtocolMock {

     typealias MocksType = PreviewVMOutput

     typealias Stubbing = __StubbingProxy_DKPreviewVMOutput
     typealias Verification = __VerificationProxy_DKPreviewVMOutput

     let cuckoo_manager = Cuckoo.MockManager.preconfiguredManager ?? Cuckoo.MockManager(hasParent: false)

    private var __defaultImplStub: PreviewVMOutput?

     func enableDefaultImplementation(_ stub: PreviewVMOutput) {
        __defaultImplStub = stub
        cuckoo_manager.enableDefaultStubImplementation()
    }

     var previewState: Driver<State> {
        get {
            return cuckoo_manager.getter("previewState",
                superclassCall:

                    Cuckoo.MockManager.crashOnProtocolSuperclassCall()
                    ,
                defaultCall: __defaultImplStub!.previewState)
        }

    }

     var previewAction: Signal<PreviewAction> {
        get {
            return cuckoo_manager.getter("previewAction",
                superclassCall:

                    Cuckoo.MockManager.crashOnProtocolSuperclassCall()
                    ,
                defaultCall: __defaultImplStub!.previewAction)
        }

    }

     struct __StubbingProxy_DKPreviewVMOutput: Cuckoo.StubbingProxy {
        private let cuckoo_manager: Cuckoo.MockManager

         init(manager: Cuckoo.MockManager) {
            self.cuckoo_manager = manager
        }

        var previewState: Cuckoo.ProtocolToBeStubbedReadOnlyProperty<MockPreviewVMOutput, Driver<State>> {
            return .init(manager: cuckoo_manager, name: "previewState")
        }

        var previewAction: Cuckoo.ProtocolToBeStubbedReadOnlyProperty<MockPreviewVMOutput, Signal<PreviewAction>> {
            return .init(manager: cuckoo_manager, name: "previewAction")
        }

    }

     struct __VerificationProxy_PreviewVMOutput: Cuckoo.VerificationProxy {
        private let cuckoo_manager: Cuckoo.MockManager
        private let callMatcher: Cuckoo.CallMatcher
        private let sourceLocation: Cuckoo.SourceLocation

         init(manager: Cuckoo.MockManager, callMatcher: Cuckoo.CallMatcher, sourceLocation: Cuckoo.SourceLocation) {
            self.cuckoo_manager = manager
            self.callMatcher = callMatcher
            self.sourceLocation = sourceLocation
        }

        var previewState: Cuckoo.VerifyReadOnlyProperty<Driver<State>> {
            return .init(manager: cuckoo_manager, name: "previewState", callMatcher: callMatcher, sourceLocation: sourceLocation)
        }

        var previewAction: Cuckoo.VerifyReadOnlyProperty<Signal<PreviewAction>> {
            return .init(manager: cuckoo_manager, name: "previewAction", callMatcher: callMatcher, sourceLocation: sourceLocation)
        }

    }
}

and this code encounter two errors:

  1. Type 'MockPreviewVMOutput' does not conform to protocol 'PreviewVMOutput';
  2. Type of expression is ambiguous without more context image
MatyasKriz commented 2 years ago

Seems to me like the problem is in Cuckoo not copying your typealias but still using just the aliased type.

I don't know if this is the case, but try to manually add the typealias into the mocked type to see if that's the reason. You need to disable mock generation to prevent it being overwritten for this test.

Another way to test this theory is to not use the typealias and instead the whole type.

bupojung commented 2 years ago

Seems to me like the problem is in Cuckoo not copying your typealias but still using just the aliased type.

I don't know if this is the case, but try to manually add the typealias into the mocked type to see if that's the reason. You need to disable mock generation to prevent it being overwritten for this test.

Another way to test this theory is to not use the typealias and instead the whole type.

I use whole type instead resolve the error. thanks

MatyasKriz commented 2 years ago

I'll reopen the issue if you don't mind, this is merely a workaround that shouldn't be necessary. This must be fixed on Cuckoo side.

MatyasKriz commented 5 months ago

Fixed in 2.0.4 where typealiases are copied over to the mock.