From 15422cf504f9dc030386499a5c68053a38763e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Stemmer?= Date: Mon, 24 Jul 2017 21:44:35 +0100 Subject: [PATCH] Add support for -coverpkg output Fixes #59 --- go-junit-report_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ parser/parser.go | 4 ++-- tests/18-coverpkg.txt | 12 ++++++++++++ tests/18-report.xml | 18 ++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/18-coverpkg.txt create mode 100644 tests/18-report.xml diff --git a/go-junit-report_test.go b/go-junit-report_test.go index 3aacf16..be0e416 100644 --- a/go-junit-report_test.go +++ b/go-junit-report_test.go @@ -642,6 +642,46 @@ var testCases = []TestCase{ }, }, }, + { + name: "18-coverpkg.txt", + reportName: "18-report.xml", + report: &parser.Report{ + Packages: []parser.Package{ + { + Name: "package1/foo", + Time: 400, + Tests: []*parser.Test{ + { + Name: "TestA", + Time: 100, + Result: parser.PASS, + Output: []string{}, + }, + { + Name: "TestB", + Time: 300, + Result: parser.PASS, + Output: []string{}, + }, + }, + CoveragePct: "10.0", + }, + { + Name: "package2/bar", + Time: 4200, + Tests: []*parser.Test{ + { + Name: "TestC", + Time: 4200, + Result: parser.PASS, + Output: []string{}, + }, + }, + CoveragePct: "99.8", + }, + }, + }, + }, } func TestParser(t *testing.T) { diff --git a/parser/parser.go b/parser/parser.go index bf3a123..5fe7a37 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -41,8 +41,8 @@ type Test struct { var ( regexStatus = regexp.MustCompile(`^\s*--- (PASS|FAIL|SKIP): (.+) \((\d+\.\d+)(?: seconds|s)\)$`) - regexCoverage = regexp.MustCompile(`^coverage:\s+(\d+\.\d+)%\s+of\s+statements$`) - regexResult = regexp.MustCompile(`^(ok|FAIL)\s+([^ ]+)\s+(?:(\d+\.\d+)s|(\[\w+ failed]))(?:\s+coverage:\s+(\d+\.\d+)%\sof\sstatements)?$`) + regexCoverage = regexp.MustCompile(`^coverage:\s+(\d+\.\d+)%\s+of\s+statements(?:\sin\s.+)?$`) + regexResult = regexp.MustCompile(`^(ok|FAIL)\s+([^ ]+)\s+(?:(\d+\.\d+)s|(\[\w+ failed]))(?:\s+coverage:\s+(\d+\.\d+)%\sof\sstatements(?:\sin\s.+)?)?$`) regexOutput = regexp.MustCompile(`( )*\t(.*)`) ) diff --git a/tests/18-coverpkg.txt b/tests/18-coverpkg.txt new file mode 100644 index 0000000..1b92aeb --- /dev/null +++ b/tests/18-coverpkg.txt @@ -0,0 +1,12 @@ +=== RUN TestA +--- PASS: TestA (0.10 seconds) +=== RUN TestB +--- PASS: TestB (0.30 seconds) +PASS +coverage: 10% of statements in fmt, encoding/xml +ok package1/foo 0.400s coverage: 10.0% of statements in fmt, encoding/xml +=== RUN TestC +--- PASS: TestC (4.20 seconds) +PASS +coverage: 99.8% of statements in fmt, encoding/xml +ok package2/bar 4.200s coverage: 99.8% of statements in fmt, encoding/xml diff --git a/tests/18-report.xml b/tests/18-report.xml new file mode 100644 index 0000000..a78497c --- /dev/null +++ b/tests/18-report.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +