Files
gio/layout/alloc_test.go
T
Elias Naur 4484674ab1 layout: don't run alloc tests with -race
The race runtime allocates where the non-race runtime doesn't.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-06-03 10:18:57 +02:00

49 lines
831 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
// +build !race
package layout
import (
"image"
"testing"
"gioui.org/op"
)
func TestStackAllocs(t *testing.T) {
var ops op.Ops
allocs := testing.AllocsPerRun(1, func() {
ops.Reset()
gtx := Context{
Ops: &ops,
}
Stack{}.Layout(gtx,
Stacked(func(gtx Context) Dimensions {
return Dimensions{Size: image.Point{X: 50, Y: 50}}
}),
)
})
if allocs != 0 {
t.Errorf("expected no allocs, got %f", allocs)
}
}
func TestFlexAllocs(t *testing.T) {
var ops op.Ops
allocs := testing.AllocsPerRun(1, func() {
ops.Reset()
gtx := Context{
Ops: &ops,
}
Flex{}.Layout(gtx,
Rigid(func(gtx Context) Dimensions {
return Dimensions{Size: image.Point{X: 50, Y: 50}}
}),
)
})
if allocs != 0 {
t.Errorf("expected no allocs, got %f", allocs)
}
}