diff --git a/README.md b/README.md index f350274..29c04d8 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/swift-test-coverage b/swift-test-coverage index e73cea8..00c2f61 100755 --- a/swift-test-coverage +++ b/swift-test-coverage @@ -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)" @@ -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