refactor(coverage): centralize test coverage logic #14

Merged
eleith merged 1 commits from gemini/feature/coverage-script-refactor into main 2025-07-24 14:23:33 +00:00
3 changed files with 28 additions and 6 deletions

No files matched your search

+3 -4
View File
@@ -1,5 +1,5 @@
build:
go build -mod=vendor -o miniflux-digest .
go build -mod=vendor -o miniflux-digest ./cmd/miniflux-digest
preview-html:
go run -mod=vendor ./scripts/preview-html/main.go
@@ -9,11 +9,10 @@ preview-miniflux-email:
go run -mod=vendor ./scripts/preview-miniflux-email/main.go
test:
go test -mod=vendor ./...
go test -mod=vendor ./... ./cmd/miniflux-digest
test-coverage:
go test -mod=vendor -coverprofile=coverage.out ./...
@go tool cover -func=coverage.out
./scripts/check-coverage.sh 60
lint:
golangci-lint run
+6 -2
View File
@@ -9,7 +9,11 @@ fi
COVERAGE_THRESHOLD=$1
go test -mod=vendor -coverprofile=coverage.out ./...
EXCLUDED_PACKAGES="miniflux-digest/internal/testutil miniflux-digest/scripts"
COVERAGE_PACKAGES=$(./scripts/list-packages.sh $EXCLUDED_PACKAGES)
go test -mod=vendor -coverprofile=coverage.out -coverpkg=$COVERAGE_PACKAGES ./... ./cmd/miniflux-digest
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
@@ -25,4 +29,4 @@ if awk -v cov="$COVERAGE" -v min="$COVERAGE_THRESHOLD" 'BEGIN {exit (cov < min)}
else
echo "Error: Test coverage is below the ${COVERAGE_THRESHOLD}% threshold."
exit 1
fi
fi
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
# This script generates a comma-separated list of Go packages to include in coverage.
# It excludes packages matching patterns provided as arguments.
EXCLUDE_PATTERNS=""
# Add any additional exclusion patterns from arguments
for arg in "$@"; do
EXCLUDE_PATTERNS="${EXCLUDE_PATTERNS} ${arg}"
done
PACKAGE_LIST=$(go list ./...)
for pattern in ${EXCLUDE_PATTERNS}; do
PACKAGE_LIST=$(echo "${PACKAGE_LIST}" | grep -v "${pattern}")
done
echo "${PACKAGE_LIST}" | paste -sd, -