Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/mattn/goveralls v0.0.11
github.com/obalunenko/coverbadger v1.2.0
golang.org/x/tools v0.1.10
gotest.tools/gotestsum v1.7.0
gotest.tools/gotestsum v1.8.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1815,8 +1815,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/gotestsum v1.7.0 h1:RwpqwwFKBAa2h+F6pMEGpE707Edld0etUD3GhqqhDNc=
gotest.tools/gotestsum v1.7.0/go.mod h1:V1m4Jw3eBerhI/A6qCxUE07RnCg7ACkKj9BYcAm09V8=
gotest.tools/gotestsum v1.8.0 h1:ltj5KWhbQjt1Yx+IPBj0Dk2HVDUs9OlLmGC2JvivTMo=
gotest.tools/gotestsum v1.8.0/go.mod h1:ctqdxBSCPv80kAFjYvFNpPntBrE5HAQnLiOKBGLmOBs=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
4 changes: 2 additions & 2 deletions tools/vendor/gotest.tools/gotestsum/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ linters-settings:
issues:
exclude-use-default: false
exclude-rules:
- linters: [golint]
- linters: [revive]
text: 'should have comment .*or be unexported'
- linters: [stylecheck]
text: 'ST1000: at least one file in a package should have a package comment'
Expand All @@ -33,7 +33,6 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gosimple
- govet
- ineffassign
Expand All @@ -42,6 +41,7 @@ linters:
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- structcheck
- stylecheck
Expand Down
24 changes: 21 additions & 3 deletions tools/vendor/gotest.tools/gotestsum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ See [documentation](#documentation).
## Install

Download a binary from [releases](https://github.com/gotestyourself/gotestsum/releases), or build from
source with `go get gotest.tools/gotestsum`.
source with `go install gotest.tools/gotestsum@latest`. With `go` version before 1.17, use `go get gotest.tools/gotestsum`.

## Demo
A demonstration of three `--format` options.
Expand Down Expand Up @@ -152,6 +152,15 @@ example `notify` command only works on macOS with
gotestsum --post-run-command notify
```

**Example: command with flags**

Possitional arguments or command line flags can be passed to the `--post-run-command` by
quoting the whole command.

```
gotestsum --post-run-command "notify me --date"
```

### Re-running failed tests

When the `--rerun-fails` flag is set, `gotestsum` will re-run any failed tests.
Expand Down Expand Up @@ -225,13 +234,18 @@ stdout and stderr output:

* The stdout produced by the script must only contain the `test2json` output, or
`gotestsum` will fail. If it isn't possible to change the script to avoid
non-JSON output, you can use `--ignore-non-json-output-lines` to ignore
non-JSON lines and write them to `gotestsum`'s stderr instead.
non-JSON output, you can use `--ignore-non-json-output-lines` (added in version 1.7.0)
to ignore non-JSON lines and write them to `gotestsum`'s stderr instead.
* Any stderr produced by the script will be considered an error (this behaviour
is necessary because package build errors are only reported by writting to
stderr, not the `test2json` stdout). Any stderr produced by tests is not
considered an error (it will be in the `test2json` stdout).

**Example: accept intput from stdin**
```
cat out.json | gotestsum --raw-command -- cat
```

**Example: run tests with profiling enabled**

Using a `profile.sh` script like this:
Expand Down Expand Up @@ -334,15 +348,19 @@ directory will be watched. Use the `--packages` flag to specify a different list
While in watch mode, pressing some keys will perform an action:

* `r` will run tests for the previous event.
Added in version 1.6.1.
* `d` will run tests for the previous event using `dlv test`, allowing you to
debug a test failure using [delve]. A breakpoint will automatically be added at
the first line of any tests which failed in the previous run. Additional
breakpoints can be added with [`runtime.Breakpoint`](https://golang.org/pkg/runtime/#Breakpoint)
or by using the delve command prompt.
Added in version 1.6.1.
* `a` will run tests for all packages, by using `./...` as the package selector.
Added in version 1.7.0.
* `l` will scan the directory list again, and if there are any new directories
which contain a file with a `.go` extension, they will be added to the watch
list.
Added in version 1.7.0.

Note that [delve] must be installed in order to use debug (`d`).

Expand Down
3 changes: 3 additions & 0 deletions tools/vendor/gotest.tools/gotestsum/cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"

"github.com/pkg/errors"
"gotest.tools/gotestsum/internal/junitxml"
Expand Down Expand Up @@ -68,6 +69,7 @@ func newEventHandler(opts *options) (*eventHandler, error) {
}
var err error
if opts.jsonFile != "" {
_ = os.MkdirAll(filepath.Dir(opts.jsonFile), 0o755)
handler.jsonFile, err = os.Create(opts.jsonFile)
if err != nil {
return handler, errors.Wrap(err, "failed to open JSON file")
Expand All @@ -80,6 +82,7 @@ func writeJUnitFile(opts *options, execution *testjson.Execution) error {
if opts.junitFile == "" {
return nil
}
_ = os.MkdirAll(filepath.Dir(opts.junitFile), 0o755)
junitFile, err := os.Create(opts.junitFile)
if err != nil {
return fmt.Errorf("failed to open JUnit file: %v", err)
Expand Down
59 changes: 47 additions & 12 deletions tools/vendor/gotest.tools/gotestsum/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os/exec"
"os/signal"
"strings"
"sync/atomic"
"syscall"

"github.com/dnephin/pflag"
"github.com/fatih/color"
Expand Down Expand Up @@ -46,8 +48,8 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
junitTestCaseClassnameFormat: &junitFieldFormatValue{},
junitTestSuiteNameFormat: &junitFieldFormatValue{},
postRunHookCmd: &commandValue{},
stdout: os.Stdout,
stderr: os.Stderr,
stdout: color.Output,
stderr: color.Error,
}
flags := pflag.NewFlagSet(name, pflag.ContinueOnError)
flags.SetInterspersed(false)
Expand All @@ -65,7 +67,7 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
flags.StringVar(&opts.jsonFile, "jsonfile",
lookEnvWithDefault("GOTESTSUM_JSONFILE", ""),
"write all TestEvents to file")
flags.BoolVar(&opts.noColor, "no-color", color.NoColor, "disable color output")
flags.BoolVar(&opts.noColor, "no-color", defaultNoColor, "disable color output")

flags.Var(opts.hideSummary, "no-summary",
"do not print summary of: "+testjson.SummarizeAll.String())
Expand Down Expand Up @@ -126,6 +128,7 @@ Formats:

Commands:
tool tools for working with test2json output
help print this help next
`)
}

Expand Down Expand Up @@ -172,6 +175,13 @@ func (o options) Validate() error {
return nil
}

var defaultNoColor = func() bool {
if os.Getenv("GITHUB_ACTIONS") == "true" {
return false
}
return color.NoColor
}()

func setupLogging(opts *options) {
if opts.debug {
log.SetLevel(log.DebugLevel)
Expand Down Expand Up @@ -209,6 +219,9 @@ func run(opts *options) error {
return finishRun(opts, exec, err)
}
exitErr := goTestProc.cmd.Wait()
if signum := atomic.LoadInt32(&goTestProc.signal); signum != 0 {
return finishRun(opts, exec, exitError{num: signalExitCode + int(signum)})
}
if exitErr == nil || opts.rerunFailsMaxAttempts == 0 {
return finishRun(opts, exec, exitErr)
}
Expand Down Expand Up @@ -335,38 +348,42 @@ type proc struct {
cmd waiter
stdout io.Reader
stderr io.Reader
// signal is atomically set to the signal value when a signal is received
// by newSignalHandler.
signal int32
}

type waiter interface {
Wait() error
}

func startGoTest(ctx context.Context, args []string) (proc, error) {
func startGoTest(ctx context.Context, args []string) (*proc, error) {
if len(args) == 0 {
return proc{}, errors.New("missing command to run")
return nil, errors.New("missing command to run")
}

cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.Stdin = os.Stdin
p := proc{cmd: cmd}
log.Debugf("exec: %s", cmd.Args)
var err error
p.stdout, err = cmd.StdoutPipe()
if err != nil {
return p, err
return nil, err
}
p.stderr, err = cmd.StderrPipe()
if err != nil {
return p, err
return nil, err
}
if err := cmd.Start(); err != nil {
return p, errors.Wrapf(err, "failed to run %s", strings.Join(cmd.Args, " "))
return nil, errors.Wrapf(err, "failed to run %s", strings.Join(cmd.Args, " "))
}
log.Debugf("go test pid: %d", cmd.Process.Pid)

ctx, cancel := context.WithCancel(ctx)
newSignalHandler(ctx, cmd.Process.Pid)
newSignalHandler(ctx, cmd.Process.Pid, &p)
p.cmd = &cancelWaiter{cancel: cancel, wrapped: p.cmd}
return p, nil
return &p, nil
}

// ExitCodeWithDefault returns the ExitStatus of a process from the error returned by
Expand All @@ -387,12 +404,28 @@ type exitCoder interface {
ExitCode() int
}

func isExitCoder(err error) bool {
func IsExitCoder(err error) bool {
_, ok := err.(exitCoder)
return ok
}

func newSignalHandler(ctx context.Context, pid int) {
type exitError struct {
num int
}

func (e exitError) Error() string {
return fmt.Sprintf("exit code %d", e.num)
}

func (e exitError) ExitCode() int {
return e.num
}

// signalExitCode is the base value added to a signal number to produce the
// exit code value. This matches the behaviour of bash.
const signalExitCode = 128

func newSignalHandler(ctx context.Context, pid int, p *proc) {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

Expand All @@ -403,6 +436,8 @@ func newSignalHandler(ctx context.Context, pid int) {
case <-ctx.Done():
return
case s := <-c:
atomic.StoreInt32(&p.signal, int32(s.(syscall.Signal)))

proc, err := os.FindProcess(pid)
if err != nil {
log.Errorf("failed to find pid of 'go test': %v", err)
Expand Down
4 changes: 2 additions & 2 deletions tools/vendor/gotest.tools/gotestsum/cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (w *watchRuns) run(event filewatcher.Event) error {
args: w.opts.args,
initFilePath: path,
}
if err := runDelve(o); !isExitCoder(err) {
if err := runDelve(o); !IsExitCoder(err) {
return fmt.Errorf("delve failed: %w", err)
}
return nil
Expand All @@ -43,7 +43,7 @@ func (w *watchRuns) run(event filewatcher.Event) error {
opts := w.opts
opts.packages = []string{event.PkgPath}
var err error
if w.prevExec, err = runSingle(&opts); !isExitCoder(err) {
if w.prevExec, err = runSingle(&opts); !IsExitCoder(err) {
return err
}
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package dotwriter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package filewatcher
Expand Down
31 changes: 12 additions & 19 deletions tools/vendor/gotest.tools/gotestsum/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package log

import (
"fmt"
"os"

"github.com/fatih/color"
)
Expand All @@ -16,15 +15,10 @@ const (
)

var (
level = WarnLevel
out stringWriter = os.Stderr
level = WarnLevel
out = color.Error
)

// TODO: replace with io.StringWriter once support for go1.11 is dropped.
type stringWriter interface {
WriteString(s string) (n int, err error)
}

// SetLevel for the global logger.
func SetLevel(l Level) {
level = l
Expand All @@ -35,36 +29,35 @@ func Warnf(format string, args ...interface{}) {
if level < WarnLevel {
return
}
out.WriteString(color.YellowString("WARN "))
out.WriteString(fmt.Sprintf(format, args...))
out.WriteString("\n")
fmt.Fprint(out, color.YellowString("WARN "))
fmt.Fprintf(out, format, args...)
fmt.Fprint(out, "\n")
}

// Debugf prints the message to stderr, with no prefix.
func Debugf(format string, args ...interface{}) {
if level < DebugLevel {
return
}
out.WriteString(fmt.Sprintf(format, args...))
out.WriteString("\n")
fmt.Fprintf(out, format, args...)
fmt.Fprint(out, "\n")
}

// Errorf prints the message to stderr, with a red ERROR prefix.
func Errorf(format string, args ...interface{}) {
if level < ErrorLevel {
return
}
out.WriteString(color.RedString("ERROR "))
out.WriteString(fmt.Sprintf(format, args...))
out.WriteString("\n")
fmt.Fprint(out, color.RedString("ERROR "))
fmt.Fprintf(out, format, args...)
fmt.Fprint(out, "\n")
}

// Error prints the message to stderr, with a red ERROR prefix.
func Error(msg string) {
if level < ErrorLevel {
return
}
out.WriteString(color.RedString("ERROR "))
out.WriteString(msg)
out.WriteString("\n")
fmt.Fprint(out, color.RedString("ERROR "))
fmt.Fprintln(out, msg)
}
Loading