-
Notifications
You must be signed in to change notification settings - Fork 1
/
deprecation_shim.go
45 lines (37 loc) · 1.2 KB
/
deprecation_shim.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
package gomega
import (
"fmt"
)
var didWarnAboutMatcherDeprecation map[string]bool
func init() {
didWarnAboutMatcherDeprecation = map[string]bool{}
}
type shimMatcher struct {
matcher DeprecatedOmegaMatcher
message string
}
func (m *shimMatcher) Match(actual interface{}) (success bool, err error) {
success, m.message, err = m.matcher.Match(actual)
return success, err
}
func (m *shimMatcher) FailureMessage(actual interface{}) (message string) {
return m.message
}
func (m *shimMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return m.message
}
func shimIfNecessary(matcher interface{}) OmegaMatcher {
switch m := matcher.(type) {
case OmegaMatcher:
return m
case DeprecatedOmegaMatcher:
matcherType := fmt.Sprintf("%T", matcher)
if !didWarnAboutMatcherDeprecation[matcherType] {
fmt.Printf("\nGOMEGA DEPRECATION WARNING\nYou are using a custom matcher of type:\n %s\nthat conforms to a deprecated matcher interface.\nPlease update your matcher, the old style will be removed in Gomega 1.0.\n", matcherType)
didWarnAboutMatcherDeprecation[matcherType] = true
}
return &shimMatcher{matcher: m}
default:
panic(fmt.Sprintf("Not a valid matcher:\n%v", matcher))
}
}