Skip to content

Commit e7a601d

Browse files
rwbergstromjoshdk
authored andcommitted
Support for capturing stdout and stderr from test cases (#27)
1 parent b247655 commit e7a601d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ingest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func ingestTestcase(root xmlNode) Test {
8080
case "error":
8181
test.Error = ingestError(node)
8282
test.Status = StatusError
83+
case "system-out":
84+
test.SystemOut = string(node.Content)
85+
case "system-err":
86+
test.SystemErr = string(node.Content)
8387
}
8488
}
8589

ingest_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
func TestInjest(t *testing.T) {
14+
func TestIngest(t *testing.T) {
1515
tests := []struct {
1616
title string
1717
input []byte
1818
expected []Suite
1919
}{
2020
{
2121
title: "xml input",
22-
input: []byte(`<testsuite errors="0" failures="1" file="Foo.java"><testcase name="unit tests" file="Foo.java"/></testsuite>`),
22+
input: []byte(`<testsuite errors="0" failures="1" file="Foo.java">
23+
<testcase name="unit tests" file="Foo.java">
24+
<system-out><![CDATA[Hello, World]]></system-out>
25+
<system-err><![CDATA[I'm an error!]]></system-err>
26+
</testcase>
27+
</testsuite>`),
2328
expected: []Suite{
2429
{
2530
Tests: []Test{
@@ -30,6 +35,8 @@ func TestInjest(t *testing.T) {
3035
"file": "Foo.java",
3136
"name": "unit tests",
3237
},
38+
SystemOut: "Hello, World",
39+
SystemErr: "I'm an error!",
3340
},
3441
},
3542
Totals: Totals{

types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ type Test struct {
129129
// Additional properties from XML node attributes.
130130
// Some tools use them to store additional information about test location.
131131
Properties map[string]string `json:"properties" yaml:"properties"`
132+
133+
// SystemOut is textual output for the test case. Usually output that is
134+
// written to stdout.
135+
SystemOut string `json:"stdout,omitempty" yaml:"stdout,omitempty"`
136+
137+
// SystemErr is textual error output for the test case. Usually output that is
138+
// written to stderr.
139+
SystemErr string `json:"stderr,omitempty" yaml:"stderr,omitempty"`
132140
}
133141

134142
// Error represents an erroneous test result.

0 commit comments

Comments
 (0)