1package expect23import "gno.land/p/nt/ufmt/v0"45// NewErrorChecker creates a new checker of errors.6func NewErrorChecker(ctx Context, err error) ErrorChecker {7 return ErrorChecker{ctx, err}8}910// ErrorChecker asserts error values.11type ErrorChecker struct {12 ctx Context13 err error14}1516// Not negates the next called expectation.17func (c ErrorChecker) Not() ErrorChecker {18 c.ctx.negated = !c.ctx.negated19 return c20}2122// WithMessage asserts that current error contains an expected message.23func (c ErrorChecker) WithMessage(msg string) {24 c.ctx.T().Helper()2526 if c.err == nil {27 c.ctx.Fail("Expected an error with message\nGot: nil\nWant: %s", msg)28 return29 }3031 NewMessageChecker(c.ctx, c.err.Error(), MessageTypeError).WithMessage(msg)32}3334// WithError asserts that current error message is the same as an expected error.35func (c ErrorChecker) WithError(err error) {36 c.ctx.T().Helper()3738 if c.err == nil {39 if err != nil {40 c.ctx.Fail("Expected an error\nGot: nil\nWant: %s", err.Error())41 }42 return43 }4445 got := c.err.Error()46 c.ctx.CheckExpectation(got == err.Error(), func(ctx Context) string {47 if !ctx.IsNegated() {48 return ufmt.Sprintf("Expected errors to match\nGot: %s\nWant: %s", got, err.Error())49 }50 return ufmt.Sprintf("Expected errors to be different\nGot: %s", got)51 })52}53Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.