Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lcov 1.11 + CocoaPod + Cobertura #29

Merged
merged 26 commits into from
Mar 21, 2015
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
569c52a
Update to lcov 1.11
designatednerd Nov 20, 2014
348c63b
Add podspec.
designatednerd Nov 20, 2014
fcfa261
use SRCROOT to export.
designatednerd Nov 20, 2014
4fd2cdf
add getcov to podspec
designatednerd Nov 20, 2014
a530cb1
Add llvm-cov-wrapper to podspec
designatednerd Nov 20, 2014
fe57da8
Update envcov.sh to allow for CocoaPods use.
designatednerd Nov 20, 2014
b614d6e
Point podspec at actual repo, clarify comment.
designatednerd Nov 20, 2014
1e40d4b
README Updates
designatednerd Nov 21, 2014
ee8928d
Fix alignment and add keyboard shortcut for cleaning the build folder.
designatednerd Nov 21, 2014
70a5a38
Merge pull request #1 from designatednerd/master
designatednerd Nov 21, 2014
8c2d7ff
Update envcov.sh
barrault01 Nov 27, 2014
cb2cfad
Merge pull request #2 from barrault01/master
designatednerd Dec 1, 2014
3126ce1
Add Cobertura XML generation
designatednerd Dec 5, 2014
66cd8a0
Bump Podspec
designatednerd Dec 5, 2014
11f0898
Add license info.
designatednerd Dec 5, 2014
0f8190a
Whitespace silliness
designatednerd Dec 5, 2014
f454a35
Hey turns out I'm already in the lcov directory
designatednerd Dec 5, 2014
d46e758
Merge pull request #3 from designatednerd/master
Dec 5, 2014
2c19252
Quote ALL the paths.
designatednerd Feb 18, 2015
7b1d930
Bump podspec.
designatednerd Feb 18, 2015
aa7df10
Add escaped quotes to geninfo
designatednerd Feb 18, 2015
80dd422
Moar quotes!
designatednerd Feb 18, 2015
848eb29
More quote fixes, add bash specifier
designatednerd Mar 2, 2015
20b185c
Merge pull request #5 from designatednerd/master
designatednerd Mar 2, 2015
f3c6839
Merge branch 'jonreid-master' + fix merge conflict
designatednerd Mar 19, 2015
a25f4be
Merge pull request #6 from designatednerd/master
designatednerd Mar 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 55 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,81 @@
![XcodeCoverage](http://qualitycoding.org/jrwp/wp-content/uploads/2014/03/XcodeCoverage.png)

These scripts provide a simple way to generate HTML reports of the code coverage
of your Xcode project.
These scripts provide a simple way to generate HTML reports of the code coverage of your Xcode project.


Installation
============
Xcode Project Setup
===================

Before you get started, there are a couple of steps you will need to take to prepare your project:

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.
4. In your Xcode project, enable these two build settings at the project level for your Debug configuration only:
* Instrument Program Flow
* Generate Test Coverage Files


Installation: Standard
======================

1. Fork this repository; you're probably going to want to make your own
modifications.
1. Fork this repository; you're probably going to want to make your own modifications.
2. Place the XcodeCoverage folder in the same folder as your Xcode project.
3. 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.
4. In your Xcode project, enable these two build settings at the project level
for your Debug configuration only:
* Instrument Program Flow
* Generate Test Coverage Files
5. In your main target, add a Run Script build phase to execute
``XcodeCoverage/exportenv.sh``
5. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh`

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.


Installation: CocoaPods
=======================

A [CocoaPod](http://cocoapods.org/) has been added for convenient use in simple projects. There are a couple of things you should be aware of if you are using the CocoaPod instead of the standard method:

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.
- There will be no actual files added to your project. Files are only added through `preserve_paths`, so they will be available in your `Pods/XcodeCoverage` path, but you will not see them in Xcode, and they will not be compiled by Xcode.
- You will not be able to modify the scripts without those modifications being potentially overwritten by CocoaPods.

If those caveats are deal-breakers, please use the standard installation method above.

The steps to install via CocoaPods:

1. Add `pod 'XcodeCoverage', '~>1.0'` (or whatever [version specification](http://guides.cocoapods.org/using/the-podfile.html#specifying-pod-versions) you desire) to your Podfile.
2. Run `pod install`. This will download the necessary files.
3. In your main target, add a Run Script build phase to execute
`Pods/XcodeCoverage/exportenv.sh`.

Again, make sure you add the script to your main target (your app or library), not your test target.


Execution
=========

1. Run your unit tests
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.

Once that task has been completed, the process is very simple:

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

If you make changes to your test code without changing the production code and
want a clean slate, use the ``cleancov`` script.
If you make changes to your test code without changing the production code and want a clean slate, use the `cleancov` script.

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.
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.

**Optional:** XcodeCoverage can prompt to run code coverage after running unit tests:

* Edit Xcode scheme -> Test -> Post-actions
* Set "Shell" to: ``/bin/bash``
* Set "Shell" to: `/bin/bash`
* Set "Provide build settings from" to your main target
* Set script to:
``source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh``
* Set script to: `source ${SRCROOT}/XcodeCoverage/run_code_coverage_post.sh`


Modification
============

There are two places you may want to modify:
There are two places you may want to modify the included files if you are using the standard installation:

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

Credits
=======

The `lcov` -> Cobertura script is from [https://github.com/eriwen/lcov-to-cobertura-xml/](https://github.com/eriwen/lcov-to-cobertura-xml/) and is bound by [the license of that project](https://github.com/eriwen/lcov-to-cobertura-xml/blob/master/LICENSE.txt).

1. In envcov.sh, ``LCOV_INFO`` determines the name shown in the report.
2. In getcov, edit ``exclude_data()`` to specify which files to exclude, for
example, third-party libraries.
16 changes: 16 additions & 0 deletions XcodeCoverage.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pod::Spec.new do |spec|
spec.name = 'XcodeCoverage'
spec.summary = 'Code coverage for Xcode projects'
spec.version = '1.0.2'
spec.platform = :ios
spec.ios.deployment_target = '6.0'
spec.authors = {'Jon Reid' => 'jon@qualitycoding.org'}
spec.homepage = 'https://github.com/jonreid/XcodeCoverage'
spec.license = 'MIT'
spec.source = {:git => 'https://github.com/jonreid/XcodeCoverage.git', :tag => "#{spec.version}"}

#these files will be brought into the filesystem, but not added to your .xcodeproj.
spec.preserve_paths = 'cleancov', 'getcov', 'llvm-cov-wrapper.sh', 'envcov.sh', 'lcov-1.11/*', 'exportenv.sh', 'run_code_coverage_post.sh'

spec.requires_arc = true
end
31 changes: 27 additions & 4 deletions envcov.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
#!/bin/bash
#
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${DIR}/env.sh
ENV_DIR="${DIR}"

if [[ "$DIR" == *Pods/XcodeCoverage* ]]
then
echo "Using Cocoapods!"
cd "${DIR}"
cd ..
cd ..

#The env.sh file will be in the project root.
ENV_DIR="$(pwd)"
fi

source "${ENV_DIR}/env.sh"

# Change the report name if you like:
LCOV_INFO=Coverage.info

XCODECOVERAGE_PATH="${SRCROOT}/XcodeCoverage"
LCOV_PATH="${XCODECOVERAGE_PATH}/lcov-1.10/bin"
OBJ_DIR=${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}

if [[ "$DIR" == *Pods/XcodeCoverage* ]]
then
echo "Using Cocoapods!"
#The current directory will be where XcodeCoverage is living, not in SRCROOT
XCODECOVERAGE_PATH="${DIR}"
fi

LCOV_PATH="${XCODECOVERAGE_PATH}/lcov-1.11/bin"
OBJ_DIR="${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}"

# Fix for the new LLVM-COV that requires gcov to have a -v paramter
LCOV() {
${LCOV_PATH}/lcov "$@" --gcov-tool ${XCODECOVERAGE_PATH}/llvm-cov-wrapper.sh
"${LCOV_PATH}/lcov" "$@" --gcov-tool "${XCODECOVERAGE_PATH}/llvm-cov-wrapper.sh"
}
2 changes: 1 addition & 1 deletion exportenv.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR="${SRCROOT}"
export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > ${DIR}/env.sh
8 changes: 7 additions & 1 deletion getcov
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${DIR}/envcov.sh
source "${DIR}/envcov.sh"

remove_old_report()
{
@@ -33,6 +33,11 @@ exclude_data()
# Remove other patterns here...
}

generate_cobertura_xml()
{
python "${DIR}/lcov_cobertura.py" ${LCOV_INFO} --base-dir "${SRCROOT}" --output "coverage.xml"
}

generate_report()
{
"${LCOV_PATH}/genhtml" --output-directory . ${LCOV_INFO}
@@ -43,4 +48,5 @@ remove_old_report
enter_lcov_dir
gather_coverage
exclude_data
generate_cobertura_xml
generate_report
File renamed without changes.
Loading
Oops, something went wrong.