testutil: add ShouldNotAllocate helper

This commit is contained in:
Aleksandr Razumov
2018-08-02 10:24:03 +03:00
parent c1ad9a931c
commit bc192a0797
3 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package testutil
import (
"testing"
)
// ShouldNotAllocate fails if f allocates.
func ShouldNotAllocate(t *testing.T, f func()) {
if Race {
t.Skip("skip while running with -race")
return
}
if a := testing.AllocsPerRun(10, f); a > 0 {
t.Errorf("allocations detected: %f", a)
}
}

View File

@@ -0,0 +1,6 @@
// +build !race
package testutil
// Race reports if the race detector is enabled.
const Race = false

View File

@@ -0,0 +1,6 @@
// +build race
package testutil
// Race reports if the race detector is enabled.
const Race = true