Skip to content

Commit

Permalink
Add function to show and export coverage (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nef10 authored Aug 20, 2022
1 parent e4063c6 commit 27730bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ The tool can be installed via brew: `brew install Nef10/tap/swift-test-coverage`

## Usage

Just call `swift test-coverage` from a folder within you swift package.
Just call `swift test-coverage` from a folder within your swift package to see a report with the coverage percentage of the different files.

Call `swift test-coverage show` to aditionally print the coverage of the individual lines or `swift test-coverage export` to export it to an HTML file. The last two options take an optional argument of the relative or absolute filepath to limit printing/exporting the line coverage to this specific file.
16 changes: 15 additions & 1 deletion swift-test-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ echo ""
BIN="$(swift build --show-bin-path)"
FILE="$(find "${BIN}" -name '*.xctest')"
COV="$(dirname "$(which swift)")/llvm-cov"
COMMAND="report"
PIPE=false

if [[ "$OSTYPE" == "darwin"* ]]; then
FILE=""${FILE}"/Contents/MacOS/$(basename "$FILE" .xctest)"
Expand All @@ -25,4 +27,16 @@ 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
if [[ "$1" == "show" ]]; then
COMMAND="show"
elif [[ "$1" == "export" ]]; then
COMMAND="show"
ARGS="${ARGS}--format=html "
PIPE=true
fi

if [ "$PIPE" = true ] ; then
"$COV" "$COMMAND" "${FILE}" -instr-profile="${BIN}/codecov/default.profdata" -ignore-filename-regex=".build|Tests" $ARGS $2 > coverage.html
else
"$COV" "$COMMAND" "${FILE}" -instr-profile="${BIN}/codecov/default.profdata" -ignore-filename-regex=".build|Tests" $ARGS $2
fi

0 comments on commit 27730bb

Please sign in to comment.