Skip to content

Commit 061ee62

Browse files
Support for parsing time durations containing commas (#39)
1 parent 6efcf40 commit 061ee62

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

ingest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package junit
66

77
import (
88
"strconv"
9+
"strings"
910
"time"
1011
)
1112

@@ -103,6 +104,9 @@ func ingestError(root xmlNode) Error {
103104
}
104105

105106
func duration(t string) time.Duration {
107+
// Remove commas for larger durations
108+
t = strings.ReplaceAll(t, ",", "")
109+
106110
// Check if there was a valid decimal value
107111
if s, err := strconv.ParseFloat(t, 64); err == nil {
108112
return time.Duration(s*1000000) * time.Microsecond

ingest_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestExamplesInTheWild(t *testing.T) {
113113
var testcase = Test{
114114
Name: "testStdoutStderr",
115115
Classname: "com.example.FooTest",
116-
Duration: 9 * time.Millisecond,
116+
Duration: 1234560 * time.Millisecond,
117117
Status: StatusFailed,
118118
Error: Error{
119119
Type: "java.lang.AssertionError",
@@ -122,7 +122,7 @@ func TestExamplesInTheWild(t *testing.T) {
122122
Properties: map[string]string{
123123
"classname": "com.example.FooTest",
124124
"name": "testStdoutStderr",
125-
"time": "0.009",
125+
"time": "1,234.56",
126126
},
127127
SystemOut: "Hello, World\n",
128128
SystemErr: "I'm an error!\n",

testdata/surefire.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<property name="sun.io.unicode.encoding" value="UnicodeBig"/>
4848
<property name="java.class.version" value="55.0"/>
4949
</properties>
50-
<testcase name="testStdoutStderr" classname="com.example.FooTest" time="0.009">
50+
<testcase name="testStdoutStderr" classname="com.example.FooTest" time="1,234.56">
5151
<failure type="java.lang.AssertionError">java.lang.AssertionError
5252
at com.example.FooTest.testStdoutStderr(FooTest.java:13)
5353
</failure>

0 commit comments

Comments
 (0)