Skip to content

Commit

Permalink
Support for capturing stdout and stderr from test cases (joshdk#27) (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Bergstrom <[email protected]>
  • Loading branch information
thecapdan and rwbergstrom committed Dec 30, 2020
1 parent 918c066 commit 5eb04b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func ingestTestcase(root xmlNode) Test {
case "error":
test.Error = ingestError(node)
test.Status = StatusError
case "system-out":
test.SystemOut = string(node.Content)
case "system-err":
test.SystemErr = string(node.Content)
}
}

Expand Down
12 changes: 10 additions & 2 deletions ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ import (
"github.com/stretchr/testify/require"
)

func TestInjest(t *testing.T) {
func TestIngest(t *testing.T) {
tests := []struct {
title string
input []byte
expected []Suite
}{
{
title: "xml input",
input: []byte(`<testsuites><testsuite errors="0" failures="1" file="Foo.java"><testcase name="unit tests" file="Foo.java"/></testsuite></testsuites>`),
input: []byte(`<testsuites><testsuite errors="0" failures="1" file="Foo.java">
<testcase name="unit tests" file="Foo.java">
<system-out><![CDATA[Hello, World]]></system-out>
<system-err><![CDATA[I'm an error!]]></system-err>
</testcase>
</testsuite>
</testsuites>`),
expected: []Suite{
{
Tests: []Test{
Expand All @@ -31,6 +37,8 @@ func TestInjest(t *testing.T) {
"file": "Foo.java",
"name": "unit tests",
},
SystemOut: "Hello, World",
SystemErr: "I'm an error!",
},
},
Totals: Totals{
Expand Down
8 changes: 8 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ type Test struct {
// Additional properties from XML node attributes.
// Some tools use them to store additional information about test location.
Properties map[string]string `json:"properties" yaml:"properties"`

// SystemOut is textual output for the test case. Usually output that is
// written to stdout.
SystemOut string `json:"stdout,omitempty" yaml:"stdout,omitempty"`

// SystemErr is textual error output for the test case. Usually output that is
// written to stderr.
SystemErr string `json:"stderr,omitempty" yaml:"stderr,omitempty"`
}

// Error represents an erroneous test result.
Expand Down

0 comments on commit 5eb04b8

Please sign in to comment.