Navigation
Other Sites
My Stuff:
Search
Twitterings
Tuesday
04Mar2008

Xcode: Unit Testing Built Products

Just wanted to share a little trick I recently developed for Xcode. I had a problem with FlickrExport 3: the Info.plist file was not being regenerated correctly when I built the target without cleaning it first. This problem only came to light when I started using preprocessing in the Info.plist to fill in the CFBundleVersion from a build setting defined in a .xcconfig file. The result was that I thought I was building version 3.0.0bX and the final product's Info.plist was actually 3.0.0b(X-1).

What I wanted to do was to check that everything was copacetic in the built product after the build was finished. My solution was to add a final Shell Script build phase to the target with the following code:


grep -q "${FE_APERTURE_VERSION}" \
"${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"
if [ $? -eq 0 ]; then
echo "Plist check passed."
else
echo "Error: out of date plist in built product. Perform a clean build."
exit 1
fi


This fragment greps the built Info.plist file for the current value of the FE_APERTURE_VERSION build setting. If they don't match, the script exits with a non-zero code and Xcode stops the build.

I've since expanded this a bit to check that the included frameworks are in their proper locations, are correctly built as Universal Binaries and so on.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>