package diary import ( "bytes" "context" "log/slog" "strings" "sync/atomic" "testing" "time" "github.com/charmbracelet/colorprofile" ) // TestConsoleHideOnTTYTerminal (IN-01): the styled console handler skips a // HideOnTTY record when its writer is a terminal, and writes ordinary // records. func TestConsoleHideOnTTYTerminal(t *testing.T) { var buf bytes.Buffer h := newConsoleHandler(&buf, ConsoleOptions{Profile: colorprofile.ANSI}, new(atomic.Bool)) h.terminal = true hidden := slog.NewRecord(time.Time{}, slog.LevelInfo, "hidden summary", 0) if err := h.Handle(HideOnTTY(context.Background()), hidden); err != nil { t.Fatal(err) } shown := slog.NewRecord(time.Time{}, slog.LevelInfo, "shown line", 0) if err := h.Handle(context.Background(), shown); err != nil { t.Fatal(err) } if strings.Contains(buf.String(), "hidden summary") { t.Errorf("terminal console shows a HideOnTTY record:\n%s", buf.String()) } if !strings.Contains(buf.String(), "shown line") { t.Errorf("terminal console lacks the ordinary record:\n%s", buf.String()) } }