When build and running tests with code coverage enabled for iOS projects with CocoaPods, the code in the included pods will also be taken into account by default. In order to disable code coverage and warnings from included pods, add the below block to the Podfile
.
# Disable code coverage for pod files
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
config.build_settings['SWIFT_EXEC'] = '$(SRCROOT)/../SWIFT_EXEC-no-coverage'
config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = ''
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
config.build_settings['CODE_SIGNING_REQUIRED'] = 'NO'
end
end
installer.pods_project.build_configurations.each do |config|
config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = ''
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
config.build_settings['CODE_SIGNING_REQUIRED'] = 'NO'
end
end
Create a file SWIFT_EXEC-no-coverage
in the root folder at the same level as Podfile
with the below snippet and make the file executable by running chmod +x SWIFT_EXEC-no-coverage
.
#! /usr/bin/perl -w
use strict;
use Getopt::Long qw(:config pass_through);
my $profile_coverage_mapping;
GetOptions("profile-coverage-mapping" => \$profile_coverage_mapping);
exec("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", @ARGV);