Skip to content

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

Open
@abemedia

Description

@abemedia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions