Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse test duration correctly for >= go 1.5 #438

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/server/parser/package_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ var expectedExampleFunctions = contract.PackageResult{

const inputGolang15 = `
=== RUN Golang15
--- PASS: Golang15 (0.00s)
--- PASS: Golang15 (0.01s)
PASS
ok github.com/smartystreets/goconvey/webserver/examples 0.008s
`
Expand All @@ -781,7 +781,7 @@ var expectedGolang15 = contract.PackageResult{
TestResults: []contract.TestResult{
contract.TestResult{
TestName: "Golang15",
Elapsed: 0.00,
Elapsed: 0.01,
Passed: true,
File: "",
Line: 0,
Expand Down
9 changes: 8 additions & 1 deletion web/server/parser/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ import (
// parseTestFunctionDuration parses the duration in seconds as a float64
// from a line of go test output that looks something like this:
// --- PASS: TestOldSchool_PassesWithMessage (0.03 seconds)
//
// For Go1.5 and greater the test output looks something like this:
// --- PASS: TestOldSchool_PassesWithMessage (0.03s)
func parseTestFunctionDuration(line string) float64 {
line = strings.Replace(line, "(", "", 1)
fields := strings.Split(line, " ")
return parseDurationInSeconds(fields[3]+"s", 2)
timeStr := fields[3]+"s"
if strings.HasSuffix(timeStr, "s)s") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "s)s" ? wouldn't it be "s)" ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The < go 1.5 case is treated as the default and so in the previous line we have

timeStr := fields[3]+"s"

For < go 1.5 a line like

--- PASS: TestOldSchool_PassesWithMessage (0.03 seconds)

would have fields[3] == 0.03 and timeStr == 0.03s

For >= go 1.5 with input like

--- PASS: TestOldSchool_PassesWithMessage (0.03s)

we'd have fields[3] == 0.03s) and timeStr == 0.03s)s

timeStr = timeStr[:len(timeStr)-2]
}
return parseDurationInSeconds(timeStr, 2)
}

func parseDurationInSeconds(raw string, precision int) float64 {
Expand Down