mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 21:18:08 -05:00
Merge pull request #7 from ikarishinjieva/feature/no_xml_header
add flag -no-xml-header
This commit is contained in:
commit
18ee6df2f2
@ -1,11 +1,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var noXmlHeader bool
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.BoolVar(&noXmlHeader, "no-xml-header", false, "do not print xml header")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
// Read input
|
// Read input
|
||||||
report, err := Parse(os.Stdin)
|
report, err := Parse(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -14,7 +23,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write xml
|
// Write xml
|
||||||
err = JUnitReportXML(report, os.Stdout)
|
err = JUnitReportXML(report, noXmlHeader, os.Stdout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error writing XML: %s\n", err)
|
fmt.Printf("Error writing XML: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -11,9 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
name string
|
name string
|
||||||
reportName string
|
reportName string
|
||||||
report *Report
|
report *Report
|
||||||
|
noXmlHeader bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var testCases []TestCase = []TestCase{
|
var testCases []TestCase = []TestCase{
|
||||||
@ -128,6 +129,33 @@ var testCases []TestCase = []TestCase{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "05-no_xml_header.txt",
|
||||||
|
reportName: "05-report.xml",
|
||||||
|
report: &Report{
|
||||||
|
Packages: []Package{
|
||||||
|
{
|
||||||
|
Name: "package/name",
|
||||||
|
Time: 160,
|
||||||
|
Tests: []Test{
|
||||||
|
{
|
||||||
|
Name: "TestOne",
|
||||||
|
Time: 60,
|
||||||
|
Result: PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TestTwo",
|
||||||
|
Time: 100,
|
||||||
|
Result: PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
noXmlHeader: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParser(t *testing.T) {
|
func TestParser(t *testing.T) {
|
||||||
@ -200,7 +228,7 @@ func TestJUnitFormatter(t *testing.T) {
|
|||||||
|
|
||||||
var junitReport bytes.Buffer
|
var junitReport bytes.Buffer
|
||||||
|
|
||||||
if err = JUnitReportXML(testCase.report, &junitReport); err != nil {
|
if err = JUnitReportXML(testCase.report, testCase.noXmlHeader, &junitReport); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ func NewJUnitProperty(name, value string) JUnitProperty {
|
|||||||
|
|
||||||
// JUnitReportXML writes a junit xml representation of the given report to w
|
// JUnitReportXML writes a junit xml representation of the given report to w
|
||||||
// in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd
|
// in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd
|
||||||
func JUnitReportXML(report *Report, w io.Writer) error {
|
func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error {
|
||||||
suites := []JUnitTestSuite{}
|
suites := []JUnitTestSuite{}
|
||||||
|
|
||||||
// convert Report to JUnit test suites
|
// convert Report to JUnit test suites
|
||||||
@ -111,7 +111,9 @@ func JUnitReportXML(report *Report, w io.Writer) error {
|
|||||||
|
|
||||||
writer := bufio.NewWriter(w)
|
writer := bufio.NewWriter(w)
|
||||||
|
|
||||||
writer.WriteString(xml.Header)
|
if !noXmlHeader {
|
||||||
|
writer.WriteString(xml.Header)
|
||||||
|
}
|
||||||
writer.Write(bytes)
|
writer.Write(bytes)
|
||||||
writer.WriteByte('\n')
|
writer.WriteByte('\n')
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
|
6
tests/05-no_xml_header.txt
Normal file
6
tests/05-no_xml_header.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
=== RUN TestOne
|
||||||
|
--- PASS: TestOne (0.06s)
|
||||||
|
=== RUN TestTwo
|
||||||
|
--- PASS: TestTwo (0.10s)
|
||||||
|
PASS
|
||||||
|
ok package/name 0.160s
|
7
tests/05-report.xml
Normal file
7
tests/05-report.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<testsuite tests="2" failures="0" time="0.160" name="package/name">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="name" name="TestOne" time="0.060"></testcase>
|
||||||
|
<testcase classname="name" name="TestTwo" time="0.100"></testcase>
|
||||||
|
</testsuite>
|
Loading…
x
Reference in New Issue
Block a user