diff --git a/main.go b/main.go index 0d48481..405f688 100644 --- a/main.go +++ b/main.go @@ -24,16 +24,19 @@ func runGoTest() int { cmd := exec.Command("go", args...) cmd.Env = os.Environ() - reader, writer := io.Pipe() - defer writer.Close() + outReader, outWriter := io.Pipe() + defer outWriter.Close() - cmd.Stdout = writer - cmd.Stderr = writer + errReader, errWriter := io.Pipe() + defer errWriter.Close() + + cmd.Stdout = outWriter + cmd.Stderr = errWriter go func() { - defer reader.Close() + defer outReader.Close() - scanner := bufio.NewScanner(reader) + scanner := bufio.NewScanner(outReader) for scanner.Scan() { line := scanner.Text() @@ -60,6 +63,21 @@ func runGoTest() int { } }() + go func() { + defer errReader.Close() + + scanner := bufio.NewScanner(errReader) + + for scanner.Scan() { + line := scanner.Text() + color.Red("%s\n", line) + } + + if err := scanner.Err(); err != nil { + log.Printf("scanner error: %s", err) + } + }() + if err := cmd.Run(); err != nil { return 1 }