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

Mock protocols inherited from NSObjectProtocol #329

Open
paiv opened this issue Jan 24, 2020 · 1 comment
Open

Mock protocols inherited from NSObjectProtocol #329

paiv opened this issue Jan 24, 2020 · 1 comment
Labels
awaiting response A Cuckoo maintainer is awaiting response from the issue/PR author/community. enhancement good first issue If you're looking to contribute, this issue is the way to go!

Comments

@paiv
Copy link

paiv commented Jan 24, 2020

I am trying to mock a protocol inheriting from NSObjectProtocol. This seems like a common scenario, but I don't see it mentioned.

  1. The fist issue is, I need to supply source for NSObjectProtocol to Cuckoo generate. I am using this protocol generated by Xcode:
@objc public protocol NSObjectProtocol {
    func isEqual(_ object: Any?) -> Bool
    var hash: Int { get }
    var superclass: AnyClass? { get }
    func `self`() -> Self
    func perform(_ aSelector: Selector!) -> Unmanaged<AnyObject>!
    func perform(_ aSelector: Selector!, with object: Any!) -> Unmanaged<AnyObject>!
    func perform(_ aSelector: Selector!, with object1: Any!, with object2: Any!) -> Unmanaged<AnyObject>!
    func isProxy() -> Bool
    func isKind(of aClass: AnyClass) -> Bool
    func isMember(of aClass: AnyClass) -> Bool
    func conforms(to aProtocol: Protocol) -> Bool
    func responds(to aSelector: Selector!) -> Bool
    var description: String { get }
    @objc optional var debugDescription: String { get }
}
  1. Next, generated mock MockNSObjectProtocol have compilation issues:
public func self() -> Self {

// Keyword 'self' cannot be used as an identifier here

(see #328)

    return cuckoo_manager.call("self() -> Self",
            parameters: (),
            escapingParameters: (),
            superclassCall:
                
                Cuckoo.MockManager.crashOnProtocolSuperclassCall()
                ,
            defaultCall: __defaultImplStub!.`self`())
        
    }

// Cannot convert return expression of type 'NSObjectProtocol' to return type 'Self'

(seems like #304)

    public var debugDescription: String {
        get {
            return cuckoo_manager.getter("debugDescription",
                superclassCall:
                    
                    Cuckoo.MockManager.crashOnProtocolSuperclassCall()
                    ,
                defaultCall: __defaultImplStub!.debugDescription)
        }
        
    }

// Value of optional type 'String?' must be unwrapped to a value of type 'String'

(copied into #330)

I am stuck at this stage. I assume this is the way it supposed to work, bar generator issues.

@MatyasKriz
Copy link
Collaborator

Oh yes, when we were improving attribute parsing, this was one of the areas that were left untouched. We are currently tending to more pressing matters using the time we have, but if you're interested in adding support for @objc protocols, I'll happily introduce you to the project and answer any of your questions.

As far as I remember, SourceKitten actually gives us the @objc and optional (as per #330) for the attributes, we aren't just handling them correctly at the moment.

@MatyasKriz MatyasKriz added awaiting response A Cuckoo maintainer is awaiting response from the issue/PR author/community. enhancement good first issue If you're looking to contribute, this issue is the way to go! help wanted This issue is asking for a way to solve a problem. and removed good first issue If you're looking to contribute, this issue is the way to go! labels Feb 29, 2020
@MatyasKriz MatyasKriz added good first issue If you're looking to contribute, this issue is the way to go! and removed help wanted This issue is asking for a way to solve a problem. labels May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response A Cuckoo maintainer is awaiting response from the issue/PR author/community. enhancement good first issue If you're looking to contribute, this issue is the way to go!
Projects
None yet
Development

No branches or pull requests

2 participants