github.com/searKing/golang/go@v1.2.117/log/slog/logger_test.go (about) 1 // Copyright 2023 The searKing Author. 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 package slog 6 7 import ( 8 "runtime" 9 "testing" 10 ) 11 12 // callerPC returns the program counter at the given stack depth. 13 func callerPC(depth int) uintptr { 14 var pcs [1]uintptr 15 runtime.Callers(depth, pcs[:]) 16 return pcs[0] 17 } 18 19 func wantAllocs(t *testing.T, want int, f func()) { 20 t.Helper() 21 got := int(testing.AllocsPerRun(5, f)) 22 if got != want { 23 t.Errorf("got %d allocs, want %d", got, want) 24 } 25 }