Merge "Don't write output during tests"

This commit is contained in:
Treehugger Robot
2017-04-20 22:46:54 +00:00
committed by Gerrit Code Review
2 changed files with 7 additions and 6 deletions

View File

@@ -47,14 +47,14 @@ var (
)
func main() {
exitCode, err := Main(os.Args[0], os.Args[1:])
exitCode, err := Main(os.Stdout, os.Args[0], os.Args[1:])
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
os.Exit(exitCode)
}
func Main(name string, args []string) (int, error) {
func Main(out io.Writer, name string, args []string) (int, error) {
if len(args) < 1 {
return 1, fmt.Errorf("usage: %s javac ...", name)
}
@@ -78,7 +78,7 @@ func Main(name string, args []string) (int, error) {
// Process subprocess stdout asynchronously
errCh := make(chan error)
go func() {
errCh <- process(pr, os.Stdout)
errCh <- process(pr, out)
}()
// Wait for subprocess to finish

View File

@@ -16,6 +16,7 @@ package main
import (
"bytes"
"io/ioutil"
"strconv"
"testing"
)
@@ -82,7 +83,7 @@ func TestJavacColorize(t *testing.T) {
func TestSubprocess(t *testing.T) {
t.Run("failure", func(t *testing.T) {
exitCode, err := Main("test", []string{"sh", "-c", "exit 9"})
exitCode, err := Main(ioutil.Discard, "test", []string{"sh", "-c", "exit 9"})
if err != nil {
t.Fatal("unexpected error", err)
}
@@ -92,7 +93,7 @@ func TestSubprocess(t *testing.T) {
})
t.Run("signal", func(t *testing.T) {
exitCode, err := Main("test", []string{"sh", "-c", "kill -9 $$"})
exitCode, err := Main(ioutil.Discard, "test", []string{"sh", "-c", "kill -9 $$"})
if err != nil {
t.Fatal("unexpected error", err)
}
@@ -102,7 +103,7 @@ func TestSubprocess(t *testing.T) {
})
t.Run("success", func(t *testing.T) {
exitCode, err := Main("test", []string{"echo"})
exitCode, err := Main(ioutil.Discard, "test", []string{"echo"})
if err != nil {
t.Fatal("unexpected error", err)
}