Kolos65 / Mockable

A Swift macro driven auto-mocking library.
MIT License
199 stars 14 forks source link

My test keeps crashing `EXC_BAD_ACCESS` #16

Closed Boowman closed 5 months ago

Boowman commented 5 months ago
import Foundation
import Mockable

@Mockable
protocol TestProtocol {
    func testing(val: String) -> String
}

class TestService: TestProtocol {
    func testing(val: String = "") -> String {
        return "Testing"
    }
}

class TestViewModel: ObservableObject {
    private var services: TestProtocol
    private var value: String = ""

    init() {
        services = TestService()
        value = services.testing(val: "Some cool")
    }

    convenience init(services: TestProtocol) {
        self.init()
        self.services = services
        self.value = services.testing(val: "Whyyy")
    }

    func getValue() -> String {
        return value
    }
}

I have imported MockableTest into my test file, I have added MOCKING under Custom Flags for Debug and I added Mockable into my main target.

Screenshot 2024-02-05 at 09 44 30
Kolos65 commented 5 months ago

I cant reproduce this, your example is working fine on my end... Can you share your full test case? Do you always get BAD_ACCESS or just every other run?

Boowman commented 5 months ago

I get it every run, I tried it in a blank project, same issue. If it helps I can upload a Github repo and share it with you as it doesn't really make sense why it would crash to be fair.

Screenshot 2024-02-05 at 10 25 53 Screenshot 2024-02-05 at 10 28 14 Screenshot 2024-02-05 at 10 26 05 Screenshot 2024-02-05 at 10 58 56
Kolos65 commented 5 months ago

Please send me a link to an example project, I still cannot repro this. What version of Xcode are you using?

Boowman commented 5 months ago

Link to a test project: https://github.com/Boowman/PlayWorld I am running Xcode 15.2, tested it on 15.0 and I get the same thing.

Screenshot 2024-02-05 at 13 19 22
Kolos65 commented 5 months ago

I found it:

Under the General settings of your PlayWorldTests target, go to Frameworks and Libraries and remove Mockable (keeping MockableTest).

MockableTest also includes Mockable so you only need to add MockableTest to your test targets. See the docs for more info.

Boowman commented 5 months ago

Well, I have good news and bad news:

Kolos65 commented 5 months ago

clean + reset packages cache + delete derived data + reopen xcode

Boowman commented 5 months ago

That did not seem to work, I am wondering if there is something I have to have enabled. I remember in other new projects I would get a popup on the side to allow macros. I didn't get it this time as it was an older project.

If I expand the macro I can see it getting created so I doubt it has anything to do with Allow & Trust