Test case:
package foo_test
import (
"fmt"
"testing"
)
func makeRace() {
var x int
c := make(chan bool)
go func() {
x = 1
c <- true
}()
fmt.Println(x)
<-c
}
func TestFoo(t *testing.T) {
makeRace()
}
Running this test with go test -race -test.v prints
=== RUN TestFoo
0
==================
WARNING: DATA RACE
Write at 0x00c000014288 by goroutine 8:
command-line-arguments_test.makeRace.func1()
/home/iant/foo_test.go:12 +0x33
Previous read at 0x00c000014288 by goroutine 7:
command-line-arguments_test.makeRace()
/home/iant/foo_test.go:15 +0x10c
command-line-arguments_test.TestFoo()
/home/iant/foo_test.go:20 +0x1c
testing.tRunner()
/home/iant/go/src/testing/testing.go:1595 +0x238
??()
-:0 +0x5243c4
Goroutine 8 (running) created at:
command-line-arguments_test.makeRace()
/home/iant/foo_test.go:11 +0xfc
command-line-arguments_test.TestFoo()
/home/iant/foo_test.go:20 +0x1c
testing.tRunner()
/home/iant/go/src/testing/testing.go:1595 +0x238
??()
-:0 +0x5243c4
Goroutine 7 (running) created at:
testing.(*T).Run()
/home/iant/go/src/testing/testing.go:1648 +0x835
testing.runTests.func1()
/home/iant/go/src/testing/testing.go:2054 +0x84
testing.tRunner()
/home/iant/go/src/testing/testing.go:1595 +0x238
testing.runTests()
/home/iant/go/src/testing/testing.go:2052 +0x896
testing.(*M).Run()
/home/iant/go/src/testing/testing.go:1925 +0xb57
main.main()
_testmain.go:47 +0x2bd
==================
testing.go:1465: race detected during execution of test
--- FAIL: TestFoo (0.00s)
=== NAME
testing.go:1465: race detected during execution of test
FAIL
FAIL command-line-arguments 0.007s
FAIL
Note the === NAME near the end. A === NAME line should be followed by the name of the test. Omitting the name is confusing and can break code that is parsing the test output.
Test case:
Running this test with
go test -race -test.vprintsNote the
=== NAMEnear the end. A=== NAMEline should be followed by the name of the test. Omitting the name is confusing and can break code that is parsing the test output.