Brightify / Cuckoo

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

PropertyObservers affecting mocked property generation. #501

Closed Marquis103 closed 4 months ago

Marquis103 commented 4 months ago

This is something new in Cuckoo 2 that was not in the original version. If I have a property say:

var number: Int = 0 {
  didSet {
    print("\(number)")
  }
}

The mock for this property will be:

    override var number: Int {
        get {
            return cuckoo_manager.getter(
                "number",
                superclassCall: super.number,
                defaultCall: __defaultImplStub!.number
            )
        }
    }

Naturally we will get an error here because we are overriding a mutable property with a read-only implementation. When I switch to the latest version of the original cuckoo it doesn't do that. Even more, if I remove the didSet:

var number: Int = 0

It will override ride the property with its expected getter and setter.

Any thoughts or assistance anyone can provide on this?

MatyasKriz commented 4 months ago

Hey, @Marquis103, thanks for the report, this is simply an oversight when converting from SourceKitten to SwiftSyntax.

During this we can see how incomplete our tests were. 😄 I'll take a look at it.

Marquis103 commented 4 months ago

Thanks @MatyasKriz for the speedy response

MatyasKriz commented 4 months ago

I've fixed this one, thanks for reporting it. 🙂

However, I'm having some problems releasing a new version because of Xcode update, I'll take a look at it as soon as I can.

MatyasKriz commented 4 months ago

Fixed and released. Enjoy!