Skip to content

Commit

Permalink
Update coverage for xccov (lyft#137)
Browse files Browse the repository at this point in the history
* Update coverage for xccov

* Add python script instead of jq
  • Loading branch information
keith authored Apr 10, 2018
1 parent d6f6a84 commit c07df3d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
.LSOverride
build/
Carthage/Build
coverage.txt
DerivedData
Icon
run-tests
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:
env: ACTION=swiftpm-macOS

language: objective-c
osx_image: xcode9.3beta
osx_image: xcode9.3

script:
- make install-$ACTION && make test-$ACTION
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ test-coverage:
-enableCodeCoverage YES \
test \
| xcpretty -ct
rm -f coverage.txt
Resources/coverage.sh build
! grep -C 10 "^\s*0" coverage.txt

test-swiftpm-macOS:
swift test
17 changes: 14 additions & 3 deletions Resources/coverage.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/bin/bash

set -e
set -o pipefail
set -u

coverage_dir="$1"
profdata=$(find "$coverage_dir" -name "*.profdata" | head -1)
executable=$(find "$coverage_dir" -type f -name "Mapper" | head -1)
xcrun llvm-cov show -instr-profile "$profdata" "$executable" > "coverage.txt"
profdata="$(find "$coverage_dir" -name "*.xccovreport")"

result="$(xcrun xccov view \
--only-targets \
--json \
"$profdata" \
| python Resources/get-coverage.py Mapper.framework)"

if [ "$result" -ne "1" ]; then
echo "Coverage is $result, should be 1"
exit 1
fi
14 changes: 14 additions & 0 deletions Resources/get-coverage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import print_function
import json
import sys

module = sys.argv[1]
coverage = json.load(sys.stdin)
for blob in coverage:
if blob["name"] == module:
print(blob["lineCoverage"])
sys.exit(0)

print("Module '{}' not found in '{}'".format(module, json.dumps(coverage)),
file=sys.stderr)
sys.exit(1)

0 comments on commit c07df3d

Please sign in to comment.