6 | 6 |
"runtime"
|
7 | 7 |
"sync"
|
8 | 8 |
"time"
|
|
9 |
"errors"
|
9 | 10 |
|
10 | 11 |
"github.com/onsi/gomega/types"
|
11 | 12 |
)
|
|
16 | 17 |
wasViaPanic() bool
|
17 | 18 |
}
|
18 | 19 |
|
|
20 |
|
|
21 |
func asStopTryingError(actual interface{}) (StopTryingError, bool) {
|
|
22 |
if actual == nil {
|
|
23 |
return nil, false
|
|
24 |
}
|
|
25 |
if actualErr, ok := actual.(error); ok {
|
|
26 |
var target *stopTryingError
|
|
27 |
if errors.As(actualErr, &target) {
|
|
28 |
return target, true
|
|
29 |
} else {
|
|
30 |
return nil, false
|
|
31 |
}
|
|
32 |
}
|
|
33 |
|
|
34 |
return nil, false
|
|
35 |
}
|
|
36 |
|
19 | 37 |
type stopTryingError struct {
|
20 | 38 |
message string
|
21 | 39 |
viaPanic bool
|
|
33 | 51 |
func (s *stopTryingError) wasViaPanic() bool {
|
34 | 52 |
return s.viaPanic
|
35 | 53 |
}
|
36 | |
|
37 | |
var stopTryingErrorType = reflect.TypeOf(&stopTryingError{})
|
38 | 54 |
|
39 | 55 |
var StopTrying = func(message string) StopTryingError {
|
40 | 56 |
return &stopTryingError{message: message}
|
|
156 | 172 |
return nil, fmt.Errorf("No values were returned by the function passed to Gomega"), stopTrying
|
157 | 173 |
}
|
158 | 174 |
actual := values[0].Interface()
|
159 | |
if actual != nil && reflect.TypeOf(actual) == stopTryingErrorType {
|
160 | |
stopTrying = actual.(StopTryingError)
|
|
175 |
if stopTryingErr, ok := asStopTryingError(actual); ok{
|
|
176 |
stopTrying = stopTryingErr
|
161 | 177 |
}
|
162 | 178 |
for i, extraValue := range values[1:] {
|
163 | 179 |
extra := extraValue.Interface()
|
164 | 180 |
if extra == nil {
|
165 | 181 |
continue
|
166 | 182 |
}
|
167 | |
extraType := reflect.TypeOf(extra)
|
168 | |
if extraType == stopTryingErrorType {
|
169 | |
stopTrying = extra.(StopTryingError)
|
|
183 |
if stopTryingErr, ok := asStopTryingError(extra); ok{
|
|
184 |
stopTrying = stopTryingErr
|
170 | 185 |
continue
|
171 | 186 |
}
|
172 | |
zero := reflect.Zero(extraType).Interface()
|
|
187 |
zero := reflect.Zero(reflect.TypeOf(extra)).Interface()
|
173 | 188 |
if reflect.DeepEqual(extra, zero) {
|
174 | 189 |
continue
|
175 | 190 |
}
|
|
225 | 240 |
return func() (actual interface{}, err error, stopTrying StopTryingError) {
|
226 | 241 |
defer func() {
|
227 | 242 |
if e := recover(); e != nil {
|
228 | |
if reflect.TypeOf(e) == stopTryingErrorType {
|
229 | |
stopTrying = e.(StopTryingError)
|
|
243 |
if stopTryingErr, ok := asStopTryingError(e); ok {
|
|
244 |
stopTrying = stopTryingErr
|
230 | 245 |
} else {
|
231 | 246 |
panic(e)
|
232 | 247 |
}
|
|
290 | 305 |
}
|
291 | 306 |
}
|
292 | 307 |
if e := recover(); e != nil {
|
293 | |
if reflect.TypeOf(e) == stopTryingErrorType {
|
294 | |
stopTrying = e.(StopTryingError)
|
|
308 |
if stopTryingErr, ok := asStopTryingError(e); ok {
|
|
309 |
stopTrying = stopTryingErr
|
295 | 310 |
} else if assertionFailure == nil {
|
296 | 311 |
panic(e)
|
297 | 312 |
}
|