1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:18:35 -06:00

cmd/go: make the default coverage mode -atomic if -race is set

Fixes #7013.

LGTM=adg
R=golang-codereviews, gobot, adg
CC=golang-codereviews
https://golang.org/cl/76370043
This commit is contained in:
Rob Pike 2014-03-18 14:38:40 +11:00
parent 8a511cccb5
commit 108a4dcd75
4 changed files with 43 additions and 3 deletions

View File

@ -802,7 +802,8 @@ control the execution of any test:
-covermode set,count,atomic
Set the mode for coverage analysis for the package[s]
being tested. The default is "set".
being tested. The default is "set" unless -race is enabled,
in which case it is "atomic".
The values:
set: bool: does this statement run?
count: int: how many times does this statement run?

View File

@ -568,6 +568,37 @@ TEST coverage runs
./testgo test -short -coverpkg=strings strings regexp || ok=false
./testgo test -short -cover strings math regexp || ok=false
# Check that coverage analysis uses set mode.
TEST coverage uses set mode
if ./testgo test -short -coverpkg=encoding/binary -coverprofile=testdata/cover.out; then
if ! grep -q 'mode: set' testdata/cover.out; then
ok=false
fi
else
ok=false
fi
rm -f testdata/cover.out
TEST coverage uses atomic mode for -race.
if ./testgo test -short -race -coverpkg=encoding/binary -coverprofile=testdata/cover.out; then
if ! grep -q 'mode: atomic' testdata/cover.out; then
ok=false
fi
else
ok=false
fi
rm -f testdata/cover.out
TEST coverage uses actual setting to override even for -race.
if ./testgo test -short -race -coverpkg=encoding/binary -covermode=count -coverprofile=testdata/cover.out; then
if ! grep -q 'mode: count' testdata/cover.out; then
ok=false
fi
else
ok=false
fi
rm -f testdata/cover.out
TEST coverage with cgo
d=$(TMPDIR=/var/tmp mktemp -d -t testgoXXX)
./testgo test -short -cover ./testdata/cgocover >$d/cgo.out 2>&1 || ok=false

View File

@ -137,7 +137,8 @@ control the execution of any test:
-covermode set,count,atomic
Set the mode for coverage analysis for the package[s]
being tested. The default is "set".
being tested. The default is "set" unless -race is enabled,
in which case it is "atomic".
The values:
set: bool: does this statement run?
count: int: how many times does this statement run?

View File

@ -117,7 +117,6 @@ var testFlagDefn = []*testFlagSpec{
func testFlags(args []string) (packageNames, passToTest []string) {
inPkg := false
outputDir := ""
testCoverMode = "set"
for i := 0; i < len(args); i++ {
if !strings.HasPrefix(args[i], "-") {
if !inPkg && packageNames == nil {
@ -218,6 +217,14 @@ func testFlags(args []string) (packageNames, passToTest []string) {
}
}
if testCoverMode == "" {
testCoverMode = "set"
if buildRace {
// Default coverage mode is atomic when -race is set.
testCoverMode = "atomic"
}
}
// Tell the test what directory we're running in, so it can write the profiles there.
if testProfile && outputDir == "" {
dir, err := os.Getwd()