summaryrefslogtreecommitdiff
path: root/platform/ios/scripts/ios-code-coverage.sh
blob: 2d5094d3d515e29fa7fed761cee3c1675d6596ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash

set -e
set -o pipefail

#
# Get code coverage report, then convert it to JSON.
# The coverage reports end up in different locations based on whether coverage
# is generated via CI or locally.
#
cov_result="";
ls -l build/ios/ios/Logs/Test/
if [[ -d /build/ios/Logs/Test/*.xcresult ]]; then 
    cov_result=/build/ios/Logs/Test/*.xcresult
elif [[ -d /build/ios/ios/Logs/Test/*.xcresult ]]; then
    cov_result=/build/ios/ios/Logs/Test/*.xcresult
else
    echo "Coverage file does not exist. Please run tests before executing"
    exit 1
fi

xcrun xccov view $cov_result --json > output.json

#
# Convert the line coverage for the dynamic target to a percentage. Currently, 
# only CI tests are included when calculated code coverage.
# 
percentage=`node -e "console.log(require('./output.json').lineCoverage)"`
cov=$(printf "%.2f" $(echo "$percentage*100" | bc -l))

# Generate a formatted JSON file and upload it to S3.
# ./././scripts/code-coverage.sh $cov "iOS" "$1"