From 4484674ab1d796816345875c4cb6e3b751a1e187 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 3 Jun 2020 10:18:57 +0200 Subject: [PATCH] layout: don't run alloc tests with -race The race runtime allocates where the non-race runtime doesn't. Signed-off-by: Elias Naur --- layout/alloc_test.go | 48 +++++++++++++++++++++++++++++++++++++++++++ layout/layout_test.go | 36 -------------------------------- 2 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 layout/alloc_test.go diff --git a/layout/alloc_test.go b/layout/alloc_test.go new file mode 100644 index 00000000..f428c5a9 --- /dev/null +++ b/layout/alloc_test.go @@ -0,0 +1,48 @@ +// 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) + } +} diff --git a/layout/layout_test.go b/layout/layout_test.go index 8b1f0ce9..f46fbfcd 100644 --- a/layout/layout_test.go +++ b/layout/layout_test.go @@ -29,39 +29,3 @@ func TestStack(t *testing.T) { t.Errorf("Stack ignored Expanded size, got %v expected %v", got, exp) } } - -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) - } -}