Skip to content

proposal: testing: support automatic multiple package coverage #21126

@dlsniper

Description

@dlsniper

Currently it's very hard to support coverage for the tested package and all the dependencies of that package.

In order to do this today, one would need to do something like this:

go test -coverpkg `go list -f {{.Deps}} | sed 's/\[//g' | sed 's/]//g' | sed 's/ /,/g'`,tested/package/name tested/package/name

The problem is that this would also list the standard library dependencies, which is not really useful and it's hard to write as well (see the fact that one needs to append the name of the tested package to actually get the coverage for it). The above command also doesn't work on Windows.

The other option would be to use:

go test -coverpkg PACKAGE_DIR/... tested/package/name

This however will not show dependencies from GOPATH.

As such, I'm proposing adding a magical keyword named deps (like all) to solve this problem. The way it should work would be:

go test -coverpkg deps tested/package/name

This comes up pretty often, see: https://youtrack.jetbrains.com/issue/GO-1541 for the number of voters / watchers or duplicate issues. It is true that the IDE could generate the list of packages but the users that do not use such a tool wouldn't be able to benefit from it.

Please note this is different from #6909.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions