Skip to content

Commit

Permalink
Use the same icons as other gotestsum formats
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Aug 27, 2023
1 parent d827c00 commit 61b66b7
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 177 deletions.
61 changes: 40 additions & 21 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ func testNameFormatTestEvent(out io.Writer, event TestEvent) {
event.Elapsed)
}

func testDoxFormat(out io.Writer) EventFormatter {
func testDoxFormat(out io.Writer, opts FormatOptions) EventFormatter {
buf := bufio.NewWriter(out)
type Result struct {
Event TestEvent
Sentence string
}
getIcon := icon
if opts.UseHiVisibilityIcons {
getIcon = iconHiVis
}
results := map[string][]Result{}
return eventFormatterFunc(func(event TestEvent, exec *Execution) error {
switch {
Expand All @@ -109,18 +113,14 @@ func testDoxFormat(out io.Writer) EventFormatter {
return tests[i].Sentence < tests[j].Sentence
})
for _, r := range tests {
status := color.RedString("x")
if r.Event.Action == ActionPass {
status = color.GreenString("✔")
}
fmt.Fprintf(buf, " %s %s (%.2fs)\n",
status,
getIcon(r.Event.Action),
r.Sentence,
r.Event.Elapsed)
}
fmt.Fprintln(buf)
return buf.Flush()
case event.Action == ActionFail, event.Action == ActionPass:
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 {
Expand Down Expand Up @@ -239,40 +239,59 @@ func pkgNameFormat(out io.Writer, opts FormatOptions) eventFormatterFunc {
}
}

func icon(action Action) string {
switch action {
case ActionPass:
return color.GreenString("✓")
case ActionSkip:
return color.YellowString("∅")
case ActionFail:
return color.RedString("✖")
default:
return ""
}
}

func iconHiVis(action Action) string {
switch action {
case ActionPass:
return "✅"
case ActionSkip:
return "➖"
case ActionFail:
return "❌"
default:
return ""
}
}

func shortFormatPackageEvent(opts FormatOptions, event TestEvent, exec *Execution) string {
pkg := exec.Package(event.Package)

var iconSkipped, iconSuccess, iconFailure string
getIcon := icon
if opts.UseHiVisibilityIcons {
iconSkipped = "➖"
iconSuccess = "✅"
iconFailure = "❌"
} else {
iconSkipped = "∅"
iconSuccess = "✓"
iconFailure = "✖"
getIcon = iconHiVis
}

fmtEvent := func(action string) string {
return action + " " + packageLine(event, exec.Package(event.Package))
}
withColor := colorEvent(event)
switch event.Action {
case ActionSkip:
if opts.HideEmptyPackages {
return ""
}
return fmtEvent(withColor(iconSkipped))
return fmtEvent(getIcon(event.Action))
case ActionPass:
if pkg.Total == 0 {
if opts.HideEmptyPackages {
return ""
}
return fmtEvent(withColor(iconSkipped))
return fmtEvent(getIcon(ActionSkip))
}
return fmtEvent(withColor(iconSuccess))
return fmtEvent(getIcon(event.Action))
case ActionFail:
return fmtEvent(withColor(iconFailure))
return fmtEvent(getIcon(event.Action))
}
return ""
}
Expand Down Expand Up @@ -364,7 +383,7 @@ func NewEventFormatter(out io.Writer, format string, formatOpts FormatOptions) E
case "dots-v2":
return newDotFormatter(out, formatOpts)
case "gotestdox", "testdox":
return testDoxFormat(out)
return testDoxFormat(out, formatOpts)
case "testname", "short-verbose":
if os.Getenv("GITHUB_ACTIONS") == "true" {
return githubActionsFormat(out)
Expand Down
18 changes: 12 additions & 6 deletions testjson/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ func TestFormats_DefaultGoTestJson(t *testing.T) {

testCases := []testCase{
{
name: "testdox",
format: testDoxFormat,
name: "testdox",
format: func(out io.Writer) EventFormatter {
return testDoxFormat(out, FormatOptions{})
},
expectedOut: "format/testdox.out",
},
{
Expand Down Expand Up @@ -182,8 +184,10 @@ func TestFormats_Coverage(t *testing.T) {

testCases := []testCase{
{
name: "testdox",
format: testDoxFormat,
name: "testdox",
format: func(out io.Writer) EventFormatter {
return testDoxFormat(out, FormatOptions{})
},
expectedOut: "format/testdox-coverage.out",
},
{
Expand Down Expand Up @@ -255,8 +259,10 @@ func TestFormats_Shuffle(t *testing.T) {

testCases := []testCase{
{
name: "testdox",
format: testDoxFormat,
name: "testdox",
format: func(out io.Writer) EventFormatter {
return testDoxFormat(out, FormatOptions{})
},
expectedOut: "format/testdox-shuffle.out",
},
{
Expand Down
88 changes: 46 additions & 42 deletions testjson/testdata/format/testdox-coverage.out
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
gotest.tools/gotestsum/testjson/internal/good:
✔ Nested success (0.00s)
✔ Nested success a (0.00s)
✔ Nested success a sub (0.00s)
✔ Nested success b (0.00s)
✔ Nested success b sub (0.00s)
✔ Nested success c (0.00s)
✔ Nested success c sub (0.00s)
✔ Nested success d (0.00s)
✔ Nested success d sub (0.00s)
✔ Parallel the first (0.01s)
✔ Parallel the second (0.01s)
✔ Parallel the third (0.00s)
✔ Passed (0.00s)
✔ Passed with log (0.00s)
✔ Passed with stdout (0.00s)
✔ With stderr (0.00s)
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
✓ Nested success a sub (0.00s)
✓ Nested success b (0.00s)
✓ Nested success b sub (0.00s)
✓ Nested success c (0.00s)
✓ Nested success c sub (0.00s)
✓ Nested success d (0.00s)
✓ Nested success d sub (0.00s)
✓ Parallel the first (0.01s)
✓ Parallel the second (0.01s)
✓ Parallel the third (0.00s)
✓ Passed (0.00s)
✓ Passed with log (0.00s)
✓ Passed with stdout (0.00s)
∅ Skipped (0.00s)
∅ Skipped wit log (0.00s)
✓ With stderr (0.00s)

gotest.tools/gotestsum/testjson/internal/stub:
x Failed (0.00s)
x Failed with stderr (0.00s)
✔ Nested success (0.00s)
✔ Nested success a (0.00s)
✔ Nested success a sub (0.00s)
✔ Nested success b (0.00s)
✔ Nested success b sub (0.00s)
✔ Nested success c (0.00s)
✔ Nested success c sub (0.00s)
✔ Nested success d (0.00s)
✔ Nested success d sub (0.00s)
x Nested with failure (0.00s)
✔ Nested with failure a (0.00s)
✔ Nested with failure a sub (0.00s)
✔ Nested with failure b (0.00s)
✔ Nested with failure b sub (0.00s)
x Nested with failure c (0.00s)
✔ Nested with failure d (0.00s)
✔ Nested with failure d sub (0.00s)
✔ Parallel the first (0.01s)
✔ Parallel the second (0.01s)
✔ Parallel the third (0.00s)
✔ Passed (0.00s)
✔ Passed with log (0.00s)
✔ Passed with stdout (0.00s)
✔ With stderr (0.00s)
✖ Failed (0.00s)
✖ Failed with stderr (0.00s)
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
✓ Nested success a sub (0.00s)
✓ Nested success b (0.00s)
✓ Nested success b sub (0.00s)
✓ Nested success c (0.00s)
✓ Nested success c sub (0.00s)
✓ Nested success d (0.00s)
✓ Nested success d sub (0.00s)
✖ Nested with failure (0.00s)
✓ Nested with failure a (0.00s)
✓ Nested with failure a sub (0.00s)
✓ Nested with failure b (0.00s)
✓ Nested with failure b sub (0.00s)
✖ Nested with failure c (0.00s)
✓ Nested with failure d (0.00s)
✓ Nested with failure d sub (0.00s)
✓ Parallel the first (0.01s)
✓ Parallel the second (0.01s)
✓ Parallel the third (0.00s)
✓ Passed (0.00s)
✓ Passed with log (0.00s)
✓ Passed with stdout (0.00s)
∅ Skipped (0.00s)
∅ Skipped wit log (0.00s)
✓ With stderr (0.00s)

113 changes: 59 additions & 54 deletions testjson/testdata/format/testdox-shuffle.out
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
gotest.tools/gotestsum/testjson/internal/good:
✔ Nested success (0.00s)
✔ Nested success a (0.00s)
✔ Nested success a sub (0.00s)
✔ Nested success b (0.00s)
✔ Nested success b sub (0.00s)
✔ Nested success c (0.00s)
✔ Nested success c sub (0.00s)
✔ Nested success d (0.00s)
✔ Nested success d sub (0.00s)
✔ Parallel the first (0.01s)
✔ Parallel the second (0.01s)
✔ Parallel the third (0.00s)
✔ Passed (0.00s)
✔ Passed with log (0.00s)
✔ Passed with stdout (0.00s)
✔ With stderr (0.00s)
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
✓ Nested success a sub (0.00s)
✓ Nested success b (0.00s)
✓ Nested success b sub (0.00s)
✓ Nested success c (0.00s)
✓ Nested success c sub (0.00s)
✓ Nested success d (0.00s)
✓ Nested success d sub (0.00s)
✓ Parallel the first (0.01s)
✓ Parallel the second (0.01s)
✓ Parallel the third (0.00s)
✓ Passed (0.00s)
✓ Passed with log (0.00s)
✓ Passed with stdout (0.00s)
∅ Skipped (0.00s)
∅ Skipped wit log (0.00s)
✓ With stderr (0.00s)

gotest.tools/gotestsum/testjson/internal/parallelfails:
x Nested parallel failures (0.00s)
x Nested parallel failures a (0.00s)
x Nested parallel failures b (0.00s)
x Nested parallel failures c (0.00s)
x Nested parallel failures d (0.00s)
x Parallel the first (0.01s)
x Parallel the second (0.01s)
x Parallel the third (0.00s)
Passed (0.00s)
Passed with log (0.00s)
Passed with stdout (0.00s)
With stderr (0.00s)
Nested parallel failures (0.00s)
Nested parallel failures a (0.00s)
Nested parallel failures b (0.00s)
Nested parallel failures c (0.00s)
Nested parallel failures d (0.00s)
Parallel the first (0.01s)
Parallel the second (0.01s)
Parallel the third (0.00s)
Passed (0.00s)
Passed with log (0.00s)
Passed with stdout (0.00s)
With stderr (0.00s)

gotest.tools/gotestsum/testjson/internal/withfails:
x Failed (0.00s)
x Failed with stderr (0.00s)
✔ Nested success (0.00s)
✔ Nested success a (0.00s)
✔ Nested success a sub (0.00s)
✔ Nested success b (0.00s)
✔ Nested success b sub (0.00s)
✔ Nested success c (0.00s)
✔ Nested success c sub (0.00s)
✔ Nested success d (0.00s)
✔ Nested success d sub (0.00s)
x Nested with failure (0.00s)
✔ Nested with failure a (0.00s)
✔ Nested with failure a sub (0.00s)
✔ Nested with failure b (0.00s)
✔ Nested with failure b sub (0.00s)
x Nested with failure c (0.00s)
✔ Nested with failure d (0.00s)
✔ Nested with failure d sub (0.00s)
✔ Parallel the first (0.01s)
✔ Parallel the second (0.01s)
✔ Parallel the third (0.00s)
✔ Passed (0.00s)
✔ Passed with log (0.00s)
✔ Passed with stdout (0.00s)
✔ With stderr (0.00s)
✖ Failed (0.00s)
✖ Failed with stderr (0.00s)
✓ Nested success (0.00s)
✓ Nested success a (0.00s)
✓ Nested success a sub (0.00s)
✓ Nested success b (0.00s)
✓ Nested success b sub (0.00s)
✓ Nested success c (0.00s)
✓ Nested success c sub (0.00s)
✓ Nested success d (0.00s)
✓ Nested success d sub (0.00s)
✖ Nested with failure (0.00s)
✓ Nested with failure a (0.00s)
✓ Nested with failure a sub (0.00s)
✓ Nested with failure b (0.00s)
✓ Nested with failure b sub (0.00s)
✖ Nested with failure c (0.00s)
✓ Nested with failure d (0.00s)
✓ Nested with failure d sub (0.00s)
✓ Parallel the first (0.01s)
✓ Parallel the second (0.01s)
✓ Parallel the third (0.00s)
✓ Passed (0.00s)
✓ Passed with log (0.00s)
✓ Passed with stdout (0.00s)
∅ Skipped (0.00s)
∅ Skipped wit log (0.00s)
∅ Timeout (0.00s)
✓ With stderr (0.00s)

Loading

0 comments on commit 61b66b7

Please sign in to comment.