Skip to content

Commit

Permalink
Restore default format
Browse files Browse the repository at this point in the history
Only use github-actions format if format is set to testname. The current default
pkgname is much more compact. Maybe we could add a github-actions-pkgname format
in the future that folds the entire package.

For now it seems safe to use github-actions instead of pkgname if the GITHUB_ACTIONS
environment variable is set.  If someone really wants the output expanded by default
they can unset or overwrite that env var for the 'gotestsum' process.
  • Loading branch information
dnephin committed Aug 26, 2023
1 parent f814ba5 commit 2913209
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
go-version: '1.20'
cache: true
- run: go build .
- run: ./gotestsum
- run: ./gotestsum -f testname
2 changes: 2 additions & 0 deletions cmd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (bufferCloser) Close() error { return nil }
func (bufferCloser) Sync() error { return nil }

func TestEventHandler_Event_WithMissingActionFail(t *testing.T) {
t.Setenv("GITHUB_ACTIONS", "no")

buf := new(bufferCloser)
errBuf := new(bytes.Buffer)
format := testjson.NewEventFormatter(errBuf, "testname", testjson.FormatOptions{})
Expand Down
8 changes: 3 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
flags.Usage = func() {
usage(os.Stdout, name, flags)
}
defaultFormat := "pkgname"
if os.Getenv("GITHUB_ACTIONS") == "true" {
defaultFormat = "github-actions"
}

flags.StringVarP(&opts.format, "format", "f",
lookEnvWithDefault("GOTESTSUM_FORMAT", defaultFormat),
lookEnvWithDefault("GOTESTSUM_FORMAT", "pkgname"),
"print format of test input")
flags.BoolVar(&opts.formatOptions.HideEmptyPackages, "format-hide-empty-pkg",
false, "do not print empty packages in compact formats")
Expand Down Expand Up @@ -143,6 +140,7 @@ Formats:
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testname print a line for each test and package
github-actions testname format with github actions log grouping
standard-quiet standard go test format
standard-verbose standard go test -v format
Expand Down
2 changes: 2 additions & 0 deletions cmd/main_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestE2E_RerunFails(t *testing.T) {
if testing.Short() {
t.Skip("too slow for short run")
}
t.Setenv("GITHUB_ACTIONS", "no")

type testCase struct {
name string
Expand Down Expand Up @@ -245,6 +246,7 @@ func TestE2E_IgnoresWarnings(t *testing.T) {
if testing.Short() {
t.Skip("too slow for short run")
}
t.Setenv("GITHUB_ACTIONS", "no")

flags, opts := setupFlags("gotestsum")
args := []string{
Expand Down
1 change: 1 addition & 0 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Formats:
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testname print a line for each test and package
github-actions testname format with github actions log grouping
standard-quiet standard go test format
standard-verbose standard go test -v format

Expand Down
4 changes: 4 additions & 0 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io"
"os"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -312,6 +313,9 @@ func NewEventFormatter(out io.Writer, format string, formatOpts FormatOptions) E
case "dots-v2":
return newDotFormatter(out, formatOpts)
case "testname", "short-verbose":
if os.Getenv("GITHUB_ACTIONS") == "true" {
return githubActionsFormat(out)
}
return testNameFormat(out)
case "pkgname", "short":
return pkgNameFormat(out, formatOpts)
Expand Down

0 comments on commit 2913209

Please sign in to comment.