Skip to content

Commit 317ae0e

Browse files
Merge pull request #7 from jonreid/master
Upstream Pull
2 parents a25f4be + 1377a4d commit 317ae0e

12 files changed

+255
-123
lines changed

CHANGES.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Version 1.2.2
2+
-------------
3+
_22 Mar 2015_
4+
5+
* Add `getcov` command line parameters, making it easier to use XcodeCoverage in continuous integration. _Thanks to: Tom Aylesworth_
6+
* Add Cobertura XML generation. _Thanks to: Ellen Shapiro_
7+
* Support use as CocoaPod. _Thanks to: Ellen Shapiro_
8+
* Update to lcov 1.11. _Thanks to: Ellen Shapiro_
9+
* Add XcodeCoverage.xcconfig for simple project setup.
10+
11+
12+
Version 1.1.1
13+
-------------
14+
_13 Nov 2014_
15+
16+
* Exclude "Developer/SDKs" instead of "Applications/Xcode.app" so that people can use multiple versions of Xcode. _Thanks to: Cédric Luthi_
17+
* Quote arguments to support built products directory containing spaces. _Thanks to: Cédric Luthi_
18+
* Fix functionality optional post-test dialog in other locales by forcing buttons to be in English.
19+
20+
21+
Version 1.1.0
22+
-------------
23+
_30 Mar 2014_
24+
25+
* Support Xcode 5.1. _Thanks to: Mike Maietta_
26+
* Add optional post-test script `run_code_coverage_post.sh` to prompt whether to generate coverage report. _Thanks to: Matthew Purland_
27+
* Improve function coverage by specifying `--derive-func-data`. _Thanks to: jstevenco_
28+
* Directly include copy of lcov 1.10.
29+
30+
31+
Version 1.0.1
32+
-------------
33+
_09 Mar 2014_
34+
35+
* Fix: Use `CURRENT_ARCH` instead of `NATIVE_ARCH`. _Thanks to: Scott Densmore_
36+
* Improve scripts so they can be run from any working directory.
37+
* Export `OBJROOT` so that customizations can include subprojects.
38+
39+
40+
Version 1.0.0
41+
-------------
42+
_01 Dec 2012_
43+
44+
* Initial release

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
XcodeCoverage by Jon Reid, http://qualitycoding/about/
2-
Copyright 2014 Jonathan M. Reid
2+
Copyright 2015 Jonathan M. Reid
33

44
Permission is hereby granted, free of charge, to any person obtaining a copy of
55
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
![XcodeCoverage](http://qualitycoding.org/jrwp/wp-content/uploads/2014/03/XcodeCoverage.png)
22

3-
These scripts provide a simple way to generate HTML reports of the code coverage of your Xcode project.
3+
XcodeCoverage provides a simple way to generate reports of the code coverage of your Xcode project. Generated reports include HTML and Cobertura XML.
44

5-
6-
Xcode Project Setup
7-
===================
8-
9-
Before you get started, there are a couple of steps you will need to take to prepare your project:
10-
11-
1. Depending on your version of Xcode, you may need to get Xcode's coverage instrumentation by going to Xcode > Preferences, into Downloads, and installing Command Line Tools. If you do not see this as an option in the Downloads section, the tools should already be installed.
12-
4. In your Xcode project, enable these two build settings at the project level for your Debug configuration only:
13-
* Instrument Program Flow
14-
* Generate Test Coverage Files
5+
Coverage data excludes Apple's SDKs, and the exclusion rules can be customized.
156

167

178
Installation: Standard
189
======================
1910

20-
1. Fork this repository; you're probably going to want to make your own modifications.
11+
Use the standard installation if you want to customize XcodeCoverage to exclude certain files and directories, such as third-party libraries. Otherwise, the CocoaPods installation described below may be more convenient.
12+
13+
1. Fork this repository.
2114
2. Place the XcodeCoverage folder in the same folder as your Xcode project.
22-
5. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh`
15+
3. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh`
2316

2417
A few people have been tripped up by the last step: Make sure you add the script to your main target (your app or library), not your test target.
2518

@@ -44,16 +37,38 @@ The steps to install via CocoaPods:
4437
Again, make sure you add the script to your main target (your app or library), not your test target.
4538

4639

47-
Execution
48-
=========
40+
Xcode Project Setup
41+
===================
42+
43+
XcodeCoverage comes with an xcconfig file with the build settings required to instrument your code for coverage analysis.
44+
45+
If you already use an xcconfig, include it in the configuration you want to instrument:
46+
* Standard installation: `#include "XcodeCoverage/XcodeCoverage.xcconfig"`
47+
* CocoaPods installation: `#include "Pods/XcodeCoverage/XcodeCoverage.xcconfig"`
4948

50-
Immediately after installation, run your application at least once to generate the `env.sh` file, which will be placed at the same level as your `.xcodeproj` folder. This file should *not* be checked into version control, since it contains paths local to your machine.
49+
If you don't already use an xcconfig, drag XcodeCoverage.xcconfig into your project. Where it prompts "Add to targets," deselect all targets. (Otherwise, it will be included in the bundle.) Then click on your project in Xcode's Navigator pane, and select the Info tab. For the configuration you want to instrument, select XcodeCoverage.
5150

52-
Once that task has been completed, the process is very simple:
51+
If you'd rather specify the build settings by hand, enable these two settings at the project level:
52+
* Instrument Program Flow
53+
* Generate Test Coverage Files
54+
55+
Make sure not to instrument your AppStore release.
56+
57+
Execution
58+
=========
5359

5460
1. Run your unit tests.
5561
2. In Terminal, execute `getcov` in your project's XcodeCoverage folder.
5662

63+
`getcov` has the following command-line options:
64+
65+
* `--show` or `-s`: Show HTML report.
66+
* `--xml` or `-x`: Generate Cobertura XML.
67+
* `-o output_dir`: Specify output directory.
68+
* `-i info_file`: Specify name of generated lcov info file.
69+
* `-v`: Enable verbose output.
70+
* `-h` or `--help`: Show usage.
71+
5772
If you make changes to your test code without changing the production code and want a clean slate, use the `cleancov` script.
5873

5974
If you make changes to your production code, you should clear out all build artifacts before measuring code coverage again. "Clean Build Folder" by holding down the Option key in Xcode's "Product" menu, or by using the ⌥⇧⌘K key combination.
@@ -63,16 +78,14 @@ If you make changes to your production code, you should clear out all build arti
6378
* Edit Xcode scheme -> Test -> Post-actions
6479
* Set "Shell" to: `/bin/bash`
6580
* Set "Provide build settings from" to your main target
66-
* Set script to: `source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh`
81+
* Set script to `source XcodeCoverage/run_code_coverage_post.sh` for standard installation. For CocoaPods installation, use `source Pods/XcodeCoverage/run_code_coverage_post.sh`
6782

6883

6984
Modification
7085
============
7186

72-
There are two places you may want to modify the included files if you are using the standard installation:
87+
If you are using the standard installation, you can modify `exclude_data()` in `getcov` to specify which files to exclude, such as third-party libraries.
7388

74-
1. In `envcov.sh`, `LCOV_INFO` determines the name shown in the report.
75-
2. In `getcov`, edit `exclude_data()` to specify which files to exclude, for example, third-party libraries.
7689

7790
Credits
7891
=======

XcodeCoverage.podspec

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
Pod::Spec.new do |spec|
2-
spec.name = 'XcodeCoverage'
3-
spec.summary = 'Code coverage for Xcode projects'
4-
spec.version = '1.0.2'
5-
spec.platform = :ios
6-
spec.ios.deployment_target = '6.0'
7-
spec.authors = {'Jon Reid' => '[email protected]'}
8-
spec.homepage = 'https://github.com/jonreid/XcodeCoverage'
9-
spec.license = 'MIT'
10-
spec.source = {:git => 'https://github.com/jonreid/XcodeCoverage.git', :tag => "#{spec.version}"}
1+
Pod::Spec.new do |s|
2+
s.name = 'XcodeCoverage'
3+
s.version = '1.2.2'
4+
s.summary = 'Code coverage for Xcode projects'
5+
s.description = <<-DESC
6+
XcodeCoverage provides a simple way to generate reports of the code coverage
7+
of your Xcode project. Generated reports include HTML and Cobertura XML.
8+
9+
Coverage data excludes Apple's SDKs, and the exclusion rules can be customized.
10+
DESC
11+
s.homepage = 'https://github.com/jonreid/XcodeCoverage'
12+
s.license = 'MIT'
13+
s.author = {'Jon Reid' => '[email protected]'}
14+
s.social_media_url = 'https://twitter.com/qcoding'
15+
16+
s.ios.deployment_target = '6.0'
17+
s.osx.deployment_target = '10.8'
18+
s.source = {:git => 'https://github.com/jonreid/XcodeCoverage.git', :tag => 'v1.2.2'}
1119

12-
#these files will be brought into the filesystem, but not added to your .xcodeproj.
13-
spec.preserve_paths = 'cleancov', 'getcov', 'llvm-cov-wrapper.sh', 'envcov.sh', 'lcov-1.11/*', 'exportenv.sh', 'run_code_coverage_post.sh'
14-
15-
spec.requires_arc = true
16-
end
20+
# XcodeCoverage files will be brought into the filesystem, but not added to your .xcodeproj.
21+
s.preserve_paths = '*', '**'
22+
end

XcodeCoverage.xcconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// XcodeCoverage by Jon Reid, http://qualitycoding.org/about/
2+
// Source: https://github.com/jonreid/XcodeCoverage
3+
4+
GCC_GENERATE_TEST_COVERAGE_FILES = YES
5+
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES

cleancov

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
3-
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt
3+
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt
44

5-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6-
source ${DIR}/envcov.sh
5+
scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
source "${scripts}/envcov.sh"
77

88
LCOV --zerocounters -d "${OBJ_DIR}"

envcov.sh

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
#!/bin/bash
2-
#
32
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
4-
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt
3+
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt
54

6-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7-
ENV_DIR="${DIR}"
5+
scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
source "${scripts}/env.sh"
87

9-
if [[ "$DIR" == *Pods/XcodeCoverage* ]]
10-
then
11-
echo "Using Cocoapods!"
12-
cd "${DIR}"
13-
cd ..
14-
cd ..
15-
16-
#The env.sh file will be in the project root.
17-
ENV_DIR="$(pwd)"
18-
fi
19-
20-
source "${ENV_DIR}/env.sh"
21-
22-
# Change the report name if you like:
23-
LCOV_INFO=Coverage.info
24-
25-
XCODECOVERAGE_PATH="${SRCROOT}/XcodeCoverage"
26-
27-
if [[ "$DIR" == *Pods/XcodeCoverage* ]]
28-
then
29-
echo "Using Cocoapods!"
30-
#The current directory will be where XcodeCoverage is living, not in SRCROOT
31-
XCODECOVERAGE_PATH="${DIR}"
32-
fi
33-
34-
LCOV_PATH="${XCODECOVERAGE_PATH}/lcov-1.11/bin"
8+
LCOV_PATH="${scripts}/lcov-1.11/bin"
359
OBJ_DIR="${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}"
3610

37-
# Fix for the new LLVM-COV that requires gcov to have a -v paramter
11+
# Fix for the new LLVM-COV that requires gcov to have a -v parameter
3812
LCOV() {
39-
"${LCOV_PATH}/lcov" "$@" --gcov-tool "${XCODECOVERAGE_PATH}/llvm-cov-wrapper.sh"
13+
"${LCOV_PATH}/lcov" "$@" --gcov-tool "${scripts}/llvm-cov-wrapper.sh"
4014
}

exportenv.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
2-
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt
2+
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt
33

4-
DIR="${SRCROOT}"
5-
export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > ${DIR}/env.sh
4+
scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > "${scripts}/env.sh"

0 commit comments

Comments
 (0)