Merge pull request #8 from ikarishinjieva:feature/support_compiled_test

Conflicts:
	go-junit-report_test.go
This commit is contained in:
Joël Stemmer 2015-02-04 11:08:45 +01:00
commit 054e4c1b39
5 changed files with 67 additions and 4 deletions

View File

@ -7,16 +7,18 @@ import (
)
var noXmlHeader bool
var packageName string
func init() {
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() {
flag.Parse()
// Read input
report, err := Parse(os.Stdin)
report, err := Parse(os.Stdin, packageName)
if err != nil {
fmt.Printf("Error reading input: %s\n", err)
os.Exit(1)

View File

@ -15,6 +15,7 @@ type TestCase struct {
reportName string
report *Report
noXmlHeader bool
packageName string
}
var testCases []TestCase = []TestCase{
@ -206,6 +207,33 @@ var testCases []TestCase = []TestCase{
},
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) {
@ -217,7 +245,7 @@ func TestParser(t *testing.T) {
t.Fatal(err)
}
report, err := Parse(file)
report, err := Parse(file, testCase.packageName)
if err != nil {
t.Fatalf("error parsing: %s", err)
}

View File

@ -38,7 +38,7 @@ var (
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)
report := &Report{make([]Package, 0)}
@ -46,6 +46,9 @@ func Parse(r io.Reader) (*Report, error) {
// keep track of tests we find
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
var test *Test
@ -85,6 +88,7 @@ func Parse(r io.Reader) (*Report, error) {
})
tests = make([]Test, 0)
testsTime = 0
} else if test != nil {
if matches := regexStatus.FindStringSubmatch(line); len(matches) == 4 {
// test status
@ -97,7 +101,9 @@ func Parse(r io.Reader) (*Report, error) {
}
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") {
// test output
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
}

View 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
View 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>