MCPcopy Create free account
hub / github.com/stretchr/testify / TestError

Function TestError

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

Source from the content-addressed store, hash-verified

1593func (*customError) Error() string { return "fail" }
1594
1595func TestError(t *testing.T) {
1596
1597 mockT := new(testing.T)
1598
1599 // start with a nil error
1600 var err error
1601
1602 False(t, Error(mockT, err), "Error should return False for nil arg")
1603
1604 // now set an error
1605 err = errors.New("some error")
1606
1607 True(t, Error(mockT, err), "Error with error should return True")
1608
1609 // go vet check
1610 True(t, Errorf(mockT, err, "example with %s", "formatted message"), "Errorf with error should return True")
1611
1612 // returning an empty error interface
1613 err = func() error {
1614 var err *customError
1615 return err
1616 }()
1617
1618 if err == nil { // err is not nil here!
1619 t.Errorf("Error should be nil due to empty interface: %s", err)
1620 }
1621
1622 True(t, Error(mockT, err), "Error should pass with empty error interface")
1623}
1624
1625func TestEqualError(t *testing.T) {
1626 mockT := new(testing.T)

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