Skip to content

Commit

Permalink
Merge pull request #254 from gotestyourself/deprecate-assert-error
Browse files Browse the repository at this point in the history
Deprecate assert.ErrorType
  • Loading branch information
dnephin authored Apr 4, 2023
2 parents 77099a8 + 043b579 commit fe86c87
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
}

// ErrorType fails the test if err is nil, or err is not the expected type.
// Most new code should use ErrorIs instead. ErrorType may be deprecated in the
// future.
// New code should use ErrorIs instead.
//
// Expected can be one of:
//
Expand All @@ -285,6 +284,8 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
// must be called from the goroutine running the test function, not from other
// goroutines created during the test. Use Check with cmp.ErrorType from other
// goroutines.
//
// Deprecated: Use ErrorIs
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
if ht, ok := t.(helperT); ok {
ht.Helper()
Expand Down
4 changes: 3 additions & 1 deletion assert/cmp/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
//
// reflect.Type
//
// Fails if err does not implement the reflect.Type
// Fails if err does not implement the reflect.Type.
//
// Deprecated: Use ErrorIs
func ErrorType(err error, expected interface{}) Comparison {
return func() Result {
switch expectedType := expected.(type) {
Expand Down
8 changes: 4 additions & 4 deletions fs/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestNewFile(t *testing.T) {

tmpFile.Remove()
_, err = os.Stat(tmpFile.Path())
assert.ErrorType(t, err, os.IsNotExist)
assert.ErrorIs(t, err, os.ErrNotExist)
})

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

tmpFile.Remove()
_, err = os.Stat(tmpFile.Path())
assert.ErrorType(t, err, os.IsNotExist)
assert.ErrorIs(t, err, os.ErrNotExist)
})
}

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

t.Run("file has been removed", func(t *testing.T) {
_, err := os.Stat(tmpFile.Path())
assert.ErrorType(t, err, os.IsNotExist)
assert.ErrorIs(t, err, os.ErrNotExist)
})
}

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

t.Run("dir has been removed", func(t *testing.T) {
_, err := os.Stat(tmpFile.Path())
assert.ErrorType(t, err, os.IsNotExist)
assert.ErrorIs(t, err, os.ErrNotExist)
})
}

Expand Down

0 comments on commit fe86c87

Please sign in to comment.