Skip to content

Commit

Permalink
Rename --no-summary to --hide-summary
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Oct 11, 2020
1 parent 1530e18 commit 8efcfba
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 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
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

0 comments on commit 8efcfba

Please sign in to comment.