-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: fix
-coverpkg
not ignoring special directories
The pattern passed to `-coverpkg` when running `go test` would not ignore directories usually ignored by the `go` command, i.e. those beginning with "." or "_" are ignored by the go tool, as are directories named "testdata". Fix this by adding an explicit check for these (by following a similar check in `src/cmd/doc/dirs.go`[1]) allowing us to ignore them. The scope of the change is limted to package matching to only the -coverpkg flag of `go test` to avoid impacting -gcflags and the other per package flags, e.g. we don't want to change behaviour for a user building something that imports a leading dot package who wants to set gcflags for it Two tests are added for this change, one is a regression test attempting to directly replicate the behaviour described in the issue, the other is updating another test I saw fail when trialling other solutions to this issue so I thought it worthwhile to be explicit about the change there. See linked issue for a reproduction. Fixes #66038 [1] https://go.googlesource.com/go/+/16e5d24480dca7ddcbdffb78a8ed5de3e5155dec/src/cmd/doc/dirs.go#136
- Loading branch information
1 parent
5b5d6f8
commit 84888c7
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/cmd/go/testdata/script/coverpkg_ignores_special_dirs.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# test for https://github.com/golang/go/issues/66038 | ||
[short] skip | ||
|
||
env GO111MODULE=off | ||
# files | ||
env GOPATH=$WORK/.dir${:}$WORK/_dir${:}$WORK/testdata | ||
|
||
cd $WORK | ||
go test -coverpkg=./... ./... | ||
stdout 'coverage: 100.0%' | ||
|
||
-- $WORK/a.go -- | ||
package a | ||
|
||
// trivial function with 100% test coverage | ||
|
||
import ( | ||
_ "dot_dir" | ||
_ "under_dir" | ||
_ "testdata_dir" | ||
) | ||
|
||
func F(i int) int { | ||
return i*i | ||
} | ||
|
||
-- $WORK/a_test.go -- | ||
package a | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestF(t *testing.T) { | ||
F(2) | ||
} | ||
|
||
-- $WORK/.dir/src/dot_dir/b.go -- | ||
package dot_dir | ||
|
||
func G(i int) int { | ||
return i*i | ||
} | ||
|
||
-- $WORK/_dir/src/under_dir/b.go -- | ||
package dot_dir | ||
|
||
func G(i int) int { | ||
return i*i | ||
} | ||
|
||
-- $WORK/testdata/src/testdata_dir/b.go -- | ||
package testdata_dir | ||
|
||
func G(i int) int { | ||
return i*i | ||
} |