Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.66k stars 171 forks source link

Throwing "'some' types are only permitted in properties, subscripts, and functions" when `func` throws & has `some` for its parameter #470

Open enebin opened 1 year ago

enebin commented 1 year ago

First, I'd like to say I've really appreciated your works. It's pure amazement. However, there're a few issues blocking me to do further tasks. I brought some infos about it.

Reproducing code is here:

import SwiftUI

class SomeClass {
    func someMethod(_: some UIViewRepresentable) throws {

    }
}

It generates:

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

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

        func someMethod<M1: Cuckoo.Matchable>(_ parameter0: M1) -> Cuckoo.ClassStubNoReturnThrowingFunction<(some UIViewRepresentable)> where M1.MatchedType == some UIViewRepresentable {
            let matchers: [Cuckoo.ParameterMatcher<(some UIViewRepresentable)>] = [wrap(matchable: parameter0) { $0 }]
            return .init(stub: cuckoo_manager.createStub(for: MockSomeClass.self, method:
    """
    someMethod(_: some UIViewRepresentable) throws
    """, parameterMatchers: matchers))
        }

    }

and


 class MockSomeClass: SomeClass, Cuckoo.ClassMock {

     typealias MocksType = SomeClass

     typealias Stubbing = __StubbingProxy_SomeClass
     typealias Verification = __VerificationProxy_SomeClass

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

    private var __defaultImplStub: SomeClass?

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

     override func someMethod(_ parameter0: some UIViewRepresentable) throws {

    return try cuckoo_manager.callThrows(
    """
    someMethod(_: some UIViewRepresentable) throws
    """,
            parameters: (parameter0),
            escapingParameters: (parameter0),
            superclassCall:

                super.someMethod(parameter0)
                ,
            defaultCall: __defaultImplStub!.someMethod(parameter0))

    }

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

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

        func someMethod<M1: Cuckoo.Matchable>(_ parameter0: M1) -> Cuckoo.ClassStubNoReturnThrowingFunction<(some UIViewRepresentable)> where M1.MatchedType == some UIViewRepresentable {
            let matchers: [Cuckoo.ParameterMatcher<(some UIViewRepresentable)>] = [wrap(matchable: parameter0) { $0 }]
            return .init(stub: cuckoo_manager.createStub(for: MockSomeClass.self, method:
    """
    someMethod(_: some UIViewRepresentable) throws
    """, parameterMatchers: matchers))
        }

    }

     struct __VerificationProxy_SomeClass: 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
        }

        @discardableResult
        func someMethod<M1: Cuckoo.Matchable>(_ parameter0: M1) -> Cuckoo.__DoNotUse<(some UIViewRepresentable), Void> where M1.MatchedType == some UIViewRepresentable {
            let matchers: [Cuckoo.ParameterMatcher<(some UIViewRepresentable)>] = [wrap(matchable: parameter0) { $0 }]
            return cuckoo_manager.verify(
    """
    someMethod(_: some UIViewRepresentable) throws
    """, callMatcher: callMatcher, parameterMatchers: matchers, sourceLocation: sourceLocation)
        }

    }
}

and throws 'some' types are only permitted in properties, subscripts, and functions like the screenshot I attached below:

image

Could you check it once?

MatyasKriz commented 1 year ago

Hey there, @enebin! Thanks for bringing this to light. I'd like to improve the way Cuckoo works with types altogether, so it helps knowing of this case I need to think about. 🙂

MatyasKriz commented 3 months ago

I admit that I completely forgot about this case, but it seems like a good addition to the project. If you're willing to contribute, I'd gladly merge it! 🙂