Skip to content

Commit 201b9f6

Browse files
matttproudgopherbot
authored andcommitted
cmd/go: clarify that -coverpkg uses import paths
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 #69653 Change-Id: Ifde6a974405ce1614e28898fc2b92ed5bad94e57 GitHub-Last-Rev: 466c662 GitHub-Pull-Request: #69655 Reviewed-on: https://go-review.googlesource.com/c/go/+/616257 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent b33fc48 commit 201b9f6

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

src/cmd/go/alldocs.go

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/help/helpdoc.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ Go library.
6464
- "cmd" expands to the Go repository's commands and their
6565
internal libraries.
6666
67+
Package names match against fully-qualified import paths or patterns that
68+
match against any number of import paths. For instance, "fmt" refers to the
69+
standard library's package fmt, but "http" alone for package http would not
70+
match the import path "net/http" from the standard library. Instead, the
71+
complete import path "net/http" must be used.
72+
6773
Import paths beginning with "cmd/" only match source code in
6874
the Go repository.
6975
@@ -93,7 +99,10 @@ By convention, this is arranged by starting each path with a
9399
unique prefix that belongs to you. For example, paths used
94100
internally at Google all begin with 'google', and paths
95101
denoting remote repositories begin with the path to the code,
96-
such as 'github.com/user/repo'.
102+
such as 'github.com/user/repo'. Package patterns should include this prefix.
103+
For instance, a package called 'http' residing under 'github.com/user/repo',
104+
would be addressed with the fully-qualified pattern:
105+
'github.com/user/repo/http'.
97106
98107
Packages in a program need not have unique package names,
99108
but there are two reserved package names with special meaning.

src/cmd/go/internal/test/test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ control the execution of any test:
235235
Sets -cover.
236236
237237
-coverpkg pattern1,pattern2,pattern3
238-
Apply coverage analysis in each test to packages matching the patterns.
239-
The default is for each test to analyze only the package being tested.
240-
See 'go help packages' for a description of package patterns.
241-
Sets -cover.
238+
Apply coverage analysis in each test to packages whose import paths
239+
match the patterns. The default is for each test to analyze only
240+
the package being tested. See 'go help packages' for a description
241+
of package patterns. Sets -cover.
242242
243243
-cpu 1,2,4
244244
Specify a list of GOMAXPROCS values for which the tests, benchmarks or

src/cmd/go/internal/work/build.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ and test commands:
104104
Sets -cover.
105105
-coverpkg pattern1,pattern2,pattern3
106106
For a build that targets package 'main' (e.g. building a Go
107-
executable), apply coverage analysis to each package matching
108-
the patterns. The default is to apply coverage analysis to
109-
packages in the main Go module. See 'go help packages' for a
110-
description of package patterns. Sets -cover.
107+
executable), apply coverage analysis to each package whose
108+
import path matches the patterns. The default is to apply
109+
coverage analysis to packages in the main Go module. See
110+
'go help packages' for a description of package patterns.
111+
Sets -cover.
111112
-v
112113
print the names of packages as they are compiled.
113114
-work

0 commit comments

Comments
 (0)