From 983d90e11dd0e12a484def454530fe9f5de031fc Mon Sep 17 00:00:00 2001 From: Nakul Bajaj Date: Tue, 17 Oct 2023 23:24:20 -0700 Subject: [PATCH] testing/slogtest: test no source key with empty PC in record Fixes #62280 Change-Id: Ideaffb797d8bb9cc70e635f0b019ae3cb90abc92 Reviewed-on: https://go-review.googlesource.com/c/go/+/536117 Reviewed-by: Bryan Mills LUCI-TryBot-Result: Go LUCI Reviewed-by: Jonathan Amsterdam --- src/testing/slogtest/slogtest.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/testing/slogtest/slogtest.go b/src/testing/slogtest/slogtest.go index e60e8438d4..6f08180df5 100644 --- a/src/testing/slogtest/slogtest.go +++ b/src/testing/slogtest/slogtest.go @@ -216,6 +216,17 @@ var cases = []testCase{ inGroup("G", hasAttr("b", "v2")), }, }, + { + name: "empty-PC", + explanation: withSource("a Handler should not output SourceKey if the PC is zero"), + f: func(l *slog.Logger) { + l.Info("message") + }, + mod: func(r *slog.Record) { r.PC = 0 }, + checks: []check{ + missingKey(slog.SourceKey), + }, + }, } // TestHandler tests a [slog.Handler]. -- 2.50.0