]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: make the default coverage mode -atomic if -race is set
authorRob Pike <r@golang.org>
Tue, 18 Mar 2014 03:38:40 +0000 (14:38 +1100)
committerRob Pike <r@golang.org>
Tue, 18 Mar 2014 03:38:40 +0000 (14:38 +1100)
Fixes #7013.

LGTM=adg
R=golang-codereviews, gobot, adg
CC=golang-codereviews
https://golang.org/cl/76370043

src/cmd/go/doc.go
src/cmd/go/test.bash
src/cmd/go/test.go
src/cmd/go/testflag.go

index 155623000ed6898318451fd8a3a9290ac6927c82..61693789358107b7991afda8db48919e4011627c 100644 (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?
index 507f2885ddcfe86e219309f8ca40ec64b9ee5dfd..fe00df9e24d9f8948a5ddfedadb323fd19392b58 100755 (executable)
@@ -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
index 3344f0e5b86c3c6c31a619f632a6e4166a015424..20a9e74af14fce5657de99de1538694388daf158 100644 (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?
index 69c33d39e66710b6e722b0bd0b5bc387da19d4b1..2b5f89ba5f97000137124afcf074c9ba550cd182 100644 (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()