MCPcopy
hub / github.com/stretchr/testify / TestError

Function TestError

assert/assertions_test.go:1665–1694  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1663func (*customError) Error() string { return "fail" }
1664
1665func TestError(t *testing.T) {
1666 t.Parallel()
1667
1668 mockT := new(testing.T)
1669
1670 // start with a nil error
1671 var err error
1672
1673 False(t, Error(mockT, err), "Error should return False for nil arg")
1674
1675 // now set an error
1676 err = errors.New("some error")
1677
1678 True(t, Error(mockT, err), "Error with error should return True")
1679
1680 // go vet check
1681 True(t, Errorf(mockT, err, "example with %s", "formatted message"), "Errorf with error should return True")
1682
1683 // returning an empty error interface
1684 err = func() error {
1685 var err *customError
1686 return err
1687 }()
1688
1689 if err == nil { // err is not nil here!
1690 t.Errorf("Error should be nil due to empty interface: %s", err)
1691 }
1692
1693 True(t, Error(mockT, err), "Error should pass with empty error interface")
1694}
1695
1696func TestEqualError(t *testing.T) {
1697 t.Parallel()

Callers

nothing calls this directly

Calls 5

FalseFunction · 0.70
ErrorFunction · 0.70
TrueFunction · 0.70
ErrorfFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected