Files
mire/internal/output/output_test.go
2026-03-21 12:49:57 +00:00

59 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package output
import (
"os"
"strings"
"testing"
)
func TestFormatIncludesANSIByDefault(t *testing.T) {
t.Setenv("NO_COLOR", "")
got := Format("hello\n")
if !strings.Contains(got, "\x1b[") {
t.Fatalf("Format() = %q, want ANSI styling", got)
}
if !strings.Contains(got, "hello\n") {
t.Fatalf("Format() = %q, want message body", got)
}
}
func TestFormatPlainWhenNoColorSet(t *testing.T) {
t.Setenv("NO_COLOR", "1")
if got := Format("hello\n"); got != "mire hello\n" {
t.Fatalf("Format() = %q, want %q", got, "mire hello\n")
}
}
func TestLabelsPlainWhenNoColorSet(t *testing.T) {
t.Setenv("NO_COLOR", "1")
if got := Label("RUN", Info); got != "RUN" {
t.Fatalf("Label() = %q, want %q", got, "RUN")
}
if got := Label("PASS", Pass); got != "PASS" {
t.Fatalf("Label() = %q, want %q", got, "PASS")
}
if got := Label("FAIL", Fail); got != "FAIL" {
t.Fatalf("Label() = %q, want %q", got, "FAIL")
}
}
func TestFormatReadsNoColorAtRuntime(t *testing.T) {
t.Setenv("NO_COLOR", "")
styled := Format("hello\n")
if err := os.Setenv("NO_COLOR", "1"); err != nil {
t.Fatalf("Setenv() error = %v", err)
}
plain := Format("hello\n")
if !strings.Contains(styled, "\x1b[") {
t.Fatalf("styled Format() = %q, want ANSI styling", styled)
}
if plain != "mire hello\n" {
t.Fatalf("plain Format() = %q, want %q", plain, "mire hello\n")
}
}