Skip to content

Commit eaee66e

Browse files
denischilikDenis Chilik
andauthored
Add scripts to analyze project test coverage (#388)
Co-authored-by: Denis Chilik <[email protected]>
1 parent de374ae commit eaee66e

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

Scripts/check_coverage.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import sys
2+
import json
3+
import os
4+
5+
6+
files_to_check = set()
7+
8+
COVERAGE_THRESHOLD=90
9+
10+
IGNORED_PATHS = [
11+
"UnitTests"
12+
]
13+
14+
GREEN = "\033[92m"
15+
RED = "\033[91m"
16+
RESET = "\033[0m"
17+
18+
def is_ignored(path):
19+
for ignore in IGNORED_PATHS:
20+
if ignore in path:
21+
return True
22+
23+
return False
24+
25+
with open("./build/coverage.json") as f:
26+
data = json.load(f)
27+
28+
failed_files = []
29+
30+
def matched_file_list(full_path):
31+
return any(full_path.endwith(check_path) for check_path in files_to_check)
32+
33+
for target in data.get("targets", []):
34+
for file in target.get("files", []):
35+
path = file.get("path", file["name"])
36+
37+
if files_to_check and not matched_file_list(path):
38+
continue
39+
40+
if is_ignored(path):
41+
continue
42+
43+
coverage = file.get("lineCoverage", 0) * 100
44+
45+
if coverage == 100:
46+
color = GREEN
47+
continue
48+
elif coverage >= COVERAGE_THRESHOLD:
49+
color = GREEN
50+
else:
51+
color = RED
52+
failed_files.append((path, coverage))
53+
54+
print(f"{color}{path}: {coverage:.3f}%{RESET}")

Scripts/check_coverage.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SCHEME="mParticle-Apple-SDK"
2+
DESTINATION="platform=iOS Simulator,name=iPhone 16 Pro,OS=latest"
3+
RESULT_BUNDLE_PATH="./build/TestResults.xcresult"
4+
5+
rm -rf "$RESULT_BUNDLE_PATH"
6+
7+
xcodebuild test \
8+
-project ../mParticle-Apple-SDK.xcodeproj \
9+
-scheme "$SCHEME" \
10+
-destination "$DESTINATION" \
11+
-enableCodeCoverage YES \
12+
-resultBundlePath "$RESULT_BUNDLE_PATH" \
13+
14+
xcrun xccov view --report --json "$RESULT_BUNDLE_PATH" > ./build/coverage.json
15+
16+
python3 check_coverage.py

0 commit comments

Comments
 (0)