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

feat: add coverage scripts #15018

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ report

# plan test output
/go/vt/vtgate/planbuilder/testdata/plan_test*

# coverage output
coverage.out
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,23 @@ generate-flag-testdata:

install_kubectl_kind:
./tools/get_kubectl_kind.sh



# Scripts related to test coverage
PACKAGE ?= ./go/...

coverage:
go install golang.org/x/tools/cmd/cover
go test -coverprofile=coverage.out $(PACKAGE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, but I often find myself using the -v flag too as it helps find failing tests. Might be worth adding

go tool cover -html=coverage.out
Comment on lines +432 to +435
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels very similar to the already existing unit_test_cover Makefile target. The following snippet is going to be important is testing the sqlparser package:

# Handle go tool cover failures due to not handling `//line` directives, which
# the goyacc compiler adds to the generated parser in sql.go. See:
# https://github.com/golang/go/issues/41222
sed -i'' -e '/^vitess.io\/vitess\/go\/vt\/sqlparser\/yaccpar/d' coverage.out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh got it. Should I rename the same to test.coverage to avoid the target conflict?


coverage-clean:
rm -f coverage.out

coverage-help:
@echo "Usage: make [OPTIONS] coverage"
@echo "Options:"
@echo " PACKAGE=<name> Specify the package to test (default: $(PACKAGE))"
@echo " coverage Run tests and generate coverage report"
@echo " coverage-clean Clean up generated files"
Loading