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

Function TestNoError

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

Source from the content-addressed store, hash-verified

1631}
1632
1633func TestNoError(t *testing.T) {
1634 t.Parallel()
1635
1636 mockT := new(testing.T)
1637
1638 // start with a nil error
1639 var err error
1640
1641 True(t, NoError(mockT, err), "NoError should return True for nil arg")
1642
1643 // now set an error
1644 err = errors.New("some error")
1645
1646 False(t, NoError(mockT, err), "NoError with error should return False")
1647
1648 // returning an empty error interface
1649 err = func() error {
1650 var err *customError
1651 return err
1652 }()
1653
1654 if err == nil { // err is not nil here!
1655 t.Errorf("Error should be nil due to empty interface: %s", err)
1656 }
1657
1658 False(t, NoError(mockT, err), "NoError should fail with empty error interface")
1659}
1660
1661type customError struct{}
1662

Callers

nothing calls this directly

Calls 4

TrueFunction · 0.70
NoErrorFunction · 0.70
FalseFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected