@@ -107,8 +107,8 @@ func TestNew(t *testing.T) {
107107 }
108108}
109109
110+ // This test should work for any go version
110111func TestIs (t * testing.T ) {
111-
112112 if Is (nil , io .EOF ) {
113113 t .Errorf ("nil is an error" )
114114 }
@@ -128,51 +128,6 @@ func TestIs(t *testing.T) {
128128 if Is (io .EOF , fmt .Errorf ("io.EOF" )) {
129129 t .Errorf ("io.EOF is fmt.Errorf" )
130130 }
131-
132- custErr := errorWithCustomIs {
133- Key : "TestForFun" ,
134- Err : io .EOF ,
135- }
136-
137- shouldMatch := errorWithCustomIs {
138- Key : "TestForFun" ,
139- }
140-
141- shouldNotMatch := errorWithCustomIs {Key : "notOk" }
142-
143- if ! Is (custErr , shouldMatch ) {
144- t .Errorf ("custErr is not a TestForFun customError" )
145- }
146-
147- if Is (custErr , shouldNotMatch ) {
148- t .Errorf ("custErr is a notOk customError" )
149- }
150-
151- if ! Is (custErr , New (shouldMatch )) {
152- t .Errorf ("custErr is not a New(TestForFun customError)" )
153- }
154-
155- if Is (custErr , New (shouldNotMatch )) {
156- t .Errorf ("custErr is a New(notOk customError)" )
157- }
158-
159- if ! Is (New (custErr ), shouldMatch ) {
160- t .Errorf ("New(custErr) is not a TestForFun customError" )
161- }
162-
163- if Is (New (custErr ), shouldNotMatch ) {
164- t .Errorf ("New(custErr) is a notOk customError" )
165- }
166-
167- if ! Is (New (custErr ), New (shouldMatch )) {
168- t .Errorf ("New(custErr) is not a New(TestForFun customError)" )
169- }
170-
171- if Is (New (custErr ), New (shouldNotMatch )) {
172- t .Errorf ("New(custErr) is a New(notOk customError)" )
173- }
174-
175-
176131}
177132
178133func TestWrapError (t * testing.T ) {
@@ -361,17 +316,3 @@ func callersToFrames(callers []uintptr) []runtime.Frame {
361316 }
362317 }
363318}
364-
365- type errorWithCustomIs struct {
366- Key string
367- Err error
368- }
369-
370- func (ewci errorWithCustomIs ) Error () string {
371- return "[" + ewci .Key + "]: " + ewci .Err .Error ()
372- }
373-
374- func (ewci errorWithCustomIs ) Is (target error ) bool {
375- matched , ok := target .(errorWithCustomIs )
376- return ok && matched .Key == ewci .Key
377- }
0 commit comments