From 05dcca8ead5fa010d2cb9653ff4d5302a9b60be6 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Mon, 18 Mar 2013 00:45:28 +0100 Subject: [PATCH] Add code coverage Yeah, coverage is poor right now. I know I know... --- Support/HockeySDK.xcodeproj/project.pbxproj | 16 ++++++ Vendor/XcodeCoverage/.gitignore | 2 + Vendor/XcodeCoverage/LICENSE.txt | 21 +++++++ Vendor/XcodeCoverage/README.md | 62 +++++++++++++++++++++ Vendor/XcodeCoverage/cleancov | 10 ++++ Vendor/XcodeCoverage/envcov.sh | 14 +++++ Vendor/XcodeCoverage/exportenv.sh | 7 +++ Vendor/XcodeCoverage/getcov | 48 ++++++++++++++++ 8 files changed, 180 insertions(+) create mode 100755 Vendor/XcodeCoverage/.gitignore create mode 100755 Vendor/XcodeCoverage/LICENSE.txt create mode 100755 Vendor/XcodeCoverage/README.md create mode 100755 Vendor/XcodeCoverage/cleancov create mode 100755 Vendor/XcodeCoverage/envcov.sh create mode 100755 Vendor/XcodeCoverage/exportenv.sh create mode 100755 Vendor/XcodeCoverage/getcov diff --git a/Support/HockeySDK.xcodeproj/project.pbxproj b/Support/HockeySDK.xcodeproj/project.pbxproj index 8dc22540b0..d9e66ca9ab 100644 --- a/Support/HockeySDK.xcodeproj/project.pbxproj +++ b/Support/HockeySDK.xcodeproj/project.pbxproj @@ -594,6 +594,7 @@ 1E5954CC15B6F24A00A03429 /* Sources */, 1E5954DB15B6F24A00A03429 /* Frameworks */, 1E59558B15B6FD8800A03429 /* Headers */, + 1EE9071A16F6871F003DDE1D /* ShellScript */, ); buildRules = ( ); @@ -771,6 +772,19 @@ shellPath = /bin/sh; shellScript = "/usr/local/bin/appledoc \\\n --output \"${SOURCE_ROOT}/../documentation\" \\\n --ignore Vendor \\\n --ignore Products \\\n --ignore .m \\\n --create-html \\\n --create-docset \\\n --install-docset \\\n --keep-intermediate-files \\\n --project-name \"${HOCKEYSDK_DOCSET_NAME} ${VERSION_STRING}\" \\\n --project-version \"${VERSION_STRING}\" \\\n --project-company \"BitStadium GmbH\" \\\n --company-id \"de.bitstadium\" \\\n --docset-bundle-name \"${HOCKEYSDK_DOCSET_NAME} ${VERSION_STRING}\" \\\n --docset-feed-name \"${HOCKEYSDK_DOCSET_NAME}\" \\\n --docset-desc \"\" \\\n --docset-platform-family \"iphoneos\" \\\n --index-desc \"${SOURCE_ROOT}/../docs/index.md\" \\\n --include \"${SOURCE_ROOT}/../docs/index.html\" \\\n --include \"${SOURCE_ROOT}/../docs/\" \\\n --merge-categories \\\n --no-repeat-first-par \\\n --warn-undocumented-object \\\n --warn-undocumented-member \\\n --warn-empty-description \\\n --warn-unknown-directive \\\n --warn-invalid-crossref \\\n --warn-missing-arg \\\n --logformat xcode \\\n --exit-threshold 2 \\\n \"${SOURCE_ROOT}/../\"\n"; }; + 1EE9071A16F6871F003DDE1D /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/../Vendor/XcodeCoverage/exportenv.sh\""; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -1039,6 +1053,8 @@ DEAD_CODE_STRIPPING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_GENERATE_TEST_COVERAGE_FILES = YES; + GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "BITHOCKEY_STATIC_LIBRARY=1", diff --git a/Vendor/XcodeCoverage/.gitignore b/Vendor/XcodeCoverage/.gitignore new file mode 100755 index 0000000000..c61ec5d04a --- /dev/null +++ b/Vendor/XcodeCoverage/.gitignore @@ -0,0 +1,2 @@ +env.sh +lcov-* diff --git a/Vendor/XcodeCoverage/LICENSE.txt b/Vendor/XcodeCoverage/LICENSE.txt new file mode 100755 index 0000000000..3e396ae65c --- /dev/null +++ b/Vendor/XcodeCoverage/LICENSE.txt @@ -0,0 +1,21 @@ +Copyright 2012 Jonathan M. Reid +All rights reserved. + +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 +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT License) diff --git a/Vendor/XcodeCoverage/README.md b/Vendor/XcodeCoverage/README.md new file mode 100755 index 0000000000..f34cb776f2 --- /dev/null +++ b/Vendor/XcodeCoverage/README.md @@ -0,0 +1,62 @@ +These scripts provide a simple way to generate HTML reports of the code coverage +of your Xcode 4.5 project. +For a detailed blog post, see http://qualitycoding.org/xcode-code-coverage/ + + +Installation +============ + +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. [Dowload lcov-1.10](http://downloads.sourceforge.net/ltp/lcov-1.10.tar.gz). +Place the lcov-1.10 folder inside the XcodeCoverage folder. +4. Get Xcode's coverage instrumentation by going to Xcode Preferences, into Downloads, and installing Command Line Tools. +5. 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 +6. 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. + + +Execution +========= + +1. Run your unit tests +2. In Terminal, cd to your project's XcodeCoverage folder, then + + $ ./getcov + +If you make changes to your test code without changing the production code and +want a clean slate, use the ``cleancov`` script: + + $ ./cleancov + +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. + + +Modification +============ + +There are two places you may want to modify: + +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. + + +More resources +============== + +* [Sources](https://github.com/jonreid/XcodeCoverage) +* Testing tools: [OCHamcrest](https://github.com/hamcrest/OCHamcrest), +[OCMockito](https://github.com/jonreid/OCMockito), +[JMRTestTools](https://github.com/jonreid/JMRTestTools) +* [Quality Coding](http://qualitycoding.org/) blog - Tools, tips & techniques +for _building quality in_ to iOS development diff --git a/Vendor/XcodeCoverage/cleancov b/Vendor/XcodeCoverage/cleancov new file mode 100755 index 0000000000..1130af9d13 --- /dev/null +++ b/Vendor/XcodeCoverage/cleancov @@ -0,0 +1,10 @@ +#!/bin/sh +# +# Copyright 2012 Jonathan M. Reid. See LICENSE.txt +# Created by: Jon Reid, http://qualitycoding.org/ +# Source: https://github.com/jonreid/XcodeCoverage +# + +source envcov.sh + +"${LCOV}" --zerocounters -d "${OBJ_DIR}" diff --git a/Vendor/XcodeCoverage/envcov.sh b/Vendor/XcodeCoverage/envcov.sh new file mode 100755 index 0000000000..b48d4b7e01 --- /dev/null +++ b/Vendor/XcodeCoverage/envcov.sh @@ -0,0 +1,14 @@ +# +# Copyright 2012 Jonathan M. Reid. See LICENSE.txt +# Created by: Jon Reid, http://qualitycoding.org/ +# Source: https://github.com/jonreid/XcodeCoverage +# + +source env.sh + +# Change the report name if you like: +LCOV_INFO=Coverage.info + +LCOV_PATH=${SRCROOT}/../Vendor/XcodeCoverage/lcov-1.10/bin +LCOV=${LCOV_PATH}/lcov +OBJ_DIR=${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH} diff --git a/Vendor/XcodeCoverage/exportenv.sh b/Vendor/XcodeCoverage/exportenv.sh new file mode 100755 index 0000000000..32455f9f48 --- /dev/null +++ b/Vendor/XcodeCoverage/exportenv.sh @@ -0,0 +1,7 @@ +# +# Copyright 2012 Jonathan M. Reid. See LICENSE.txt +# Created by: Jon Reid, http://qualitycoding.org/ +# Source: https://github.com/jonreid/XcodeCoverage +# + +export | egrep '( BUILT_PRODUCTS_DIR)|(CURRENT_ARCH)|(OBJECT_FILE_DIR_normal)|(SRCROOT)|(OBJROOT)' > ../Vendor/XcodeCoverage/env.sh diff --git a/Vendor/XcodeCoverage/getcov b/Vendor/XcodeCoverage/getcov new file mode 100755 index 0000000000..332aa8c053 --- /dev/null +++ b/Vendor/XcodeCoverage/getcov @@ -0,0 +1,48 @@ +#!/bin/sh +# +# Copyright 2012 Jonathan M. Reid. See LICENSE.txt +# Created by: Jon Reid, http://qualitycoding.org/ +# Source: https://github.com/jonreid/XcodeCoverage +# + +source envcov.sh + +remove_old_report() +{ + pushd ${BUILT_PRODUCTS_DIR} + if [ -e lcov ]; then + rm -r lcov + fi + popd +} + +enter_lcov_dir() +{ + cd ${BUILT_PRODUCTS_DIR} + mkdir lcov + cd lcov +} + +gather_coverage() +{ + "${LCOV}" --capture -b "${SRCROOT}" -d "${OBJ_DIR}" -o ${LCOV_INFO} +} + +exclude_data() +{ + "${LCOV}" --remove ${LCOV_INFO} "/Applications/Xcode.app/*" -d "${OBJ_DIR}" -o ${LCOV_INFO} + "${LCOV}" --remove ${LCOV_INFO} "main.m" -d "${OBJ_DIR}" -o ${LCOV_INFO} + # Remove other patterns here... +} + +generate_report() +{ + "${LCOV_PATH}/genhtml" --output-directory . ${LCOV_INFO} + open index.html +} + +remove_old_report +enter_lcov_dir +gather_coverage +exclude_data +generate_report