You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
561 B
Go
38 lines
561 B
Go
// +build std
|
|
|
|
package incr
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestOnce(t *testing.T) {
|
|
x := 1
|
|
|
|
t.Run("increment", func(t *testing.T) {
|
|
x++
|
|
if x != 2 {
|
|
t.Errorf("expected x to be 2, is %d instead", x)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestTwice(t *testing.T) {
|
|
x := 1
|
|
|
|
t.Run("increment", func(t *testing.T) {
|
|
x++
|
|
if x != 2 {
|
|
t.Errorf("expected x to be 2, is %d instead", x)
|
|
}
|
|
})
|
|
|
|
// this fails, because both subtests close over the same x.
|
|
t.Run("increment", func(t *testing.T) {
|
|
x++
|
|
if x != 2 {
|
|
t.Errorf("expected x to be 2, is %d instead", x)
|
|
}
|
|
})
|
|
}
|