erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Add a macro to disable XCTest support optionally #495

Closed matrush closed 3 years ago

matrush commented 3 years ago

We have some use cases needs to use OCMock without linking XCTest framework. E.g. In snapshot tests where a binary is expected to run with mock objects. Linking XCTest will cause the binary failed to run. The error is:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest

I think adding a macro to support opt-out is probably a better idea for cases like this. By default the XCTest framework support is still on so most of the users won't be affected.

erikdoe commented 3 years ago

Can I ask how you build OCMock? I'm asking because XCTest is explicitly linked in the .xcodeproj file. Or does Apple's build system now optimise this and doesn't link a framework if nothing is referenced in it?

matrush commented 3 years ago

Can I ask how you build OCMock? I'm asking because XCTest is explicitly linked in the .xcodeproj file. Or does Apple's build system now optimise this and doesn't link a framework if nothing is referenced in it?

Hi @erikdoe, our projects were using BUCK to build projects from the source code which might be slightly different from the common flow. But I guess you can get the idea, if the built binary has XCTest and was linked to another binary target (like Application), it will cause the issue. See some discussions here

erikdoe commented 3 years ago

Of course! I forgot you're at Facebook. Now this makes sense; you can change your Buck file to drop the dependency on XCTest, but you need the references in the source removed. I'll merge this PR but will leave this feature undocumented. It's such a niche use case. By the way, I remember discussing the pros and cons of monorepos and custom build systems with @shs96c years ago, and now it's arrived here.

erikdoe commented 3 years ago

During the merge I renamed the define. It's called OCM_DISABLE_XCTEST_FEATURES now. I've also used this new define for the watchOS build because that also needed to skip the XCTest-based features.