mirror of
https://github.com/gortc/stun.git
synced 2025-09-27 04:45:55 +08:00
testutil: add ShouldNotAllocate helper
This commit is contained in:
16
internal/testutil/allocs.go
Normal file
16
internal/testutil/allocs.go
Normal 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)
|
||||
}
|
||||
}
|
6
internal/testutil/norace.go
Normal file
6
internal/testutil/norace.go
Normal file
@@ -0,0 +1,6 @@
|
||||
// +build !race
|
||||
|
||||
package testutil
|
||||
|
||||
// Race reports if the race detector is enabled.
|
||||
const Race = false
|
6
internal/testutil/race.go
Normal file
6
internal/testutil/race.go
Normal file
@@ -0,0 +1,6 @@
|
||||
// +build race
|
||||
|
||||
package testutil
|
||||
|
||||
// Race reports if the race detector is enabled.
|
||||
const Race = true
|
Reference in New Issue
Block a user