Brightify / Cuckoo

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

Unable to mock functions with certain keywords as argument labels #452

Closed sethdeckard closed 1 year ago

sethdeckard commented 1 year ago

Generate a mock for the following protocol:

protocol TestProtocol {
    func test(for: String)
}

This produces code that will not compile because the keyword when used in the body of the method is not escaped:

     func test(for: String)  {

    return cuckoo_manager.call(
    """
    test(for: String)
    """,
            parameters: (for), // error here
            escapingParameters: (for), // error here
            superclassCall:

                Cuckoo.MockManager.crashOnProtocolSuperclassCall()
                ,
            defaultCall: __defaultImplStub!.test(for: for)) // error here (and a few other places)

    }

PR https://github.com/Brightify/Cuckoo/pull/412 seems to attempt to address this, but only for the function name itself. Which kind of seems odd given that using for as an argument label seems somewhat common compared to using it as a function name, which seems like more of an edge case. In fact, Foundation actually has several functions that use for: as an argument label.

The release notes mention this as being fixed but I think that should have been limited to function names (probably due to commit title being too general):

Reserved keywords are now escaped. (thank you, @sk409!)

Cuckoo version: 1.9.1

sethdeckard commented 1 year ago

It looks like I was able to patch this on my side, by mostly changing the templates, but also some of the filters. I'll submit a PR in the am. 😄

sethdeckard commented 1 year ago

@MatyasKriz Here's the PR: https://github.com/Brightify/Cuckoo/pull/454