github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/test_race_cover_mode_issue20435.txt (about) 1 [short] skip 2 [!race] skip 3 4 # Make sure test is functional. 5 go test testrace 6 7 # Now, check that -race -covermode=set is not allowed. 8 ! go test -race -covermode=set testrace 9 stderr '-covermode must be "atomic", not "set", when -race is enabled' 10 ! stdout PASS 11 ! stderr PASS 12 13 -- testrace/race_test.go -- 14 package testrace 15 16 import "testing" 17 18 func TestRace(t *testing.T) { 19 for i := 0; i < 10; i++ { 20 c := make(chan int) 21 x := 1 22 go func() { 23 x = 2 24 c <- 1 25 }() 26 x = 3 27 <-c 28 _ = x 29 } 30 } 31 32 func BenchmarkRace(b *testing.B) { 33 for i := 0; i < b.N; i++ { 34 c := make(chan int) 35 x := 1 36 go func() { 37 x = 2 38 c <- 1 39 }() 40 x = 3 41 <-c 42 _ = x 43 } 44 }