Skip to content

Commit

Permalink
Merge pull request #152 from dnephin/less-whitespace-in-summary
Browse files Browse the repository at this point in the history
summary: fewer newlines and rename the no-summary flag to hide-summary
  • Loading branch information
dnephin authored Oct 11, 2020
2 parents e3cd29c + 5c495de commit fddcbf4
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 46 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ Following the formatted output is a summary of the test run. The summary include
DONE 101 tests[, 3 skipped][, 2 failures][, 1 error] in 0.103s
```

To disable parts of the summary use `--no-summary section`.
To hide parts of the summary use `--hide-summary section`.


**Example: hide skipped tests in the summary**
```
gotestsum --no-summary=skipped
gotestsum --hide-summary=skipped
```

**Example: hide everything except the DONE line**
```
gotestsum --no-summary=skipped,failed,errors,output
gotestsum --hide-summary=skipped,failed,errors,output
# or
gotestsum --no-summary=all
gotestsum --hide-summary=all
```

**Example: hide output in the summary, only print names of failed and skipped tests
**Example: hide test output in the summary, only print names of failed and skipped tests
and errors**
```
gotestsum --no-summary=output
gotestsum --hide-summary=output
```

### JUnit XML output
Expand Down
12 changes: 6 additions & 6 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"gotest.tools/gotestsum/testjson"
)

type noSummaryValue struct {
type hideSummaryValue struct {
value testjson.Summary
}

func newNoSummaryValue() *noSummaryValue {
return &noSummaryValue{value: testjson.SummarizeAll}
func newHideSummaryValue() *hideSummaryValue {
return &hideSummaryValue{value: testjson.SummarizeAll}
}

func readAsCSV(val string) ([]string, error) {
Expand All @@ -27,7 +27,7 @@ func readAsCSV(val string) ([]string, error) {
return csv.NewReader(strings.NewReader(val)).Read()
}

func (s *noSummaryValue) Set(val string) error {
func (s *hideSummaryValue) Set(val string) error {
v, err := readAsCSV(val)
if err != nil {
return err
Expand All @@ -43,11 +43,11 @@ func (s *noSummaryValue) Set(val string) error {
return nil
}

func (s *noSummaryValue) Type() string {
func (s *hideSummaryValue) Type() string {
return "summary"
}

func (s *noSummaryValue) String() string {
func (s *hideSummaryValue) String() string {
// flip all the bits, since the flag value is the negative of what is stored
return (testjson.SummarizeAll ^ s.value).String()
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (

func TestNoSummaryValue_SetAndString(t *testing.T) {
t.Run("none", func(t *testing.T) {
assert.Equal(t, newNoSummaryValue().String(), "none")
assert.Equal(t, newHideSummaryValue().String(), "none")
})
t.Run("one", func(t *testing.T) {
value := newNoSummaryValue()
value := newHideSummaryValue()
assert.NilError(t, value.Set("output"))
assert.Equal(t, value.String(), "output")
})
t.Run("some", func(t *testing.T) {
value := newNoSummaryValue()
value := newHideSummaryValue()
assert.NilError(t, value.Set("errors,failed"))
assert.Equal(t, value.String(), "failed,errors")
})
t.Run("bad value", func(t *testing.T) {
value := newNoSummaryValue()
value := newHideSummaryValue()
assert.ErrorContains(t, value.Set("bogus"), "must be one or more of")
})
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Run(name string, args []string) error {

func setupFlags(name string) (*pflag.FlagSet, *options) {
opts := &options{
noSummary: newNoSummaryValue(),
hideSummary: newHideSummaryValue(),
junitTestCaseClassnameFormat: &junitFieldFormatValue{},
junitTestSuiteNameFormat: &junitFieldFormatValue{},
postRunHookCmd: &commandValue{},
Expand All @@ -60,8 +60,12 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
lookEnvWithDefault("GOTESTSUM_JSONFILE", ""),
"write all TestEvents to file")
flags.BoolVar(&opts.noColor, "no-color", color.NoColor, "disable color output")
flags.Var(opts.noSummary, "no-summary",

flags.Var(opts.hideSummary, "no-summary",
"do not print summary of: "+testjson.SummarizeAll.String())
flags.Lookup("no-summary").Hidden = true
flags.Var(opts.hideSummary, "hide-summary",
"hide sections of the summary: "+testjson.SummarizeAll.String())
flags.Var(opts.postRunHookCmd, "post-run-command",
"command to run after the tests have completed")

Expand Down Expand Up @@ -131,7 +135,7 @@ type options struct {
junitFile string
postRunHookCmd *commandValue
noColor bool
noSummary *noSummaryValue
hideSummary *hideSummaryValue
junitTestSuiteNameFormat *junitFieldFormatValue
junitTestCaseClassnameFormat *junitFieldFormatValue
rerunFailsMaxAttempts int
Expand Down Expand Up @@ -214,7 +218,7 @@ func run(opts *options) error {
}

func finishRun(opts *options, exec *testjson.Execution, exitErr error) error {
testjson.PrintSummary(opts.stdout, exec, opts.noSummary.value)
testjson.PrintSummary(opts.stdout, exec, opts.hideSummary.value)

if err := writeJUnitFile(opts, exec); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestRun_RerunFails_WithTooManyInitialFailures(t *testing.T) {
rerunFailsMaxInitialFailures: 1,
stdout: out,
stderr: os.Stderr,
noSummary: newNoSummaryValue(),
hideSummary: newHideSummaryValue(),
}
err := run(opts)
assert.ErrorContains(t, err, "number of test failures (2) exceeds maximum (1)", out.String())
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestRun_RerunFails_BuildErrorPreventsRerun(t *testing.T) {
rerunFailsMaxInitialFailures: 1,
stdout: out,
stderr: os.Stderr,
noSummary: newNoSummaryValue(),
hideSummary: newHideSummaryValue(),
}
err := run(opts)
assert.ErrorContains(t, err, "rerun aborted because previous run had errors", out.String())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,4 @@ SEED: 3
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 2)
SEED: 4


DONE 3 runs, 14 tests, 8 failures
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,4 @@ SEED: 3
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 2)
SEED: 4


DONE 3 runs, 14 tests, 8 failures
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ SEED: 4
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 3)
SEED: 5


DONE 5 runs, 18 tests, 10 failures
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ SEED: 4
=== FAIL: cmd/testdata/e2e/flaky TestFailsOften (re-run 3)
SEED: 5


DONE 5 runs, 18 tests, 10 failures
2 changes: 1 addition & 1 deletion cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Usage:
Flags:
--debug enabled debug logging
-f, --format string print format of test input (default "short")
--hide-summary summary hide sections of the summary: skipped,failed,errors,output (default none)
--jsonfile string write all TestEvents to file
--junitfile string write a JUnit XML file
--junitfile-testcase-classname field-format format the testcase classname field as: full, relative, short (default full)
--junitfile-testsuite-name field-format format the testsuite name field as: full, relative, short (default full)
--no-color disable color output (default true)
--no-summary summary do not print summary of: skipped,failed,errors,output (default none)
--packages list space separated list of package to test
--post-run-command command command to run after the tests have completed
--raw-command don't prepend 'go test -json' to the 'go test' command
Expand Down
6 changes: 4 additions & 2 deletions testjson/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func writeTestCaseSummary(out io.Writer, execution executionSummary, conf testCa
return
}
fmt.Fprintln(out, "\n=== "+conf.header)
for _, tc := range testCases {
for idx, tc := range testCases {
fmt.Fprintf(out, "=== %s: %s %s%s (%s)\n",
conf.prefix,
RelativePackagePath(tc.Package),
Expand All @@ -183,7 +183,9 @@ func writeTestCaseSummary(out io.Writer, execution executionSummary, conf testCa
}
fmt.Fprint(out, line)
}
fmt.Fprintln(out)
if _, isNoOutput := execution.(*noOutputSummary); !isNoOutput && idx+1 != len(testCases) {
fmt.Fprintln(out)
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions testjson/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ Some stdout/stderr here
=== SKIP: project/pkg/more TestOnlySometimes (0.00s)
good_test.go:27: the skip message
=== Failed
=== FAIL: project/badmain (0.00s)
sometimes main can exit 2
Expand All @@ -169,7 +168,6 @@ Some stdout/stderr here
=== FAIL: project/pkg/more TestAlbatross (0.04s)
=== Errors
pkg/file.go:99:12: missing ',' before newline
Expand All @@ -186,17 +184,12 @@ DONE 13 tests, 1 skipped, 4 failures, 1 error in 34.123s
=== Skipped
=== SKIP: project/pkg/more TestOnlySometimes (0.00s)
=== Failed
=== FAIL: project/badmain (0.00s)
=== FAIL: project/fs TestFileDo (1.41s)
=== FAIL: project/fs TestFileDoError (0.01s)
=== FAIL: project/pkg/more TestAlbatross (0.04s)
=== Errors
pkg/file.go:99:12: missing ',' before newline
Expand Down
1 change: 0 additions & 1 deletion testjson/testdata/bug-missing-skip-message-summary.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ WARN Failed to detect terminal width for dots format, error: inappropriate ioctl
TestGetPkgPathPrefix/with_go_path: pkgpathprefix_test.go:22: isGoModuleEnabled()
--- SKIP: TestGetPkgPathPrefix/with_go_path (0.00s)


DONE 42 tests, 2 skipped in 0.000s
2 changes: 0 additions & 2 deletions testjson/testdata/bug-repeated-test-case-output.out
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
=== SKIP: github.com/gotestyourself/gotestyourself/testjson/internal/stub TestSkippedWitLog (0.00s)
stub_test.go:30: the skip message


=== Failed
=== FAIL: github.com/gotestyourself/gotestyourself/testjson/internal/badmain (0.00s)
sometimes main can exit 2
Expand Down Expand Up @@ -85,5 +84,4 @@ this is stderr

=== FAIL: github.com/gotestyourself/gotestyourself/testjson/internal/stub TestNestedWithFailure (0.00s)


DONE 138 tests, 12 skipped, 13 failures in 0.000s
1 change: 0 additions & 1 deletion testjson/testdata/summary-misattributed-output
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
foo_test.go:26: output from sub2 test
foo_test.go:32: output after sub test


DONE 5 tests, 1 failure in 0.000s
1 change: 0 additions & 1 deletion testjson/testdata/summary-missing-test-fail-event
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ gotest.tools/v3/poll.WaitOn.func1(0xc00001e3c0, 0x67df50, 0x6c1960, 0xc00016c240
created by gotest.tools/v3/poll.WaitOn
/home/daniel/pers/code/gotest.tools/poll/poll.go:124 +0x16f


DONE 1 tests, 1 failure in 0.000s
1 change: 0 additions & 1 deletion testjson/testdata/summary-parallel-failures.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@
=== FAIL: testjson/internal/parallelfails TestParallelTheSecond (0.01s)
TestParallelTheSecond: fails_test.go:35: failed the second


DONE 12 tests, 8 failures in 0.000s
2 changes: 0 additions & 2 deletions testjson/testdata/summary-root-test-has-subtest-failures
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
=== SKIP: github.com/gotestyourself/gotestyourself/testjson/internal/stub TestSkippedWitLog (0.00s)
stub_test.go:30: the skip message


=== Failed
=== FAIL: github.com/gotestyourself/gotestyourself/testjson/internal/badmain (0.00s)
sometimes main can exit 2
Expand All @@ -31,5 +30,4 @@ this is stderr

=== FAIL: github.com/gotestyourself/gotestyourself/testjson/internal/stub TestNestedWithFailure (0.00s)


DONE 46 tests, 4 skipped, 5 failures in 0.000s
2 changes: 0 additions & 2 deletions testjson/testdata/summary-with-run-id.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
=== SKIP: github.com/gotestyourself/gotestyourself/testjson/internal/stub TestSkippedWitLog (re-run 7) (0.00s)
stub_test.go:30: the skip message


=== Failed
=== FAIL: github.com/gotestyourself/gotestyourself/testjson/internal/badmain (0.00s)
sometimes main can exit 2
Expand All @@ -31,5 +30,4 @@ this is stderr

=== FAIL: github.com/gotestyourself/gotestyourself/testjson/internal/stub TestNestedWithFailure (re-run 7) (0.00s)


DONE 8 runs, 46 tests, 4 skipped, 5 failures in 0.000s

0 comments on commit fddcbf4

Please sign in to comment.