1
2
3
4
5 package test
6
7 import (
8 "testing"
9 )
10
11 var output int
12
13 type Object struct {
14 Val int
15 }
16
17 func (o *Object) Initialize() *Object {
18 o.Val = 5
19 return o
20 }
21
22 func (o *Object) Update() *Object {
23 o.Val = o.Val + 1
24 return o
25 }
26
27 func TestAutotmpLoopDepth(t *testing.T) {
28 f := func() {
29 for i := 0; i < 10; i++ {
30 var obj Object
31 obj.Initialize().Update()
32 output = obj.Val
33 }
34 }
35 if n := testing.AllocsPerRun(10, f); n > 0 {
36 t.Error("obj moved to heap")
37 }
38 }
39
View as plain text