diff --git a/src/testing/slogtest/slogtest.go b/src/testing/slogtest/slogtest.go index 71076e52f4f..b16d1227dc5 100644 --- a/src/testing/slogtest/slogtest.go +++ b/src/testing/slogtest/slogtest.go @@ -162,6 +162,20 @@ func TestHandler(h slog.Handler, results func() []map[string]any) error { inGroup("G", inGroup("H", hasAttr("e", "f"))), }, }, + { + explanation: withSource("a Handler should not output groups for an empty Record"), + f: func(l *slog.Logger) { + l.With("a", "b").WithGroup("G").With("c", "d").WithGroup("H").Info("msg") + }, + checks: []check{ + hasKey(slog.TimeKey), + hasKey(slog.LevelKey), + hasAttr(slog.MessageKey, "msg"), + hasAttr("a", "b"), + inGroup("G", hasAttr("c", "d")), + inGroup("G", missingKey("H")), + }, + }, { explanation: withSource("a Handler should call Resolve on attribute values"), f: func(l *slog.Logger) {