Skip to content

Commit

Permalink
Use local map of output
Browse files Browse the repository at this point in the history
So that output of passed tests is available
  • Loading branch information
dnephin committed Aug 25, 2023
1 parent 6989927 commit 3bd6d96
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
1 change: 0 additions & 1 deletion testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func (p *Package) addOutput(id int, output string) {
if strings.HasPrefix(output, "panic: ") {
p.panicked = true
}
// TODO: limit size of buffered test output
p.output[id] = append(p.output[id], output)
}

Expand Down
40 changes: 34 additions & 6 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,50 @@ func NewEventFormatter(out io.Writer, format string, formatOpts FormatOptions) E

func githubActionsFormat(out io.Writer) eventFormatterFunc {
buf := bufio.NewWriter(out)

type name struct {
Package string
Test string
}
output := map[name][]string{}

return func(event TestEvent, exec *Execution) error {
key := name{Package: event.Package, Test: event.Test}
// test case output
if event.Test != "" && event.Action == ActionOutput {
output[key] = append(output[key], event.Output)
return nil
}

// test case end event
if event.Test != "" && event.Action.IsTerminal() {
buf.WriteString("::group::")
testNameFormatTestEvent(buf, event)

pkg := exec.Package(event.Package)
tc := pkg.LastFailedByName(event.Test)
buf.WriteString(strings.TrimRight(pkg.Output(tc.ID), "\n"))

for _, item := range output[key] {
buf.WriteString(item)
}
buf.WriteString("::endgroup::\n")
delete(output, key)
return buf.Flush()
}

if err := testNameFormat(buf).Format(event, exec); err != nil {
return err
// package event
if !event.Action.IsTerminal() {
return nil
}

result := colorEvent(event)(strings.ToUpper(string(event.Action)))
pkg := exec.Package(event.Package)
if event.Action == ActionSkip || (event.Action == ActionPass && pkg.Total == 0) {
event.Action = ActionSkip
result = colorEvent(event)("EMPTY")
}

buf.WriteString("\n ")
buf.WriteString(result)
buf.WriteRune(' ')
buf.WriteString(packageLine(event, exec.Package(event.Package)))
return buf.Flush()
}
}

0 comments on commit 3bd6d96

Please sign in to comment.