Skip to content

Commit

Permalink
Add script
Browse files Browse the repository at this point in the history
  • Loading branch information
Nef10 committed Sep 26, 2021
1 parent b000123 commit e451040
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# swift-test-coverage
Command Line Tool to display the test coverage of a swift package

Small Command Line Tool to display the test coverage of a swift package.
27 changes: 27 additions & 0 deletions swift-test-coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

swift test --enable-code-coverage
echo ""

BIN="$(swift build --show-bin-path)"
FILE="$(find ${BIN} -name '*.xctest')"
COV="$(dirname "$(which swift)")/llvm-cov"

if [[ "$OSTYPE" == "darwin"* ]]; then
FILE="${FILE}/Contents/MacOS/$(basename $FILE .xctest)"
if [[ ! -f "$COV" ]]; then
COV="$(xcrun -f llvm-cov)"
fi
fi

VERSION="$($COV --version | grep --only-matching "version [0-9]*" | cut -c 9-)"
ARGS=""

if [ "$VERSION" -gt "12" ]; then
ARGS="-show-branch-summary=0 "
fi
if [ -t 1 ] || [ "${GITHUB_ACTIONS}" = true ]; then
ARGS="${ARGS}--use-color "
fi

$COV report "${FILE}" -instr-profile="${BIN}/codecov/default.profdata" -ignore-filename-regex=".build|Tests" $ARGS

0 comments on commit e451040

Please sign in to comment.