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