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

proposal: cmd/go: ignore empty functions in coverage report #69207

Open
abemedia opened this issue Sep 2, 2024 · 3 comments
Open

proposal: cmd/go: ignore empty functions in coverage report #69207

abemedia opened this issue Sep 2, 2024 · 3 comments
Labels
Milestone

Comments

@abemedia
Copy link

abemedia commented Sep 2, 2024

Proposal Details

A common way to implement union types in Go is with an interface e.g.

type Record struct {
	Title string
	Value valueType
}

type valueType interface {
	isValue()
}

type ValueFoo struct {
	Foo string
}

func (ValueFoo) isValue() {}

type ValueBar struct {
	Bar string
}

func (ValueBar) isValue() {}

This method is amongst others employed by protobuf. The problem is that these empty functions negatively affect coverage, so in projects where coverage is enforced it can lead to having to write nonsensical tests like this:

func TestValueType(*testing.T) {
	tests := []valueType{
		ValueFoo{},
		ValueBar{},
	}

	for _, tt := range tests {
		tt.isValue()
	}
}

To avoid this it would be great if empty functions were excluded from the coverage report.

@gopherbot gopherbot added this to the Proposal milestone Sep 2, 2024
@ianlancetaylor
Copy link
Contributor

I don't see how it would be correct in general to ignore empty functions. Some people will want coverage for them, some will not.

In general we don't aim for 100% coverage as a goal.

@seankhliao
Copy link
Member

#46825 looks like the opposite case where empty functions should be marked as uncovered

@earthboundkid
Copy link
Contributor

This is another special case of #53271.

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

No branches or pull requests

5 participants