From e4510404120e796798d5d2a3e2d62cce64ecdb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20K=C3=B6tte?= Date: Sat, 25 Sep 2021 23:12:07 -0700 Subject: [PATCH] Add script --- README.md | 3 ++- swift-test-coverage | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 swift-test-coverage diff --git a/README.md b/README.md index 2e0eeb3..5c59820 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/swift-test-coverage b/swift-test-coverage new file mode 100755 index 0000000..2d0a21a --- /dev/null +++ b/swift-test-coverage @@ -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