Debian Codegraph @

event/alloc_test.go

raw symbols SCIP
1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build !race
6
7 package event_test
8
9 import (
10 "context"
11 "io"
12 "testing"
13
14 "golang.org/x/exp/event"
15 "golang.org/x/exp/event/adapter/logfmt"
16 "golang.org/x/exp/event/eventtest"
17 )
18
19 func TestAllocs(t *testing.T) {
20 anInt := event.Int64("int", 4)
21 aString := event.String("string", "value")
22
23 e := event.NewExporter(logfmt.NewHandler(io.Discard), &event.ExporterOptions{EnableNamespaces: true})
24 ctx := event.WithExporter(context.Background(), e)
25 allocs := int(testing.AllocsPerRun(5, func() {
26 event.Log(ctx, "message", aString, anInt)
27 }))
28 if allocs != 0 {
29 t.Errorf("Got %d allocs, expect 0", allocs)
30 }
31 }
32
33 func TestBenchAllocs(t *testing.T) {
34 eventtest.TestAllocs(t, eventPrint, eventLog, 0)
35 }