Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore test coverage for specified files #79

Open
screwyprof opened this issue Jul 20, 2022 · 2 comments
Open

Ignore test coverage for specified files #79

screwyprof opened this issue Jul 20, 2022 · 2 comments

Comments

@screwyprof
Copy link

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.

@mfridman
Copy link
Owner

mfridman commented Jul 29, 2022

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  │
└───────────────────────────────────────────────────────────┘

@screwyprof
Copy link
Author

screwyprof commented Jul 29, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants