Skip to content

Commit

Permalink
Keep empty packages by default in testdox format
Browse files Browse the repository at this point in the history
And only hide Fuzz test cases, always report the top level test
function.
  • Loading branch information
dnephin committed Aug 27, 2023
1 parent 61b66b7 commit 0466efc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Commonly used formats (see `--help` for a full list):
* `dots` - print a character for each test.
* `pkgname` (default) - print a line for each package.
* `testname` - print a line for each test and package.
* `testdox` - print a sentence for each test using [gotestdox](https://github.com/bitfield/gotestdox)
* `standard-quiet` - the standard `go test` format.
* `standard-verbose` - the standard `go test -v` format.

Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ Formats:
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testdox TestDox format (print a sentence for each test)
testname print a line for each test and package
testdox print a sentence for each test using gotestdox
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: 1 addition & 1 deletion cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Formats:
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testdox TestDox format (print a sentence for each test)
testname print a line for each test and package
testdox print a sentence for each test using gotestdox
github-actions testname format with github actions log grouping
standard-quiet standard go test format
standard-verbose standard go test -v format
Expand Down
11 changes: 8 additions & 3 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func testDoxFormat(out io.Writer, opts FormatOptions) EventFormatter {
if !event.Action.IsTerminal() {
return nil
}
if len(results[event.Package]) == 0 {
// No testdox for you
if opts.HideEmptyPackages && len(results[event.Package]) == 0 {
return nil
}
fmt.Fprintf(buf, "%s:\n", event.Package)
Expand All @@ -123,7 +122,7 @@ func testDoxFormat(out io.Writer, opts FormatOptions) EventFormatter {
case event.Action.IsTerminal():
// Fuzz test cases tend not to have interesting names,
// so only report these if they're failures
if strings.HasPrefix(event.Test, "Fuzz") && event.Action == ActionPass {
if isFuzzCase(event) {
return nil
}
results[event.Package] = append(results[event.Package], Result{
Expand All @@ -135,6 +134,12 @@ func testDoxFormat(out io.Writer, opts FormatOptions) EventFormatter {
})
}

func isFuzzCase(event TestEvent) bool {
return strings.HasPrefix(event.Test, "Fuzz") &&
event.Action == ActionPass &&
TestName(event.Test).IsSubTest()
}

func testNameFormat(out io.Writer) EventFormatter {
buf := bufio.NewWriter(out)
// nolint:errcheck
Expand Down
2 changes: 2 additions & 0 deletions testjson/testdata/format/testdox-coverage.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gotest.tools/gotestsum/testjson/internal/badmain:

gotest.tools/gotestsum/testjson/internal/good:
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
Expand Down
2 changes: 2 additions & 0 deletions testjson/testdata/format/testdox-shuffle.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gotest.tools/gotestsum/testjson/internal/badmain:

gotest.tools/gotestsum/testjson/internal/good:
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
Expand Down
4 changes: 4 additions & 0 deletions testjson/testdata/format/testdox.out
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
gotest.tools/gotestsum/testjson/internal/badmain:

gotest.tools/gotestsum/testjson/internal/empty:

gotest.tools/gotestsum/testjson/internal/good:
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
Expand Down

0 comments on commit 0466efc

Please sign in to comment.