Macros seem to persist between test and run builds
Macros seem to persist between test and run builds
- Subject: Macros seem to persist between test and run builds
- From: Fritz Anderson <email@hidden>
- Date: Tue, 31 May 2011 13:14:24 -0500
Xcode 4.0.2, Mac OS X 10.6.7, iOS 4.3 SDK
SUMMARY: Preprocessor macro settings from a Test build action apparently stay set in a subsequent Run build, despite being explicitly given different values.
I have an iPad app that works with AVFoundation. I want to do some unit testing of my class that does arithmetic with trees of AVAssets. Many of those operations are asynchronous, and keeping audio files around for testing is a headache, so for testing, I substitute mock classes for the AVAsset classes. My production code uses macro invocations for the class names, and I define them differently in the unit-test and application PCHes (I precompile the prefix headers):
Application prefix file:
#define MUTABLE_COMPOSITION_CLASS AVMutableComposition
#define COMPOSITION_CLASS AVComposition
#define ASSET_CLASS AVAsset
#define URL_ASSET_CLASS AVURLAsset
#define MOCK_ASSETS 0
Unit-test prefix file:
#define MUTABLE_COMPOSITION_CLASS MockAVMutableComposition
#define COMPOSITION_CLASS MockAVComposition
#define ASSET_CLASS MockAVAsset
#define URL_ASSET_CLASS MockAVURLAsset
#define MOCK_ASSETS 1
The scheme for the application target are set so that the application target is set for all actions but Test. The unit-test target is included, and is set for Test only.
I do a clean, and then build-for-running of the application. The build completes without error.
I use the Test action. The test builds and runs without error.
I then do a build-for-running of the application again. My asset references should resolve to the non-mock classes. But I get warnings that I'm passing Mock* classes to API that expects AV classes. Further, I added a warning to one of my headers, to flag that mock assets are being used:
#if MOCK_ASSETS
#warning Importing Mock Assets
#import "MockAVAsset.h"
#endif
The second build-for-run triggers the warning.
The same happens when I put the definitions in "Preprocessor Macros" or "Preprocessor Macros Not Used In Precompiled Headers."
I've verified that the two targets are using the proper prefix headers.
It appears that something lingers from the testing build. Either the wrong .pch gets used, or something caches the macros. Or I'm missing something essential.
This setup worked in Xcode 3. A lot has changed between Xc3 and Xc4; maybe I'm missing an essential feature of the new architecture. Can anyone straighten me out?
Or, can you suggest how to work around this? Maybe by resigning myself to building-for-run the test target (setting TEST_AFTER_BUILD)? Or just cleaning the application target after every test run?
— F
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden