-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest-coverage.sh
More file actions
executable file
·32 lines (26 loc) · 1.02 KB
/
test-coverage.sh
File metadata and controls
executable file
·32 lines (26 loc) · 1.02 KB
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
#!/bin/bash
set -e
# 1. Run tests with code coverage enabled
echo "Running tests with code coverage..."
swift package clean && swift build && swift test --enable-code-coverage
# 2. Find the test binary and coverage data
BINARY_PATH=$(find .build -type f -name BetterBlueKitPackageTests -print -quit)
PROFDATA_PATH=$(find .build -type f -name default.profdata -print -quit)
if [[ -z "$BINARY_PATH" || -z "$PROFDATA_PATH" ]]; then
echo "❌ Could not find test binary or coverage data."
exit 1
fi
# 3. Print a human-readable coverage summary
echo
echo "===================="
echo "Code Coverage Report"
echo "===================="
xcrun llvm-cov report "$BINARY_PATH" -instr-profile="$PROFDATA_PATH"
# 4. (Optional) Generate HTML report
if [[ "$1" == "--html" ]]; then
OUTDIR="coverage-html"
echo
echo "Generating HTML coverage report in $OUTDIR/ ..."
xcrun llvm-cov show "$BINARY_PATH" -instr-profile="$PROFDATA_PATH" -format=html -output-dir="$OUTDIR"
echo "Open $OUTDIR/index.html in your browser to view the report."
fi