mirror of
https://github.com/gortc/stun.git
synced 2025-10-30 03:21:46 +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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user