From f4820d809974e1cd3d20a4ef24d5ff1eccc0d66f Mon Sep 17 00:00:00 2001 From: ruinivist Date: Sat, 21 Mar 2026 08:24:30 +0000 Subject: [PATCH] style: formatting for time + colors --- cmd/root_test.go | 18 +++++++++--------- internal/miro/test.go | 16 ++++++++++++---- internal/miro/test_test.go | 21 +++++++++++++++++++++ internal/output/output.go | 2 +- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/cmd/root_test.go b/cmd/root_test.go index 2a2b7e0..dc9e752 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -220,10 +220,10 @@ func TestRunTest(t *testing.T) { for _, want := range []string{ "RUN a", - "PASS a in ", - " seconds", + "PASS a (", + " ms)", "RUN nested/b", - "PASS nested/b in ", + "PASS nested/b (", "Summary: total=2 passed=2 failed=0", } { if !strings.Contains(stdout, want) { @@ -266,9 +266,9 @@ func TestRunTestScopedDirectory(t *testing.T) { for _, want := range []string{ "RUN nested/b", - "PASS nested/b in ", + "PASS nested/b (", "RUN nested/c", - "PASS nested/c in ", + "PASS nested/c (", "Summary: total=2 passed=2 failed=0", } { if !strings.Contains(stdout, want) { @@ -313,7 +313,7 @@ func TestRunTestScopedLeafDirectory(t *testing.T) { for _, want := range []string{ "RUN nested/b", - "PASS nested/b in ", + "PASS nested/b (", "Summary: total=1 passed=1 failed=0", } { if !strings.Contains(stdout, want) { @@ -358,9 +358,9 @@ func TestRunTestReturnsZeroWhenScenarioMismatches(t *testing.T) { for _, want := range []string{ "RUN a", - "PASS a in ", + "PASS a (", "RUN b", - "FAIL b in ", + "FAIL b (", "output differed", "Summary: total=2 passed=1 failed=1", } { @@ -459,7 +459,7 @@ func TestRunTestReturnsZeroWhenCompareMarkerMissing(t *testing.T) { for _, want := range []string{ "RUN some", - "FAIL some in ", + "FAIL some (", "missing compare marker", "Summary: total=1 passed=0 failed=1", } { diff --git a/internal/miro/test.go b/internal/miro/test.go index 073d7b6..8cc6629 100644 --- a/internal/miro/test.go +++ b/internal/miro/test.go @@ -85,15 +85,15 @@ func runTests(path string, tio testIO) error { start := time.Now() if err := replayScenario(scenario, shellPath, tio, cfg.Sandbox); err != nil { - elapsed := time.Since(start).Seconds() + elapsed := time.Since(start) summary.failed++ - output.Fprintf(tio.out, "%s %s in %.3f seconds: %v\n", output.Label("FAIL", output.Fail), scenario.relPath, elapsed, err) + output.Fprintf(tio.out, "%s %s (%s): %v\n", output.Label("FAIL", output.Fail), scenario.relPath, formatElapsed(elapsed), err) continue } - elapsed := time.Since(start).Seconds() + elapsed := time.Since(start) summary.passed++ - output.Fprintf(tio.out, "%s %s in %.3f seconds\n", output.Label("PASS", output.Pass), scenario.relPath, elapsed) + output.Fprintf(tio.out, "%s %s (%s)\n", output.Label("PASS", output.Pass), scenario.relPath, formatElapsed(elapsed)) } summaryColor := output.Pass @@ -113,6 +113,14 @@ func runTests(path string, tio testIO) error { return nil } +func formatElapsed(elapsed time.Duration) string { + if elapsed < time.Second { + return fmt.Sprintf("%d ms", elapsed/time.Millisecond) + } + + return fmt.Sprintf("%.2f s", elapsed.Seconds()) +} + func resolveTestDiscoveryRoot(testDir, path string) (string, error) { if path == "" { return testDir, nil diff --git a/internal/miro/test_test.go b/internal/miro/test_test.go index be4eb56..bc32765 100644 --- a/internal/miro/test_test.go +++ b/internal/miro/test_test.go @@ -5,8 +5,29 @@ import ( "path/filepath" "strings" "testing" + "time" ) +func TestFormatElapsed(t *testing.T) { + tests := []struct { + name string + elapsed time.Duration + wantText string + }{ + {name: "sub-second", elapsed: 123 * time.Millisecond, wantText: "123 ms"}, + {name: "boundary", elapsed: time.Second, wantText: "1.00 s"}, + {name: "multi-second", elapsed: 1534 * time.Millisecond, wantText: "1.53 s"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := formatElapsed(tt.elapsed); got != tt.wantText { + t.Fatalf("formatElapsed(%v) = %q, want %q", tt.elapsed, got, tt.wantText) + } + }) + } +} + func TestDiscoverTestScenariosFindsNestedFixturesAndSorts(t *testing.T) { testDir := filepath.Join(t.TempDir(), "e2e") writeScenarioFixtures(t, filepath.Join(testDir, "nested", "b"), "echo two\n", "echo two\n") diff --git a/internal/output/output.go b/internal/output/output.go index 2cf742a..6a103a0 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -18,7 +18,7 @@ var ( miroGreen: 0x70E000, chevronTeal: 0x1DD3B0, info: 0xD7FFFF, - pass: 0x87D75F, + pass: 0x00d7af, fail: 0xFF8787, } )