package output import ( "bytes" "testing" "github.com/stretchr/testify/assert" ) func TestColorsEnabled_BufferIsNotTTY(t *testing.T) { t.Setenv("NO_COLOR", "") // Explicitly unset NO_COLOR so the non-TTY branch is exercised. t.Setenv("NO_COLOR", "") assert.False(t, ColorsEnabled(&bytes.Buffer{}), "bytes.Buffer must never be considered a TTY") } func TestColorsEnabled_NoColorEnvForcesOff(t *testing.T) { t.Setenv("NO_COLOR", "1") assert.False(t, ColorsEnabled(&bytes.Buffer{})) } func TestColorsEnabled_NilWriterSafe(t *testing.T) { t.Setenv("NO_COLOR", "") // A nil *os.File should return false, not panic. var f *nilWriter assert.False(t, ColorsEnabled(f)) } // nilWriter is a typed-nil io.Writer used to verify ColorsEnabled does not // panic when passed a non-*os.File writer. type nilWriter struct{} func (*nilWriter) Write(p []byte) (int, error) { return len(p), nil } func TestIsTTY_NilFile(t *testing.T) { assert.False(t, IsTTY(nil)) }