style: formatting for time + colors

This commit is contained in:
2026-03-21 08:24:30 +00:00
parent f50a6b6447
commit f4820d8099
4 changed files with 43 additions and 14 deletions
+12 -4
View File
@@ -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
+21
View File
@@ -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")
+1 -1
View File
@@ -18,7 +18,7 @@ var (
miroGreen: 0x70E000,
chevronTeal: 0x1DD3B0,
info: 0xD7FFFF,
pass: 0x87D75F,
pass: 0x00d7af,
fail: 0xFF8787,
}
)