Skip to content

Commit fe86c87

Browse files
authored
Merge pull request #254 from gotestyourself/deprecate-assert-error
Deprecate assert.ErrorType
2 parents 77099a8 + 043b579 commit fe86c87

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

assert/assert.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
262262
}
263263

264264
// ErrorType fails the test if err is nil, or err is not the expected type.
265-
// Most new code should use ErrorIs instead. ErrorType may be deprecated in the
266-
// future.
265+
// New code should use ErrorIs instead.
267266
//
268267
// Expected can be one of:
269268
//
@@ -285,6 +284,8 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
285284
// must be called from the goroutine running the test function, not from other
286285
// goroutines created during the test. Use Check with cmp.ErrorType from other
287286
// goroutines.
287+
//
288+
// Deprecated: Use ErrorIs
288289
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
289290
if ht, ok := t.(helperT); ok {
290291
ht.Helper()

assert/cmp/compare.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
306306
//
307307
// reflect.Type
308308
//
309-
// Fails if err does not implement the reflect.Type
309+
// Fails if err does not implement the reflect.Type.
310+
//
311+
// Deprecated: Use ErrorIs
310312
func ErrorType(err error, expected interface{}) Comparison {
311313
return func() Result {
312314
switch expectedType := expected.(type) {

fs/file_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestNewFile(t *testing.T) {
5151

5252
tmpFile.Remove()
5353
_, err = os.Stat(tmpFile.Path())
54-
assert.ErrorType(t, err, os.IsNotExist)
54+
assert.ErrorIs(t, err, os.ErrNotExist)
5555
})
5656

5757
t.Run(`with \ in name`, func(t *testing.T) {
@@ -61,7 +61,7 @@ func TestNewFile(t *testing.T) {
6161

6262
tmpFile.Remove()
6363
_, err = os.Stat(tmpFile.Path())
64-
assert.ErrorType(t, err, os.IsNotExist)
64+
assert.ErrorIs(t, err, os.ErrNotExist)
6565
})
6666
}
6767

@@ -76,7 +76,7 @@ func TestNewFile_IntegrationWithCleanup(t *testing.T) {
7676

7777
t.Run("file has been removed", func(t *testing.T) {
7878
_, err := os.Stat(tmpFile.Path())
79-
assert.ErrorType(t, err, os.IsNotExist)
79+
assert.ErrorIs(t, err, os.ErrNotExist)
8080
})
8181
}
8282

@@ -91,7 +91,7 @@ func TestNewDir_IntegrationWithCleanup(t *testing.T) {
9191

9292
t.Run("dir has been removed", func(t *testing.T) {
9393
_, err := os.Stat(tmpFile.Path())
94-
assert.ErrorType(t, err, os.IsNotExist)
94+
assert.ErrorIs(t, err, os.ErrNotExist)
9595
})
9696
}
9797

0 commit comments

Comments
 (0)