mfridman/tparse

Ignore test coverage for specified files

screwyprof opened this issue · 2 comments

At the moment tparse shows a nice table with cover column, which is really cool. It would be even better if it was possible to specify an exclusion list for files and/or directories to ignore.

I think the best we can do is exclude packages. Is this what you're looking for?

Although at this point you're better off using the native Go tooling to target specific tests. Otherwise you'd be running tests and then excluding them.

Example:

$ go test -count=1 -json fmt strings | tparse             
┌───────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │ PACKAGE │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼─────────┼───────┼──────┼──────┼───────│
│  PASS   │ 0.21s   │ fmt     │ 0.0%  │   75 │    0 │    1  │
│  PASS   │ 0.80s   │ strings │ 0.0%  │  115 │    0 │    0  │
└───────────────────────────────────────────────────────────┘

And with an -exclude flag

$ go test -count=1 -json fmt strings | tparse -exclude fmt
┌───────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │ PACKAGE │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼─────────┼───────┼──────┼──────┼───────│
│  PASS   │ 0.79s   │ strings │ 0.0%  │  115 │    0 │    0  │
└───────────────────────────────────────────────────────────┘

That's not exactly what I meant. Let me explain. Golang doesn't allow to ignore some certain files or folders by default. For example I'd like to ignore some auto-generated files, or or some test utils, etc... One of the ways it can be done is to check the cover.out and grep -v the files/folders to ignore. Let me show you an example of a Makefile:

IGNORE_COVERAGE_FOR=-e .*_gen.go -e backend-server.go -e  backend-types.go -e internal -e test_helpers.go -e .*test

test-all:
	@echo -e "$(OK_COLOR)==> Running tests$(NO_COLOR)"
	set -euo pipefail && go test -tags="integration" -v -race -count=1 -timeout=180s -cover -covermode atomic -coverprofile=coverage.tmp -coverpkg=./... ./... | tee junit.out
	@set -euo pipefail && cat coverage.tmp | grep -v $(IGNORE_COVERAGE_FOR) > coverage.out && rm coverage.tmp

test-pretty: ## run unit and integration tests with prety console output
	@echo -e "$(OK_COLOR)==> Running tests$(NO_COLOR)"
	@set -euo pipefail && go test -json -tags=integration -v -race -count=1 -timeout=120s -cover -covermode atomic ./... | tparse

In this example test-all target runs tests with code coverage and the coverage profile is set to -coverprofile=coverage.tmp If it was possible to do something similar with tparse, then we would get exactly what I meant.

UPD: I don't really want to ignore the whole package, but some files inside.