syle: add colors to miro test output

This commit is contained in:
2026-03-21 07:26:17 +00:00
parent b3fc15d3ae
commit 88ad09fa6d
3 changed files with 47 additions and 28 deletions
+13 -7
View File
@@ -88,24 +88,30 @@ func runTests(path string, tio testIO) error {
summary := testSummary{total: len(scenarios)} summary := testSummary{total: len(scenarios)}
for _, scenario := range scenarios { for _, scenario := range scenarios {
output.Fprintf(tio.out, "%s %s\n", output.LabelInfo("RUN"), scenario.relPath) output.Fprintf(tio.out, "%s %s\n", output.Label("RUN", output.Info), scenario.relPath)
if err := replayScenario(scenario, shellPath, tio, cfg.Sandbox); err != nil { if err := replayScenario(scenario, shellPath, tio, cfg.Sandbox); err != nil {
summary.failed++ summary.failed++
output.Fprintf(tio.out, "FAIL %s: %v\n", scenario.relPath, err) output.Fprintf(tio.out, "%s %s: %v\n", output.Label("FAIL", output.Fail), scenario.relPath, err)
continue continue
} }
summary.passed++ summary.passed++
output.Fprintf(tio.out, "PASS %s\n", scenario.relPath) output.Fprintf(tio.out, "%s %s\n", output.Label("PASS", output.Pass), scenario.relPath)
}
summaryColor := output.Pass
if summary.failed > 0 {
summaryColor = output.Fail
} }
output.Fprintf( output.Fprintf(
tio.out, tio.out,
"Summary: total=%d passed=%d failed=%d\n", "%s\n",
summary.total, output.Label(
summary.passed, fmt.Sprintf("Summary: total=%d passed=%d failed=%d", summary.total, summary.passed, summary.failed),
summary.failed, summaryColor,
),
) )
if summary.failed > 0 { if summary.failed > 0 {
+28 -15
View File
@@ -17,26 +17,39 @@ var (
}{ }{
miroGreen: 0x70E000, miroGreen: 0x70E000,
chevronTeal: 0x1DD3B0, chevronTeal: 0x1DD3B0,
info: 0xf5f2e1, info: 0xD7FFFF,
pass: 0x7bf1a8, pass: 0x87D75F,
fail: 0xff8fa3, fail: 0xFF8787,
} }
) )
func label(text string, color uint32) string { type Color int
return NewStyle().FG(color).Apply(text)
const (
Info Color = iota
Pass
Fail
)
func label(text string, color Color) string {
var fg uint32
switch color {
case Info:
fg = palette.info
case Pass:
fg = palette.pass
case Fail:
fg = palette.fail
default:
fg = palette.info
}
return NewStyle().FG(fg).Apply(text)
} }
func LabelPass(text string) string { func Label(text string, color Color) string {
return label(text, palette.pass) return label(text, color)
}
func LabelFail(text string) string {
return label(text, palette.fail)
}
func LabelInfo(text string) string {
return label(text, palette.info)
} }
func noColor() bool { func noColor() bool {
+6 -6
View File
@@ -29,14 +29,14 @@ func TestFormatPlainWhenNoColorSet(t *testing.T) {
func TestLabelsPlainWhenNoColorSet(t *testing.T) { func TestLabelsPlainWhenNoColorSet(t *testing.T) {
t.Setenv("NO_COLOR", "1") t.Setenv("NO_COLOR", "1")
if got := LabelInfo("RUN"); got != "RUN" { if got := Label("RUN", Info); got != "RUN" {
t.Fatalf("LabelInfo() = %q, want %q", got, "RUN") t.Fatalf("Label() = %q, want %q", got, "RUN")
} }
if got := LabelPass("PASS"); got != "PASS" { if got := Label("PASS", Pass); got != "PASS" {
t.Fatalf("LabelPass() = %q, want %q", got, "PASS") t.Fatalf("Label() = %q, want %q", got, "PASS")
} }
if got := LabelFail("FAIL"); got != "FAIL" { if got := Label("FAIL", Fail); got != "FAIL" {
t.Fatalf("LabelFail() = %q, want %q", got, "FAIL") t.Fatalf("Label() = %q, want %q", got, "FAIL")
} }
} }