Skip to content

Upstream Pull #7

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

Merged
merged 32 commits into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5f03479
Added command line parameters to getcov
taylesworth Oct 26, 2014
364ba13
Fixed issue with -i param
taylesworth Oct 30, 2014
99e8c2a
Merge pull request #29 from vokal/master
jonreid Mar 21, 2015
10bbde6
Merge branch 'add-getcov-params' of https://github.com/taylesworth/Xc…
jonreid Mar 21, 2015
c08c94f
Move location of generated env.sh back to XcodeCoverage folder.
jonreid Mar 21, 2015
a73b6c9
Use bash not sh
jonreid Mar 21, 2015
3bcb52e
Fix run_code_coverage_post.sh to not care about directory location, a…
jonreid Mar 21, 2015
951ec3b
run_code_coverage_post.sh: Lean toward Google shell style guide
jonreid Mar 21, 2015
cbe7595
llvm-cov-wrapper.sh: Lean toward Google shell style guide
jonreid Mar 21, 2015
c9bc663
exportenv.sh: Lean toward Google shell style guide
jonreid Mar 21, 2015
9433076
envcov.sh: Lean toward Google shell style guide
jonreid Mar 21, 2015
38c0f6a
envcov.sh: Remove unused environment var
jonreid Mar 21, 2015
8d53427
cleancov: Lean toward Google shell style guide
jonreid Mar 21, 2015
d572a29
getcov: Lean toward Google shell style guide
jonreid Mar 21, 2015
05e309b
Move definition of LCOV_INFO to getcov, where it can now be changed w…
jonreid Mar 21, 2015
bcb2d66
getcov: Pull body of script into main function
jonreid Mar 21, 2015
fa1393d
getcov: Add -x arg for generating Cobertura XML. Lean toward style gu…
jonreid Mar 21, 2015
314363b
Document getcov arguments
jonreid Mar 21, 2015
4aebe74
Rework podspec to match others I own
jonreid Mar 21, 2015
2d288ce
Add changelog
jonreid Mar 22, 2015
ab08e2d
Tweak changelog
jonreid Mar 22, 2015
a4701fe
Remove executable bit on sub-scripts
jonreid Mar 22, 2015
162da31
Bump copyright year
jonreid Mar 22, 2015
d9f68f7
Add xcconfig
jonreid Mar 22, 2015
36a5682
readme tweak
jonreid Mar 22, 2015
26fb7a5
Add xcconfig to changelog
jonreid Mar 22, 2015
43def52
No, exportenv.sh needs +x to run directly
jonreid Mar 22, 2015
7dcf721
Argh, llvm-cov-wrapper.sh really needs +x too
jonreid Mar 22, 2015
b27e006
Release v1.2.0
jonreid Mar 22, 2015
a8f71dd
Update podspec to 1.2.0, and update readme
jonreid Mar 22, 2015
7ba0dc7
1.2.0 podspec was missing xcconfig. Just preserve all files.
jonreid Mar 22, 2015
1377a4d
Correct name of XcodeCoverage.xcconfig
jonreid Mar 22, 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
44 changes: 44 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Version 1.2.2
-------------
_22 Mar 2015_

* Add `getcov` command line parameters, making it easier to use XcodeCoverage in continuous integration. _Thanks to: Tom Aylesworth_
* Add Cobertura XML generation. _Thanks to: Ellen Shapiro_
* Support use as CocoaPod. _Thanks to: Ellen Shapiro_
* Update to lcov 1.11. _Thanks to: Ellen Shapiro_
* Add XcodeCoverage.xcconfig for simple project setup.


Version 1.1.1
-------------
_13 Nov 2014_

* Exclude "Developer/SDKs" instead of "Applications/Xcode.app" so that people can use multiple versions of Xcode. _Thanks to: Cédric Luthi_
* Quote arguments to support built products directory containing spaces. _Thanks to: Cédric Luthi_
* Fix functionality optional post-test dialog in other locales by forcing buttons to be in English.


Version 1.1.0
-------------
_30 Mar 2014_

* Support Xcode 5.1. _Thanks to: Mike Maietta_
* Add optional post-test script `run_code_coverage_post.sh` to prompt whether to generate coverage report. _Thanks to: Matthew Purland_
* Improve function coverage by specifying `--derive-func-data`. _Thanks to: jstevenco_
* Directly include copy of lcov 1.10.


Version 1.0.1
-------------
_09 Mar 2014_

* Fix: Use `CURRENT_ARCH` instead of `NATIVE_ARCH`. _Thanks to: Scott Densmore_
* Improve scripts so they can be run from any working directory.
* Export `OBJROOT` so that customizations can include subprojects.


Version 1.0.0
-------------
_01 Dec 2012_

* Initial release
2 changes: 1 addition & 1 deletion LICENSE.txt
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
Copyright 2015 Jonathan M. Reid

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
![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.
XcodeCoverage provides a simple way to generate reports of the code coverage of your Xcode project. Generated reports include HTML and Cobertura XML.


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
Coverage data excludes Apple's SDKs, and the exclusion rules can be customized.


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

1. Fork this repository; you're probably going to want to make your own modifications.
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.

1. Fork this repository.
2. Place the XcodeCoverage folder in the same folder as your Xcode project.
5. In your main target, add a Run Script build phase to execute `XcodeCoverage/exportenv.sh`
3. 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.

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


Execution
=========
Xcode Project Setup
===================

XcodeCoverage comes with an xcconfig file with the build settings required to instrument your code for coverage analysis.

If you already use an xcconfig, include it in the configuration you want to instrument:
* Standard installation: `#include "XcodeCoverage/XcodeCoverage.xcconfig"`
* CocoaPods installation: `#include "Pods/XcodeCoverage/XcodeCoverage.xcconfig"`

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

Once that task has been completed, the process is very simple:
If you'd rather specify the build settings by hand, enable these two settings at the project level:
* Instrument Program Flow
* Generate Test Coverage Files

Make sure not to instrument your AppStore release.

Execution
=========

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

`getcov` has the following command-line options:

* `--show` or `-s`: Show HTML report.
* `--xml` or `-x`: Generate Cobertura XML.
* `-o output_dir`: Specify output directory.
* `-i info_file`: Specify name of generated lcov info file.
* `-v`: Enable verbose output.
* `-h` or `--help`: Show usage.

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, or by using the ⌥⇧⌘K key combination.
Expand All @@ -63,16 +78,14 @@ If you make changes to your production code, you should clear out all build arti
* Edit Xcode scheme -> Test -> Post-actions
* 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 XcodeCoverage/run_code_coverage_post.sh` for standard installation. For CocoaPods installation, use `source Pods/XcodeCoverage/run_code_coverage_post.sh`


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

There are two places you may want to modify the included files if you are using the standard installation:
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.

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
=======
Expand Down
36 changes: 21 additions & 15 deletions XcodeCoverage.podspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
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' => '[email protected]'}
spec.homepage = 'https://github.com/jonreid/XcodeCoverage'
spec.license = 'MIT'
spec.source = {:git => 'https://github.com/jonreid/XcodeCoverage.git', :tag => "#{spec.version}"}
Pod::Spec.new do |s|
s.name = 'XcodeCoverage'
s.version = '1.2.2'
s.summary = 'Code coverage for Xcode projects'
s.description = <<-DESC
XcodeCoverage provides a simple way to generate reports of the code coverage
of your Xcode project. Generated reports include HTML and Cobertura XML.

Coverage data excludes Apple's SDKs, and the exclusion rules can be customized.
DESC
s.homepage = 'https://github.com/jonreid/XcodeCoverage'
s.license = 'MIT'
s.author = {'Jon Reid' => '[email protected]'}
s.social_media_url = 'https://twitter.com/qcoding'

s.ios.deployment_target = '6.0'
s.osx.deployment_target = '10.8'
s.source = {:git => 'https://github.com/jonreid/XcodeCoverage.git', :tag => 'v1.2.2'}

#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
# XcodeCoverage files will be brought into the filesystem, but not added to your .xcodeproj.
s.preserve_paths = '*', '**'
end
5 changes: 5 additions & 0 deletions XcodeCoverage.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// XcodeCoverage by Jon Reid, http://qualitycoding.org/about/
// Source: https://github.com/jonreid/XcodeCoverage

GCC_GENERATE_TEST_COVERAGE_FILES = YES
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES
8 changes: 4 additions & 4 deletions cleancov
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
#!/bin/bash
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt

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

LCOV --zerocounters -d "${OBJ_DIR}"
38 changes: 6 additions & 32 deletions envcov.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
#!/bin/bash
#
# XcodeCoverage by Jon Reid, http://qualitycoding/about/
# Copyright 2014 Jonathan M. Reid. See LICENSE.txt
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt

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

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"

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"
LCOV_PATH="${scripts}/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
# Fix for the new LLVM-COV that requires gcov to have a -v parameter
LCOV() {
"${LCOV_PATH}/lcov" "$@" --gcov-tool "${XCODECOVERAGE_PATH}/llvm-cov-wrapper.sh"
"${LCOV_PATH}/lcov" "$@" --gcov-tool "${scripts}/llvm-cov-wrapper.sh"
}
6 changes: 3 additions & 3 deletions 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
# Copyright 2015 Jonathan M. Reid. See LICENSE.txt

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