From 30a7d171e335e24a8e8fe0f2b2d62a44b31c945d Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sun, 13 Oct 2019 13:14:53 -0400 Subject: [PATCH 1/2] Add short-with-failure format --- README.md | 2 ++ testjson/format.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 4347b4bc..46a4d1d2 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/testjson/format.go b/testjson/format.go index 6b64ac43..59856403 100644 --- a/testjson/format.go +++ b/testjson/format.go @@ -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 { @@ -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) @@ -207,6 +221,8 @@ func NewEventFormatter(format string) EventFormatter { return shortVerboseFormat case "short": return shortFormat + case "short-with-failures": + return shortWithFailuresFormat default: return nil } From 168b49e4f201902fcac9e328dfc08be0f496a531 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sun, 27 Oct 2019 14:24:46 -0400 Subject: [PATCH 2/2] Add short-with-failures to help And make the README match the help output. --- README.md | 11 +++++------ main.go | 11 ++++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 46a4d1d2..ab3f7602 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,11 @@ 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. + * `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! diff --git a/main.go b/main.go index cd9b7c92..ea3c83de 100644 --- a/main.go +++ b/main.go @@ -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")