OCMock Failing at runtime

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

OCMock Failing at runtime

Postby TheDov » 06 Mar 2012, 17:36

I'm trying to use OCMock for the first time in my test cases. It's a Mac project, built on and targeting Lion, in Xcode 4.3. The main app and the test bundle both have ARC turned on, and so every time I execute the tests I see the following log message:

Code: Select all
GC: forcing GC OFF because OBJC_DISABLE_GC is set


That's fine, as I'm using ARC so I don't care about GC. When I build my unit tests, linked against the latest stable release of OCMock (2.0.1), the build has no issues. At runtime, after the above log statement, I get the following:

Code: Select all
The test bundle at /Users/___/Library/Developer/Xcode/DerivedData/___-ayizwpehemunvodsdvczckkvarsh/Build/Products/Debug/___Tests.octest could not be loaded because its Objective-C runtime information does not match the runtime information required by the test rig.  This is likely because the test rig is being run with Objective-C garbage collection disabled, but the test bundle requires Objective-C garbage collection.  To enable Objective-C garbage collection for the test rig, run it in an environment without the OBJC_DISABLE_GC environment variable.
2012-03-06 10:29:32.812 otest[8486:203] *** NSTask: Task create for path '/Users/___/Library/Developer/Xcode/DerivedData/___-ayizwpehemunvodsdvczckkvarsh/Build/Products/Debug/___Tests.octest/Contents/MacOS/___Tests' failed: 22, "Invalid argument".  Terminating temporary process.


The message implies that garbage collection is the most common culprit, but as mentioned, there is no way I'm using GC. So, what other settings could be messing me up at runtime? I didn't think I'm doing anything atypical, and I've looked through my test project's settings to be sure, and didn't see anything weird.
TheDov
 

Re: OCMock Failing at runtime

Postby TheDov » 06 Mar 2012, 20:31

I was able to reproduce this with a new empty project.

1. Create a new project and have it create unit tests, with ARC enabled
2. Clear the Test Host setting from the unit test bundle's build settings
3. Link to the OCMock framework
4. Execute the tests, and witness the same error I reported in the original post
TheDov
 
Posts: 2
Joined: 06 Mar 2012, 17:45

Re: OCMock Failing at runtime

Postby TheDov » 07 Mar 2012, 02:54

I got it, and also posted the answer on Stack Overflow: http://stackoverflow.com/a/9594265/105717

After a day of searching everything I could think of, I found the answer in the Hamcrest tutorial (http://code.google.com/p/hamcrest/wiki/TutorialObjectiveC). For some reason, Hamcrest's and OCMock's frameworks need to be copied to the products directory. Then everything works like a charm.

1. Go to the settings for your Tests Bundle
2. Go to the Build Phases tab
3. Click the Add Build Phase button, and select Add Copy Files
4. Set the new Copy Files build phases' Destination to Products Directory
5. Drag OCMock.framework from the project outline into the list of files for the phase
6. Drag the Copy Files phase above the Run Script phase
TheDov
 
Posts: 2
Joined: 06 Mar 2012, 17:45


Return to OCMock



cron