Skip to content

Commit

Permalink
Add short-with-failure format
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Oct 13, 2019
1 parent 782abf2 commit 30a7d17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ gotestsum --format short-verbose
Supported formats:
* `dots` - output one character per test.
* `short` (default) - output a line for each test package.
* `short-with-failures` - like short, but prints test output as soon as a test
fails.
* `standard-quiet` - the default `go test` format.
* `short-verbose` - output a line for each test and package.
* `standard-verbose` - the standard `go test -v` format.
Expand Down
16 changes: 16 additions & 0 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func shortFormat(event TestEvent, exec *Execution) (string, error) {
if !event.PackageEvent() {
return "", nil
}
return shortFormatPackageEvent(event, exec)
}

func shortFormatPackageEvent(event TestEvent, exec *Execution) (string, error) {
pkg := exec.Package(event.Package)

fmtElapsed := func() string {
Expand Down Expand Up @@ -161,6 +165,16 @@ func shortFormat(event TestEvent, exec *Execution) (string, error) {
return "", nil
}

func shortWithFailuresFormat(event TestEvent, exec *Execution) (string, error) {
if !event.PackageEvent() {
if event.Action == ActionFail {
return exec.Output(event.Package, event.Test), nil
}
return "", nil
}
return shortFormatPackageEvent(event, exec)
}

func dotsFormat(event TestEvent, exec *Execution) (string, error) {
pkg := exec.Package(event.Package)
withColor := colorEvent(event)
Expand Down Expand Up @@ -207,6 +221,8 @@ func NewEventFormatter(format string) EventFormatter {
return shortVerboseFormat
case "short":
return shortFormat
case "short-with-failures":
return shortWithFailuresFormat
default:
return nil
}
Expand Down

0 comments on commit 30a7d17

Please sign in to comment.