From 6ef81aa11edbc435f9ab1eb2c1d6f47b1a93fa46 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Tue, 26 Nov 2013 16:00:18 +0000 Subject: - Add gcov flushes that will happen within the test bundles to also capture the coverage data there. Needed if you link some of your code directly into the test bundles or if you have code in headers (inlines, c++ templates, etc.) - Add a preprocessor gate to only bring in the coverage support when enabled, lets you add the source, and then use a Xcode Configuration to control when it is needed, otherwise you can end up linking coverage into your Release builds. DELTA=28 (28 added, 0 deleted, 0 changed) --- UnitTesting/GTMCodeCoverageApp.m | 6 ++++++ UnitTesting/GTMCodeCoverageTestsST.m | 11 +++++++++++ UnitTesting/GTMCodeCoverageTestsXC.m | 11 +++++++++++ 3 files changed, 28 insertions(+) (limited to 'UnitTesting') diff --git a/UnitTesting/GTMCodeCoverageApp.m b/UnitTesting/GTMCodeCoverageApp.m index 3bc7fae..415d0c0 100644 --- a/UnitTesting/GTMCodeCoverageApp.m +++ b/UnitTesting/GTMCodeCoverageApp.m @@ -25,6 +25,10 @@ #import "GTMCodeCoverageApp.h" +// Add GTM_IS_COVERAGE_BUILD to your GCC_PREPROCESSOR_DEFINITIONS for the +// Xcode Configuration that wants CodeCoverage support. +#if GTM_IS_COVERAGE_BUILD + extern void __gcov_flush(); @implementation UIApplication(GTMCodeCoverage) @@ -54,3 +58,5 @@ extern void __gcov_flush(); #endif // GTM_USING_XCTEST @end + +#endif // GTM_IS_COVERAGE_BUILD diff --git a/UnitTesting/GTMCodeCoverageTestsST.m b/UnitTesting/GTMCodeCoverageTestsST.m index a73fdad..0159a53 100644 --- a/UnitTesting/GTMCodeCoverageTestsST.m +++ b/UnitTesting/GTMCodeCoverageTestsST.m @@ -28,6 +28,12 @@ #import "GTMCodeCoverageApp.h" +// Add GTM_IS_COVERAGE_BUILD to your GCC_PREPROCESSOR_DEFINITIONS for the +// Xcode Configuration that wants CodeCoverage support. +#if GTM_IS_COVERAGE_BUILD + +extern void __gcov_flush(); + static int gSuiteCount = 0; @interface GTMCodeCoverageTests : NSObject @@ -63,7 +69,12 @@ static int gSuiteCount = 0; if ([application respondsToSelector:@selector(gtm_gcov_flush)]) { [application performSelector:@selector(gtm_gcov_flush)]; } + + // Call flush for this executable unit. + __gcov_flush(); } } @end + +#endif // GTM_IS_COVERAGE_BUILD diff --git a/UnitTesting/GTMCodeCoverageTestsXC.m b/UnitTesting/GTMCodeCoverageTestsXC.m index 39e4850..b960c26 100644 --- a/UnitTesting/GTMCodeCoverageTestsXC.m +++ b/UnitTesting/GTMCodeCoverageTestsXC.m @@ -28,6 +28,12 @@ #import "GTMCodeCoverageApp.h" +// Add GTM_IS_COVERAGE_BUILD to your GCC_PREPROCESSOR_DEFINITIONS for the +// Xcode Configuration that wants CodeCoverage support. +#if GTM_IS_COVERAGE_BUILD + +extern void __gcov_flush(); + @interface GTMCodeCoverageTests : XCTestObserver @end @@ -42,6 +48,9 @@ [application performSelector:@selector(gtm_gcov_flush)]; } + // Call flush for this executable unit. + __gcov_flush(); + // Reset defaults back to what they should be. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults removeObjectForKey:XCTestObserverClassKey]; @@ -70,3 +79,5 @@ } @end + +#endif // GTM_IS_COVERAGE_BUILD -- cgit v1.2.3