refactor: split color func from runGoTest
parent
4467751b1a
commit
c72f25c2db
31
main.go
31
main.go
|
@ -33,10 +33,20 @@ func runGoTest() int {
|
||||||
cmd.Stdout = outWriter
|
cmd.Stdout = outWriter
|
||||||
cmd.Stderr = errWriter
|
cmd.Stderr = errWriter
|
||||||
|
|
||||||
go func() {
|
go colorOutputReader(outReader)
|
||||||
defer outReader.Close()
|
go colorErrorReader(errReader)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(outReader)
|
if err := cmd.Run(); err != nil {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func colorOutputReader(reader io.ReadCloser) {
|
||||||
|
defer reader.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(reader)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
@ -61,12 +71,12 @@ func runGoTest() int {
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Printf("scanner error: %s", err)
|
log.Printf("scanner error: %s", err)
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
go func() {
|
func colorErrorReader(reader io.ReadCloser) {
|
||||||
defer errReader.Close()
|
defer reader.Close()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(errReader)
|
scanner := bufio.NewScanner(reader)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
@ -76,11 +86,4 @@ func runGoTest() int {
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Printf("scanner error: %s", err)
|
log.Printf("scanner error: %s", err)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue