summaryrefslogtreecommitdiff
path: root/scripts/collect-coverage.sh
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-02-17 12:43:04 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-02-18 15:01:58 +0200
commitcdfe4e46aaae7e720dbf7b6626f1a80e81de4a7e (patch)
tree5e83505993ad40468b0df929ee858c6a1e741203 /scripts/collect-coverage.sh
parentec97264431a3b29327332072b5328d81768547c9 (diff)
downloadqtlocation-mapboxgl-cdfe4e46aaae7e720dbf7b6626f1a80e81de4a7e.tar.gz
[tests] Added coverage report target 'check'
Issuing 'make check' now collects unit tests coverage data and generates a report in HTML.
Diffstat (limited to 'scripts/collect-coverage.sh')
-rwxr-xr-xscripts/collect-coverage.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/collect-coverage.sh b/scripts/collect-coverage.sh
new file mode 100755
index 0000000000..65f96a0b2b
--- /dev/null
+++ b/scripts/collect-coverage.sh
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+
+set -e
+set -o pipefail
+
+function usage() {
+ echo "Error: LCOV and genhtml are required for generating coverage reports."
+ if [ `uname -s` = 'Linux' ]; then
+ echo "On Debian-based distros, you can install them via 'apt-get install lcov'"
+ elif [ `uname -s` = 'Darwin' ]; then
+ echo "On OS X, you can install them via 'brew install lcov'"
+ fi
+ exit 1
+}
+
+command -v lcov >/dev/null 2>&1 || usage
+command -v genhtml >/dev/null 2>&1 || usage
+
+# Zero coverage counters
+lcov \
+ --quiet \
+ --zerocounters \
+ --directory "build/${HOST_SLUG}/${BUILDTYPE}" \
+ --output-file "build/${HOST_SLUG}/${BUILDTYPE}/coverage.info" \
+ >/dev/null 2>&1
+
+# Run all unit tests
+./scripts/run_tests.sh "build/${HOST_SLUG}/${BUILDTYPE}/test"
+
+# Collect coverage data and save it into coverage.info
+echo "Collecting coverage data..."
+lcov \
+ --quiet \
+ --capture \
+ --no-external \
+ --directory "src/mbgl" \
+ --directory "platform" \
+ --directory "include/mbgl" \
+ --directory "build/${HOST_SLUG}/${BUILDTYPE}" \
+ --base-directory "build/${HOST_SLUG}/${BUILDTYPE}" \
+ --output-file "build/${HOST_SLUG}/${BUILDTYPE}/coverage.info" \
+ >/dev/null 2>&1
+
+# Generate HTML report based on coverage.info
+echo "Generating HTML report..."
+genhtml \
+ --quiet \
+ --show-details \
+ --keep-descriptions \
+ --function-coverage \
+ --no-branch-coverage \
+ --title "Mapbox GL Native" \
+ --num-spaces 4 \
+ --sort \
+ --demangle-cpp \
+ --prefix $(pwd -P) \
+ --output-directory "build/${HOST_SLUG}/${BUILDTYPE}/coverage" \
+ "build/${HOST_SLUG}/${BUILDTYPE}/coverage.info" \
+ >/dev/null 2>&1
+
+echo "Coverage report is now available in build/${HOST_SLUG}/${BUILDTYPE}/coverage/index.html"