Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
Beautify log output
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Pasztor committed May 20, 2021
1 parent 9c2d704 commit d4db25e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.5: Beautify log output

This release sorts the tests and displays a collapsible test result even if there are no logs to format the tests uniformly.

## 1.1.4: Bugfixes for test logger

This release fixes a number of bugs found when using the test logger for GitHub Actions output.
Expand Down
22 changes: 11 additions & 11 deletions test_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -60,8 +61,13 @@ func runWithGitHubActions(m *testing.M) int {
_ = tmpFile.Close()
_ = os.Remove(tmpFile.Name())

for _, testCase := range w.testCases {
writeTestcase(testCase)
var testCases []string
for testCaseName := range w.testCases {
testCases = append(testCases, testCaseName)
}
sort.Strings(testCases)
for _, testCaseName := range testCases {
writeTestcase(w.testCases[testCaseName])
}

return result
Expand Down Expand Up @@ -117,13 +123,11 @@ var logLevelConfig = map[LevelString]logOutputFormat{
}

func writeTestcase(c *testCase) {
if len(c.lines) > 0 {
fmt.Printf("::group::")
}
fmt.Printf("::group::")
if c.pass {
fmt.Printf("\033[0;32m✅ %s\033[0m (%s)\n", c.name, c.time)
} else {
fmt.Printf("::group::\033[0;31m❌ %s\033[0m (%s)\n", c.name, c.time)
fmt.Printf("\033[0;31m❌ %s\033[0m (%s)\n", c.name, c.time)
}
for _, line := range c.lines {
format := logLevelConfig[line.level]
Expand All @@ -137,9 +141,7 @@ func writeTestcase(c *testCase) {
line.line,
)
}
if len(c.lines) > 0 {
fmt.Printf("::endgroup::\n")
}
fmt.Printf("::endgroup::\n")
}

type gitHubActionsWriter struct {
Expand Down Expand Up @@ -204,8 +206,6 @@ func (g *gitHubActionsWriter) processFail(line string) string {
panic(err)
}
g.testCases[lastTestCase].time = t
writeTestcase(g.testCases[lastTestCase])
delete(g.testCases, lastTestCase)
lastTestCase = ""
return lastTestCase
}
Expand Down

0 comments on commit d4db25e

Please sign in to comment.