1
// -*- Mode: Go; indent-tabs-mode: t -*-
4
* Copyright (C) 2015 Canonical Ltd
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 3 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
29
commonPattern = `(?U)%s\: \/.*: (.*)`
30
announcePattern = `(?U)\*\*\*\*\*\* Running (.*)\n`
31
successPatternSufix = `\s*\d*\.\d*s\n`
32
skipPatternSufix = `\s*\((.*)\)\n`
36
announceRegexp = regexp.MustCompile(announcePattern)
37
successRegexp = regexp.MustCompile(fmt.Sprintf(commonPattern, "PASS") + successPatternSufix)
38
failureRegexp = regexp.MustCompile(fmt.Sprintf(commonPattern, "FAIL") + "\n")
39
skipRegexp = regexp.MustCompile(fmt.Sprintf(commonPattern, "SKIP") + skipPatternSufix)
42
// ParserReporter is a type implementing io.Writer that
43
// parses the input data and sends the results to the Next
46
// The input data is expected to be of the form of the textual
47
// output of gocheck with verbose mode enabled, and the output
48
// will be of the form defined by the subunit format before
49
// the binary encoding. There are constants reflecting the
50
// expected patterns for this texts.
51
// Additionally, it doesn't take into account the SKIPs done
52
// from a SetUpTest method, due to the nature of the snappy test
53
// suite we are using those for resuming execution after a reboot
54
// and they shouldn't be reflected as skipped tests in the final
55
// output. For the same reason we use a special marker for the
57
type ParserReporter struct {
61
func (fr *ParserReporter) Write(data []byte) (n int, err error) {
64
if matches := announceRegexp.FindStringSubmatch(string(data)); len(matches) == 2 {
65
outputStr = fmt.Sprintf("test: %s\n", matches[1])
67
} else if matches := successRegexp.FindStringSubmatch(string(data)); len(matches) == 2 {
68
outputStr = fmt.Sprintf("success: %s\n", matches[1])
70
} else if matches := failureRegexp.FindStringSubmatch(string(data)); len(matches) == 2 {
71
outputStr = fmt.Sprintf("failure: %s\n", matches[1])
73
} else if matches := skipRegexp.FindStringSubmatch(string(data)); len(matches) == 3 {
74
outputStr = fmt.Sprintf("skip: %s [\n%s\n]\n", matches[1], matches[2])
77
outputByte := []byte(outputStr)
79
fr.Next.Write(outputByte)