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 c768413
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions testjson/format.go
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
@@ -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
@@ -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
@@ -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 c768413

Please sign in to comment.