~mvo/snappy/lp1480248-test-reenable

« back to all changes in this revision

Viewing changes to _integration-tests/testutils/report/parser.go

  • Committer: Michael Vogt
  • Date: 2015-10-16 16:51:10 UTC
  • mfrom: (640.2.136 snappy)
  • Revision ID: michael.vogt@ubuntu.com-20151016165110-djpd75rc5m0roe7c
mergedĀ lp:snappy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: Go; indent-tabs-mode: t -*-
 
2
 
 
3
/*
 
4
 * Copyright (C) 2015 Canonical Ltd
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 *
 
18
 */
 
19
 
 
20
package report
 
21
 
 
22
import (
 
23
        "fmt"
 
24
        "io"
 
25
        "regexp"
 
26
)
 
27
 
 
28
const (
 
29
        commonPattern       = `(?U)%s\: \/.*: (.*)`
 
30
        announcePattern     = `(?U)\*\*\*\*\*\* Running (.*)\n`
 
31
        successPatternSufix = `\s*\d*\.\d*s\n`
 
32
        skipPatternSufix    = `\s*\((.*)\)\n`
 
33
)
 
34
 
 
35
var (
 
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)
 
40
)
 
41
 
 
42
// ParserReporter is a type implementing io.Writer that
 
43
// parses the input data and sends the results to the Next
 
44
// reporter
 
45
//
 
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
 
56
// test's announce.
 
57
type ParserReporter struct {
 
58
        Next io.Writer
 
59
}
 
60
 
 
61
func (fr *ParserReporter) Write(data []byte) (n int, err error) {
 
62
        var outputStr string
 
63
 
 
64
        if matches := announceRegexp.FindStringSubmatch(string(data)); len(matches) == 2 {
 
65
                outputStr = fmt.Sprintf("test: %s\n", matches[1])
 
66
 
 
67
        } else if matches := successRegexp.FindStringSubmatch(string(data)); len(matches) == 2 {
 
68
                outputStr = fmt.Sprintf("success: %s\n", matches[1])
 
69
 
 
70
        } else if matches := failureRegexp.FindStringSubmatch(string(data)); len(matches) == 2 {
 
71
                outputStr = fmt.Sprintf("failure: %s\n", matches[1])
 
72
 
 
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])
 
75
        }
 
76
 
 
77
        outputByte := []byte(outputStr)
 
78
        n = len(outputByte)
 
79
        fr.Next.Write(outputByte)
 
80
        return
 
81
}