Skip to content

Commit

Permalink
Refactor pkgPath+testname formatting for testname format
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Jun 20, 2020
1 parent a256bea commit 1263c8c
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,10 @@ func testNameFormat(event TestEvent, exec *Execution) (string, error) {
result := colorEvent(event)(strings.ToUpper(string(event.Action)))
formatTest := func() string {
pkgPath := RelativePackagePath(event.Package)
// If the package path isn't the current directory, we add
// a period to separate the test name and the package path.
// If it is the current directory, we don't show it at all.
// This prevents output like ..MyTest when the test
// is in the current directory.
if pkgPath == "." {
pkgPath = ""
} else {
pkgPath += "."
}
return fmt.Sprintf("%s %s%s %s\n",

return fmt.Sprintf("%s %s %s\n",
result,
pkgPath,
event.Test,
joinPkgToTestName(pkgPath, event.Test),
event.ElapsedFormatted())
}

Expand Down Expand Up @@ -89,6 +79,18 @@ func testNameFormat(event TestEvent, exec *Execution) (string, error) {
return "", nil
}

// joinPkgToTestName for formatting.
// If the package path isn't the current directory, we add a period to separate
// the test name and the package path. If it is the current directory, we don't
// show it at all. This prevents output like ..MyTest when the test is in the
// current directory.
func joinPkgToTestName(pkg string, test string) string {
if pkg == "." {
return test
}
return pkg + "." + test
}

// isPkgFailureOutput returns true if the event is package output, and the output
// doesn't match any of the expected framing messages. Events which match this
// pattern should be package-level failures (ex: exit(1) or panic in an init() or
Expand Down

0 comments on commit 1263c8c

Please sign in to comment.