Skip to content

Commit

Permalink
Support for parsing time durations containing commas (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
vistaarjuneja authored Dec 21, 2020
1 parent 6efcf40 commit 061ee62
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package junit

import (
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -103,6 +104,9 @@ func ingestError(root xmlNode) Error {
}

func duration(t string) time.Duration {
// Remove commas for larger durations
t = strings.ReplaceAll(t, ",", "")

// Check if there was a valid decimal value
if s, err := strconv.ParseFloat(t, 64); err == nil {
return time.Duration(s*1000000) * time.Microsecond
Expand Down
4 changes: 2 additions & 2 deletions ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestExamplesInTheWild(t *testing.T) {
var testcase = Test{
Name: "testStdoutStderr",
Classname: "com.example.FooTest",
Duration: 9 * time.Millisecond,
Duration: 1234560 * time.Millisecond,
Status: StatusFailed,
Error: Error{
Type: "java.lang.AssertionError",
Expand All @@ -122,7 +122,7 @@ func TestExamplesInTheWild(t *testing.T) {
Properties: map[string]string{
"classname": "com.example.FooTest",
"name": "testStdoutStderr",
"time": "0.009",
"time": "1,234.56",
},
SystemOut: "Hello, World\n",
SystemErr: "I'm an error!\n",
Expand Down
2 changes: 1 addition & 1 deletion testdata/surefire.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<property name="sun.io.unicode.encoding" value="UnicodeBig"/>
<property name="java.class.version" value="55.0"/>
</properties>
<testcase name="testStdoutStderr" classname="com.example.FooTest" time="0.009">
<testcase name="testStdoutStderr" classname="com.example.FooTest" time="1,234.56">
<failure type="java.lang.AssertionError">java.lang.AssertionError
at com.example.FooTest.testStdoutStderr(FooTest.java:13)
</failure>
Expand Down

0 comments on commit 061ee62

Please sign in to comment.