File: reporter_test.go

package info (click to toggle)
golang-check.v1 0.0%2Bgit20180628.788fd78-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 288 kB
  • sloc: makefile: 2
file content (159 lines) | stat: -rw-r--r-- 4,169 bytes parent folder | download | duplicates (5)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package check_test

import (
	"fmt"
	"path/filepath"
	"runtime"

	. "gopkg.in/check.v1"
)

var _ = Suite(&reporterS{})

type reporterS struct {
	testFile string
}

func (s *reporterS) SetUpSuite(c *C) {
	_, fileName, _, ok := runtime.Caller(0)
	c.Assert(ok, Equals, true)
	s.testFile = filepath.Base(fileName)
}

func (s *reporterS) TestWrite(c *C) {
	testString := "test string"
	output := String{}

	dummyStream := true
	dummyVerbose := true
	o := NewOutputWriter(&output, dummyStream, dummyVerbose)

	o.Write([]byte(testString))
	c.Assert(output.value, Equals, testString)
}

func (s *reporterS) TestWriteCallStartedWithStreamFlag(c *C) {
	testLabel := "test started label"
	stream := true
	output := String{}

	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)

	o.WriteCallStarted(testLabel, c)
	expected := fmt.Sprintf("%s: %s:\\d+: %s\n", testLabel, s.testFile, c.TestName())
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallStartedWithoutStreamFlag(c *C) {
	stream := false
	output := String{}

	dummyLabel := "dummy"
	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)

	o.WriteCallStarted(dummyLabel, c)
	c.Assert(output.value, Equals, "")
}

func (s *reporterS) TestWriteCallProblemWithStreamFlag(c *C) {
	testLabel := "test problem label"
	stream := true
	output := String{}

	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)

	o.WriteCallProblem(testLabel, c)
	expected := fmt.Sprintf("%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName())
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallProblemWithoutStreamFlag(c *C) {
	testLabel := "test problem label"
	stream := false
	output := String{}

	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)

	o.WriteCallProblem(testLabel, c)
	expected := fmt.Sprintf(""+
		"\n"+
		"----------------------------------------------------------------------\n"+
		"%s: %s:\\d+: %s\n\n", testLabel, s.testFile, c.TestName())
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallProblemWithoutStreamFlagWithLog(c *C) {
	testLabel := "test problem label"
	testLog := "test log"
	stream := false
	output := String{}

	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)

	c.Log(testLog)
	o.WriteCallProblem(testLabel, c)
	expected := fmt.Sprintf(""+
		"\n"+
		"----------------------------------------------------------------------\n"+
		"%s: %s:\\d+: %s\n\n%s\n", testLabel, s.testFile, c.TestName(), testLog)
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallSuccessWithStreamFlag(c *C) {
	testLabel := "test success label"
	stream := true
	output := String{}

	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)

	o.WriteCallSuccess(testLabel, c)
	expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n\n", testLabel, s.testFile, c.TestName())
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallSuccessWithStreamFlagAndReason(c *C) {
	testLabel := "test success label"
	testReason := "test skip reason"
	stream := true
	output := String{}

	dummyVerbose := true
	o := NewOutputWriter(&output, stream, dummyVerbose)
	c.FakeSkip(testReason)

	o.WriteCallSuccess(testLabel, c)
	expected := fmt.Sprintf("%s: %s:\\d+: %s \\(%s\\)\t\\d\\.\\d+s\n\n",
		testLabel, s.testFile, c.TestName(), testReason)
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithVerboseFlag(c *C) {
	testLabel := "test success label"
	stream := false
	verbose := true
	output := String{}

	o := NewOutputWriter(&output, stream, verbose)

	o.WriteCallSuccess(testLabel, c)
	expected := fmt.Sprintf("%s: %s:\\d+: %s\t\\d\\.\\d+s\n", testLabel, s.testFile, c.TestName())
	c.Assert(output.value, Matches, expected)
}

func (s *reporterS) TestWriteCallSuccessWithoutStreamFlagWithoutVerboseFlag(c *C) {
	testLabel := "test success label"
	stream := false
	verbose := false
	output := String{}

	o := NewOutputWriter(&output, stream, verbose)

	o.WriteCallSuccess(testLabel, c)
	c.Assert(output.value, Equals, "")
}