Skip to content

Commit

Permalink
cmd/go: clarify that -coverpkg uses import paths
Browse files Browse the repository at this point in the history
This change amends the long-form help output for 'go help build' and
'go help testflag' to specify that the '-coverpkg' flag operates
explicitly on import paths as well as package names. Import paths are
fundamental for precise specification of packages versus unqualified
package names, and the naming of the flag '-coverpkg' and its original
documentation leads a user to assume that it only operates on the
simple, unqualified package name form. The situation warrants
clarification.

Fixes golang#69653
  • Loading branch information
matttproud committed Sep 28, 2024
1 parent 6a730e1 commit a76a3a6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
28 changes: 19 additions & 9 deletions src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/cmd/go/internal/help/helpdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Go library.
- "cmd" expands to the Go repository's commands and their
internal libraries.
Package names that correspond to complete import paths found in the standard
library can be used as patterns without further qualification. For instance,
"fmt" refers to the standard library's package fmt, but "http" alone for
package http could not be used to refer to import path "net/http". Instead,
the complete pattern "net/http" must be used.
Import paths beginning with "cmd/" only match source code in
the Go repository.
Expand Down Expand Up @@ -93,7 +99,10 @@ By convention, this is arranged by starting each path with a
unique prefix that belongs to you. For example, paths used
internally at Google all begin with 'google', and paths
denoting remote repositories begin with the path to the code,
such as 'github.com/user/repo'.
such as 'github.com/user/repo'. Package patterns should include this prefix.
For instance, a package called 'http' residing under 'github.com/user/repo',
would be addressed with the fully-qualified pattern:
'github.com/user/repo/http'.
Packages in a program need not have unique package names,
but there are two reserved package names with special meaning.
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ control the execution of any test:
Sets -cover.
-coverpkg pattern1,pattern2,pattern3
Apply coverage analysis in each test to packages matching the patterns.
The default is for each test to analyze only the package being tested.
See 'go help packages' for a description of package patterns.
Sets -cover.
Apply coverage analysis in each test to packages whose import paths
match the patterns. The default is for each test to analyze only
the package being tested. See 'go help packages' for a description
of package patterns. Sets -cover.
-cpu 1,2,4
Specify a list of GOMAXPROCS values for which the tests, benchmarks or
Expand Down
9 changes: 5 additions & 4 deletions src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ and test commands:
Sets -cover.
-coverpkg pattern1,pattern2,pattern3
For a build that targets package 'main' (e.g. building a Go
executable), apply coverage analysis to each package matching
the patterns. The default is to apply coverage analysis to
packages in the main Go module. See 'go help packages' for a
description of package patterns. Sets -cover.
executable), apply coverage analysis to each package whose
import path matches the patterns. The default is to apply
coverage analysis to packages in the main Go module. See
'go help packages' for a description of package patterns.
Sets -cover.
-v
print the names of packages as they are compiled.
-work
Expand Down

0 comments on commit a76a3a6

Please sign in to comment.