forked from go-check/check
/
reporter_test.go
114 lines (88 loc) · 3.95 KB
/
reporter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package check
/*************** xUnit writer tests *****************/
type XUnitTestSuite struct {
writer *xunitWriter
}
var _ = Suite(&XUnitTestSuite{})
func (s *XUnitTestSuite) SetUpTest(c *C) {
s.writer = newXunitWriter(nil, false)
}
func (s *XUnitTestSuite) TestSuccess(c *C) {
s.writer.WriteCallSuccess("PASS", c)
report, err := s.writer.GetReport()
c.Assert(err, IsNil)
match := "<testsuites>\n" +
" +<testsuite .*name=\"XUnitTestSuite\" .*tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\">\n" +
" +<testcase name=\"XUnitTestSuite\\.TestSuccess\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*</testcase>\n" +
" +</testsuite>\n" +
"</testsuites>"
c.Assert(string(report), Matches, match)
}
func (s *XUnitTestSuite) TestSkip(c *C) {
s.writer.WriteCallSkipped("SKIP", c)
report, err := s.writer.GetReport()
c.Assert(err, IsNil)
match := "<testsuites>\n" +
" +<testsuite .*name=\"XUnitTestSuite\" .*tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"1\">\n" +
" +<testcase name=\"XUnitTestSuite\\.TestSkip\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<skipped>true</skipped>\n" +
" +</testcase>\n" +
" +</testsuite>\n" +
"</testsuites>"
c.Assert(string(report), Matches, match)
}
func (s *XUnitTestSuite) TestFail(c *C) {
s.writer.WriteCallFailure("FAIL", c)
report, err := s.writer.GetReport()
c.Assert(err, IsNil)
match := "<testsuites>\n" +
" +<testsuite .*name=\"XUnitTestSuite\" .*tests=\"1\" failures=\"1\" errors=\"0\" skipped=\"0\">\n" +
" +<testcase name=\"XUnitTestSuite\\.TestFail\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<failure message=\"FAIL\" type=\"go.failure\"></failure>\n" +
" +</testcase>\n" +
" +</testsuite>\n" +
"</testsuites>"
c.Assert(string(report), Matches, match)
}
func (s *XUnitTestSuite) TestError(c *C) {
s.writer.WriteCallError("ERR", c)
report, err := s.writer.GetReport()
c.Assert(err, IsNil)
match := "<testsuites>\n" +
" +<testsuite .*name=\"XUnitTestSuite\" .*tests=\"1\" failures=\"0\" errors=\"1\" skipped=\"0\">\n" +
" +<testcase name=\"XUnitTestSuite\\.TestError\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<error message=\"ERR\" type=\"go.error\"></error>\n" +
" +</testcase>\n" +
" +</testsuite>\n" +
"</testsuites>"
c.Assert(string(report), Matches, match)
}
func (s *XUnitTestSuite) TestCombine(c *C) {
s.writer.WriteCallError("ERR", c)
s.writer.WriteCallFailure("FAIL", c)
s.writer.WriteCallSuccess("PASS", c)
s.writer.WriteCallSuccess("PASS", c)
s.writer.WriteCallFailure("FAIL", c)
s.writer.WriteCallSkipped("SKIP", c)
report, err := s.writer.GetReport()
c.Assert(err, IsNil)
match := "<testsuites>\n" +
" +<testsuite .*name=\"XUnitTestSuite\" .*tests=\"6\" failures=\"2\" errors=\"1\" skipped=\"1\">\n" +
" +<testcase name=\"XUnitTestSuite\\.TestCombine\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<error message=\"ERR\" type=\"go.error\"></error>\n" +
" +</testcase>\n" +
" +<testcase name=\"XUnitTestSuite\\.TestCombine\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<failure message=\"FAIL\" type=\"go.failure\"></failure>\n" +
" +</testcase>\n" +
" +<testcase name=\"XUnitTestSuite\\.TestCombine\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*</testcase>\n" +
" +<testcase name=\"XUnitTestSuite\\.TestCombine\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*</testcase>\n" +
" +<testcase name=\"XUnitTestSuite\\.TestCombine\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<failure message=\"FAIL\" type=\"go.failure\"></failure>\n" +
" +</testcase>\n" +
" +<testcase name=\"XUnitTestSuite\\.TestCombine\" classname=\"XUnitTestSuite\" .*file=\"[^\"]*reporter_test.go\".*>\n" +
" +<skipped>true</skipped>\n" +
" +</testcase>\n" +
" +</testsuite>\n" +
"</testsuites>"
c.Assert(string(report), Matches, match)
}