Debian Codegraph @

helpers.go

raw symbols SCIP
1 package checkscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
5 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
6 "timescip-go gomod github.com/golang/go/src go1.13 time/"
7 )
8
9 // TestName returns the current test name in the form "SuiteName.TestName"
10 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) TestNamescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#TestName().() string {
11 return c.testNamescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#testName.
12 }
13
14 // -----------------------------------------------------------------------
15 // Basic succeeding/failing logic.
16
17 // Failed returns whether the currently running test has already failed.
18 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Failedscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Failed().() bool {
19 return c.statusscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#status().() == failedStscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/failedSt.
20 }
21
22 // Fail marks the currently running test as failed.
23 //
24 // Something ought to have been previously logged so the developer can tell
25 // what went wrong. The higher level helper functions will fail the test
26 // and do the logging properly.
27 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().() {
28 c.setStatusscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#setStatus().(failedStscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/failedSt.)
29 }
30
31 // FailNow marks the currently running test as failed and stops running it.
32 // Something ought to have been previously logged so the developer can tell
33 // what went wrong. The higher level helper functions will fail the test
34 // and do the logging properly.
35 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) FailNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#FailNow().() {
36 c.Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().()
37 c.stopNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#stopNow().()
38 }
39
40 // Succeed marks the currently running test as succeeded, undoing any
41 // previous failures.
42 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Succeedscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Succeed().() {
43 c.setStatusscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#setStatus().(succeededStscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/succeededSt.)
44 }
45
46 // SucceedNow marks the currently running test as succeeded, undoing any
47 // previous failures, and stops running the test.
48 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) SucceedNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#SucceedNow().() {
49 c.Succeedscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Succeed().()
50 c.stopNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#stopNow().()
51 }
52
53 // ExpectFailure informs that the running test is knowingly broken for
54 // the provided reason. If the test does not fail, an error will be reported
55 // to raise attention to this fact. This method is useful to temporarily
56 // disable tests which cover well known problems until a better time to
57 // fix the problem is found, without forgetting about the fact that a
58 // failure still exists.
59 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) ExpectFailurescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#ExpectFailure().(reason string) {
60 if reason == "" {
61 panic("Missing reason why the test is expected to fail")
62 }
63 c.mustFailscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#mustFail. = true
64 c.reasonscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#reason. = reason
65 }
66
67 // Skip skips the running test for the provided reason. If run from within
68 // SetUpTest, the individual test being set up will be skipped, and if run
69 // from within SetUpSuite, the whole suite is skipped.
70 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Skipscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Skip().(reason string) {
71 if reason == "" {
72 panic("Missing reason why the test is being skipped")
73 }
74 c.reasonscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#reason. = reason
75 c.setStatusscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#setStatus().(skippedStscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/skippedSt.)
76 c.stopNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#stopNow().()
77 }
78
79 // Parallel will mark the test run parallel within a test suite.
80 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Parallelscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Parallel().() {
81 c.parallelscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#parallel. <- c
82 }
83
84 // -----------------------------------------------------------------------
85 // Basic logging.
86
87 // GetTestLog returns the current test error output.
88 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) GetTestLogscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#GetTestLog().() string {
89 return c.logbscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logb..Stringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/logger#String().()
90 }
91
92 // Log logs some information into the test error output.
93 // The provided arguments are assembled together into a string with fmt.Sprint.
94 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Logscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Log().(args ...interface{}) {
95 c.logscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#log().(args...)
96 }
97
98 // Log logs some information into the test error output.
99 // The provided arguments are assembled together into a string with fmt.Sprintf.
100 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Logfscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Logf().(format string, args ...interface{}) {
101 c.logfscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logf().(format, args...)
102 }
103
104 // Output enables *C to be used as a logger in functions that require only
105 // the minimum interface of *log.Logger.
106 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Outputscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Output().(calldepth int, s string) error {
107 d := timescip-go gomod github.com/golang/go/src go1.13 time/.Nowscip-go gomod github.com/golang/go/src go1.13 time/Now().().Subscip-go gomod github.com/golang/go/src go1.13 time/Time#Sub().(c.startTimescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#startTime.)
108 msec := d / timescip-go gomod github.com/golang/go/src go1.13 time/.Millisecondscip-go gomod github.com/golang/go/src go1.13 time/Millisecond.
109 sec := d / timescip-go gomod github.com/golang/go/src go1.13 time/.Secondscip-go gomod github.com/golang/go/src go1.13 time/Second.
110 min := d / timescip-go gomod github.com/golang/go/src go1.13 time/.Minutescip-go gomod github.com/golang/go/src go1.13 time/Minute.
111
112 c.Logfscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Logf().("[LOG] %d:%02d.%03d %s", min, sec%60, msec%1000, s)
113 return nil
114 }
115
116 // Error logs an error into the test error output and marks the test as failed.
117 // The provided arguments are assembled together into a string with fmt.Sprint.
118 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Errorscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Error().(args ...interface{}) {
119 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(1)
120 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.13 fmt/Sprint().("Error: ", fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.13 fmt/Sprint().(args...)))
121 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
122 c.Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().()
123 }
124
125 // Errorf logs an error into the test error output and marks the test as failed.
126 // The provided arguments are assembled together into a string with fmt.Sprintf.
127 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Errorfscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Errorf().(format string, args ...interface{}) {
128 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(1)
129 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("Error: "+format, args...))
130 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
131 c.Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().()
132 }
133
134 // Fatal logs an error into the test error output, marks the test as failed, and
135 // stops the test execution. The provided arguments are assembled together into
136 // a string with fmt.Sprint.
137 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Fatalscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fatal().(args ...interface{}) {
138 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(1)
139 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.13 fmt/Sprint().("Error: ", fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.13 fmt/Sprint().(args...)))
140 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
141 c.FailNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#FailNow().()
142 }
143
144 // Fatlaf logs an error into the test error output, marks the test as failed, and
145 // stops the test execution. The provided arguments are assembled together into
146 // a string with fmt.Sprintf.
147 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Fatalfscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fatalf().(format string, args ...interface{}) {
148 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(1)
149 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.13 fmt/Sprint().("Error: ", fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().(format, args...)))
150 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
151 c.FailNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#FailNow().()
152 }
153
154 // -----------------------------------------------------------------------
155 // Generic checks and assertions based on checkers.
156
157 // Check verifies if the first value matches the expected value according
158 // to the provided checker. If they do not match, an error is logged, the
159 // test is marked as failed, and the test execution continues.
160 //
161 // Some checkers may not need the expected argument (e.g. IsNil).
162 //
163 // Extra arguments provided to the function are logged next to the reported
164 // problem when the matching fails.
165 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Checkscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Check().(obtained interface{}, checker Checkerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/Checker#, args ...interface{}) bool {
166 return c.internalCheckscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#internalCheck().("Check", obtained, checker, args...)
167 }
168
169 // Assert ensures that the first value matches the expected value according
170 // to the provided checker. If they do not match, an error is logged, the
171 // test is marked as failed, and the test execution stops.
172 //
173 // Some checkers may not need the expected argument (e.g. IsNil).
174 //
175 // Extra arguments provided to the function are logged next to the reported
176 // problem when the matching fails.
177 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) Assertscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Assert().(obtained interface{}, checker Checkerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/Checker#, args ...interface{}) {
178 if !c.internalCheckscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#internalCheck().("Assert", obtained, checker, args...) {
179 c.stopNowscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#stopNow().()
180 }
181 }
182
183 func (c *Cscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#) internalCheckscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#internalCheck().(funcName string, obtained interface{}, checker Checkerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/Checker#, args ...interface{}) bool {
184 if checker == nil {
185 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(2)
186 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s(obtained, nil!?, ...):", funcName))
187 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().("Oops.. you've provided a nil checker!")
188 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
189 c.Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().()
190 return false
191 }
192
193 // If the last argument is a bug info, extract it out.
194 var comment CommentInterfacescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CommentInterface#
195 if len(args) > 0 {
196 if c, ok := args[len(args)-1].(CommentInterfacescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CommentInterface#); ok {
197 comment = c
198 args = args[:len(args)-1]
199 }
200 }
201
202 params := append([]interface{}{obtained}, args...)
203 info := checker.Infoscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/Checker#Info.()
204
205 if len(params) != len(info.Paramsscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CheckerInfo#Params.) {
206 names := append([]string{info.Paramsscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CheckerInfo#Params.[0], info.Namescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CheckerInfo#Name.}, info.Paramsscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CheckerInfo#Params.[1:]...)
207 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(2)
208 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s(%s):", funcName, stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Joinscip-go gomod github.com/golang/go/src go1.13 strings/Join().(names, ", ")))
209 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("Wrong number of parameters for %s: want %d, got %d", info.Namescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CheckerInfo#Name., len(names), len(params)+1))
210 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
211 c.Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().()
212 return false
213 }
214
215 // Copy since it may be mutated by Check.
216 names := append([]string{}, info.Paramsscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CheckerInfo#Params....)
217
218 // Do the actual check.
219 result, error := checker.Checkscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/Checker#Check.(params, names)
220 if !result || error != "" {
221 c.logCallerscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logCaller().(2)
222 for i := 0; i != len(params); i++ {
223 c.logValuescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logValue().(names[i], params[i])
224 }
225 if comment != nil {
226 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(comment.CheckCommentStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/CommentInterface#CheckCommentString.())
227 }
228 if error != "" {
229 c.logStringscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logString().(error)
230 }
231 c.logNewLinescip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#logNewLine().()
232 c.Failscip-go gomod github.com/pingcap/check . `github.com/pingcap/check`/C#Fail().()
233 return false
234 }
235 return true
236 }