Skip to content

Commit

Permalink
Merge pull request #29 from dnephin/pr-fix-go-module-output
Browse files Browse the repository at this point in the history
Add Go module files
  • Loading branch information
dnephin committed Nov 3, 2018
2 parents fc6f8e9 + 3652484 commit ad9c8f4
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 33 deletions.
14 changes: 13 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dobifiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

ARG GOLANG_VERSION
FROM golang:${GOLANG_VERSION:-1.10.3-alpine} as golang
FROM golang:${GOLANG_VERSION:-1.11-alpine} as golang
RUN apk add -U curl git bash
WORKDIR /go/src/gotest.tools/gotestsum
ENV CGO_ENABLED=0
Expand Down
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module gotest.tools/gotestsum

require (
github.com/fatih/color v1.6.0
github.com/google/go-cmp v0.2.0
github.com/jonboulle/clockwork v0.1.0
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-isatty v0.0.3
github.com/pkg/errors v0.8.0
github.com/sirupsen/logrus v1.0.5
github.com/spf13/pflag v1.0.1
golang.org/x/crypto v0.0.0-20180426230345-b49d69b5da94
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
golang.org/x/sys v0.0.0-20180427151831-cbbc999da32d
gotest.tools v2.1.0+incompatible
)
28 changes: 28 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
github.com/fatih/color v1.6.0 h1:66qjqZk8kalYAvDRtM1AdAJQI0tj4Wrue3Eq3B3pmFU=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/sirupsen/logrus v1.0.5 h1:8c8b5uO0zS4X6RPl/sd1ENwSkIc0/H2PaHxE3udaE8I=
github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
golang.org/x/crypto v0.0.0-20180426230345-b49d69b5da94 h1:m5xBqfQdnzv6XuV/pJizrLOwUoGzyn1J249cA0cKL4o=
golang.org/x/crypto v0.0.0-20180426230345-b49d69b5da94/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc h1:ZMCWScCvS2fUVFw8LOpxyUUW5qiviqr4Dg5NdjLeiLU=
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180427151831-cbbc999da32d h1:50dJ9HJTx71MG4/LtVzB2w2xMeaNkxpZbrrro/cHSII=
golang.org/x/sys v0.0.0-20180427151831-cbbc999da32d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gotest.tools v2.0.0+incompatible h1:yyrf3cq5SnFjtaoKnR6Lqu+6VKYWhqoXOtDalCgE8bU=
gotest.tools v2.0.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools v2.1.0+incompatible h1:5USw7CrJBYKqjg9R7QlA6jzqZKEAtvW82aNmsxxGPxw=
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
76 changes: 45 additions & 31 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/jonboulle/clockwork"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

// Action of TestEvent
Expand Down Expand Up @@ -282,50 +283,63 @@ type EventHandler interface {
// calls the Handler for each event, and returns the Execution.
func ScanTestOutput(config ScanConfig) (*Execution, error) {
execution := NewExecution()
waitOnStderr := readStderr(config.Stderr, config.Handler.Err, execution)
scanner := bufio.NewScanner(config.Stdout)
var group errgroup.Group
group.Go(func() error {
return readStdout(config, execution)
})
group.Go(func() error {
return readStderr(config, execution)
})
return execution, group.Wait()
}

func readStdout(config ScanConfig, execution *Execution) error {
scanner := bufio.NewScanner(config.Stdout)
for scanner.Scan() {
raw := scanner.Bytes()
event, err := parseEvent(raw)
switch err {
case errBadEvent:
// TODO: put raw into errors.
switch {
case err == errBadEvent:
// nolint: errcheck
config.Handler.Err(errBadEvent.Error() + ": " + scanner.Text())
continue
case nil:
default:
return nil, errors.Wrapf(err, "failed to parse test output: %s", string(raw))
case err != nil:
return errors.Wrapf(err, "failed to parse test output: %s", string(raw))
}
execution.add(event)
if err := config.Handler.Event(event, execution); err != nil {
return nil, err
return err
}
}
return errors.Wrap(scanner.Err(), "failed to scan test output")
}

func readStderr(config ScanConfig, execution *Execution) error {
scanner := bufio.NewScanner(config.Stderr)
for scanner.Scan() {
line := scanner.Text()
config.Handler.Err(line) // nolint: errcheck
if isGoModuleOutput(line) {
continue
}
execution.addError(line)
}
return errors.Wrap(scanner.Err(), "failed to scan test stderr")
}

// TODO: this is not reached if pareseEvent or Handler.Event returns an error
if err := <-waitOnStderr; err != nil {
logrus.Warnf("failed reading stderr: %s", err)
func isGoModuleOutput(scannerText string) bool {
prefixes := []string{
"go: extracting",
"go: downloading",
"go: finding",
}
return execution, errors.Wrap(scanner.Err(), "failed to scan test output")
}

type errHandler func(text string) error

func readStderr(in io.Reader, handle errHandler, exec *Execution) chan error {
wait := make(chan error, 1)
go func() {
defer close(wait)
scanner := bufio.NewScanner(in)
for scanner.Scan() {
exec.addError(scanner.Text())
if err := handle(scanner.Text()); err != nil {
wait <- err
return
}

for _, prefix := range prefixes {
if strings.HasPrefix(scannerText, prefix) {
return true
}
wait <- scanner.Err()
}()
return wait
}
return false
}

func parseEvent(raw []byte) (TestEvent, error) {
Expand Down

0 comments on commit ad9c8f4

Please sign in to comment.