github.com/fnando/bolt@v0.0.4-0.20231107225351-5241e4d187b8/internal/reporters/standard_reporter.go (about) 1 package reporters 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "strings" 7 8 c "github.com/fnando/bolt/common" 9 ) 10 11 type StandardReporter struct { 12 Output *c.Output 13 } 14 15 func (reporter StandardReporter) Name() string { 16 return "standard" 17 } 18 19 func (reporter StandardReporter) OnFinished(options ReporterFinishedOptions) { 20 21 } 22 23 func (reporter StandardReporter) OnProgress(test c.Test) { 24 25 } 26 27 func (reporter StandardReporter) OnData(line string) { 28 var data c.Stream 29 err := json.Unmarshal([]byte(line), &data) 30 31 if err != nil { 32 fmt.Fprint(reporter.Output.Stdout, line) 33 } else { 34 fmt.Fprint(reporter.Output.Stdout, reporter.formatLine(data.Output)) 35 } 36 37 } 38 39 func (reporter StandardReporter) formatLine(line string) string { 40 line = strings.Replace(line, "=== RUN", c.Color.Detail("=== RUN"), 1) 41 line = strings.Replace(line, "--- PASS:", c.Color.Pass("--- PASS:"), 1) 42 line = strings.Replace(line, "--- SKIP:", c.Color.Skip("--- SKIP:"), 1) 43 line = strings.Replace(line, "--- FAIL:", c.Color.Fail("--- FAIL:"), 1) 44 45 return line 46 }