mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-06 21:48:08 -05:00
Merge pull request #8 from ikarishinjieva:feature/support_compiled_test
Conflicts: go-junit-report_test.go
This commit is contained in:
commit
054e4c1b39
@ -7,16 +7,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var noXmlHeader bool
|
var noXmlHeader bool
|
||||||
|
var packageName string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.BoolVar(&noXmlHeader, "no-xml-header", false, "do not print xml header")
|
flag.BoolVar(&noXmlHeader, "no-xml-header", false, "do not print xml header")
|
||||||
|
flag.StringVar(&packageName, "package-name", "", "specify a package name (compiled test have no package name in output)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Read input
|
// Read input
|
||||||
report, err := Parse(os.Stdin)
|
report, err := Parse(os.Stdin, packageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error reading input: %s\n", err)
|
fmt.Printf("Error reading input: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -15,6 +15,7 @@ type TestCase struct {
|
|||||||
reportName string
|
reportName string
|
||||||
report *Report
|
report *Report
|
||||||
noXmlHeader bool
|
noXmlHeader bool
|
||||||
|
packageName string
|
||||||
}
|
}
|
||||||
|
|
||||||
var testCases []TestCase = []TestCase{
|
var testCases []TestCase = []TestCase{
|
||||||
@ -206,6 +207,33 @@ var testCases []TestCase = []TestCase{
|
|||||||
},
|
},
|
||||||
noXmlHeader: true,
|
noXmlHeader: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "07-compiled_test.txt",
|
||||||
|
reportName: "07-report.xml",
|
||||||
|
report: &Report{
|
||||||
|
Packages: []Package{
|
||||||
|
{
|
||||||
|
Name: "test/package",
|
||||||
|
Time: 160,
|
||||||
|
Tests: []Test{
|
||||||
|
{
|
||||||
|
Name: "TestOne",
|
||||||
|
Time: 60,
|
||||||
|
Result: PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TestTwo",
|
||||||
|
Time: 100,
|
||||||
|
Result: PASS,
|
||||||
|
Output: []string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
packageName: "test/package",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParser(t *testing.T) {
|
func TestParser(t *testing.T) {
|
||||||
@ -217,7 +245,7 @@ func TestParser(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := Parse(file)
|
report, err := Parse(file, testCase.packageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing: %s", err)
|
t.Fatalf("error parsing: %s", err)
|
||||||
}
|
}
|
||||||
|
22
parser.go
22
parser.go
@ -38,7 +38,7 @@ var (
|
|||||||
regexResult = regexp.MustCompile(`^(ok|FAIL)\s+(.+)\s(\d+\.\d+)s$`)
|
regexResult = regexp.MustCompile(`^(ok|FAIL)\s+(.+)\s(\d+\.\d+)s$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func Parse(r io.Reader) (*Report, error) {
|
func Parse(r io.Reader, specifiedPackageName string) (*Report, error) {
|
||||||
reader := bufio.NewReader(r)
|
reader := bufio.NewReader(r)
|
||||||
|
|
||||||
report := &Report{make([]Package, 0)}
|
report := &Report{make([]Package, 0)}
|
||||||
@ -46,6 +46,9 @@ func Parse(r io.Reader) (*Report, error) {
|
|||||||
// keep track of tests we find
|
// keep track of tests we find
|
||||||
tests := make([]Test, 0)
|
tests := make([]Test, 0)
|
||||||
|
|
||||||
|
// sum of tests' time, use this if current test has no result line (when it is compiled test)
|
||||||
|
testsTime := 0
|
||||||
|
|
||||||
// current test
|
// current test
|
||||||
var test *Test
|
var test *Test
|
||||||
|
|
||||||
@ -85,6 +88,7 @@ func Parse(r io.Reader) (*Report, error) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tests = make([]Test, 0)
|
tests = make([]Test, 0)
|
||||||
|
testsTime = 0
|
||||||
} else if test != nil {
|
} else if test != nil {
|
||||||
if matches := regexStatus.FindStringSubmatch(line); len(matches) == 4 {
|
if matches := regexStatus.FindStringSubmatch(line); len(matches) == 4 {
|
||||||
// test status
|
// test status
|
||||||
@ -97,7 +101,9 @@ func Parse(r io.Reader) (*Report, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test.Name = matches[2]
|
test.Name = matches[2]
|
||||||
test.Time = parseTime(matches[3]) * 10
|
testTime := parseTime(matches[3]) * 10
|
||||||
|
test.Time = testTime
|
||||||
|
testsTime += testTime
|
||||||
} else if strings.HasPrefix(line, "\t") {
|
} else if strings.HasPrefix(line, "\t") {
|
||||||
// test output
|
// test output
|
||||||
test.Output = append(test.Output, line[1:])
|
test.Output = append(test.Output, line[1:])
|
||||||
@ -105,6 +111,18 @@ func Parse(r io.Reader) (*Report, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if test != nil {
|
||||||
|
tests = append(tests, *test)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tests) > 0 { //no result line found
|
||||||
|
report.Packages = append(report.Packages, Package{
|
||||||
|
Name: specifiedPackageName,
|
||||||
|
Time: testsTime,
|
||||||
|
Tests: tests,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return report, nil
|
return report, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
tests/07-compiled_test.txt
Normal file
5
tests/07-compiled_test.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
=== RUN TestOne
|
||||||
|
--- PASS: TestOne (0.06s)
|
||||||
|
=== RUN TestTwo
|
||||||
|
--- PASS: TestTwo (0.10s)
|
||||||
|
PASS
|
10
tests/07-report.xml
Normal file
10
tests/07-report.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite tests="2" failures="0" time="0.160" name="test/package">
|
||||||
|
<properties>
|
||||||
|
<property name="go.version" value="1.0"></property>
|
||||||
|
</properties>
|
||||||
|
<testcase classname="package" name="TestOne" time="0.060"></testcase>
|
||||||
|
<testcase classname="package" name="TestTwo" time="0.100"></testcase>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
Loading…
x
Reference in New Issue
Block a user