Skip to content

Commit

Permalink
Merge pull request #73 from dnephin/format-verbose-errors
Browse files Browse the repository at this point in the history
Add short-with-failures format
  • Loading branch information
dnephin authored Oct 27, 2019
2 parents 782abf2 + 168b49e commit 0b91335
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ gotestsum --format short-verbose
```

Supported formats:
* `dots` - output one character per test.
* `short` (default) - output a line for each test package.
* `standard-quiet` - the default `go test` format.
* `short-verbose` - output a line for each test and package.
* `dots` - print a character for each test.
* `short` (default) - print a line for each package.
* `short-with-failures` - print a line for each package and failed test output.
* `short-verbose` - print a line for each test and package.
* `standard-quiet` - the standard `go test` format.
* `standard-verbose` - the standard `go test -v` format.

Have a suggestion for some other format? Please open an issue!
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ Flags:
flags.PrintDefaults()
fmt.Fprint(os.Stderr, `
Formats:
dots print a character for each test
short print a line for each package
short-verbose print a line for each test and package
standard-quiet default go test format
standard-verbose default go test -v format
dots print a character for each test
short print a line for each package
short-with-failures print a line for each package and failed test output
short-verbose print a line for each test and package
standard-quiet standard go test format
standard-verbose standard go test -v format
`)
}
flags.BoolVar(&opts.debug, "debug", false, "enabled debug")
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 0b91335

Please sign in to comment.