-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?
./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
-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?
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 {
}
}
+ 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()