Wednesday, 2 October 2013

Generate gcda-files with Xcode5, iOS7 simulator and XCTest

Generate gcda-files with Xcode5, iOS7 simulator and XCTest

Being inspired by the solution to this question I tried using the same
approach with XCTest.
I've set 'Generate Test Coverage Files=YES' and 'Instrument Program
Flow=YES' as well as added -lgcov to 'Other Linker Flags'. This gave me
the compiler error: ld: library not found for -lgcov
After some researched I learned that I had to manually find a suitable
libgcov.a as XCode5 doesn't seem to have that anymore. I found a bunch in
my old XCode(4).app that I've moved to my repository and added the path to
the 'Library Search Paths', but I get an error messages on the form:
duplicate symbol ___gcov_flush in:
repository/libs/gcov/i686/libgcov.a(_gcov.o)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.profile_ios.a(GCDAProfiling.o)
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
or using an incorrect library for the target architecture:
ld: warning: ignoring file /repository/libs/gcov/x86_64/libgcov.a, file
was built for archive which is not the architecture being linked (i386):
/repository/libs/gcov/x86_64/libgcov.a
XCode still doesn't produce any gcda files. Anyone have any ideas of how
to solve this?
Code:
#import <XCTest/XCTestLog.h>
@interface VATestObserver : XCTestLog
@end
static id mainSuite = nil;
@implementation VATestObserver
extern void __gcov_flush(void);
+ (void)initialize {
[[NSUserDefaults standardUserDefaults] setValue:@"VATestObserver"
forKey:XCTestObserverClassKey];
[super initialize];
}
- (void)testSuiteDidStart:(XCTestRun *)testRun {
[super testSuiteDidStart:testRun];
XCTestSuiteRun *suite = [[XCTestSuiteRun alloc] init];
[suite addTestRun:testRun];
if (mainSuite == nil) {
mainSuite = suite;
}
}
- (void)testSuiteDidStop:(XCTestRun *)testRun {
[super testSuiteDidStop:testRun];
XCTestSuiteRun *suite = [[XCTestSuiteRun alloc] init];
[suite addTestRun:testRun];
if (mainSuite == suite) {
UIApplication* application = [UIApplication sharedApplication];
[application.delegate applicationWillTerminate:application];
}
}
- (void)applicationWillTerminate:(UIApplication*)application {
__gcov_flush();
}
@end

No comments:

Post a Comment