errby

package module
v0.0.0-...-a1449e0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 4 Imported by: 0

README

errby

Package github.com/elblox/errby is a small helper package to compare errors by their output with is, the famous lightweight testing mini-framework by Mat Ryer.

As Dave Cheney points out in Don't just check errors, handle them gracefully, the output of error.Error should not be inspected in order to change the behaviour of a program, but

Full quote:

As an aside, I believe you should never inspect the output of the error.Error method. The Error method on the error interface exists for humans, not code.

The contents of that string belong in a log file, or displayed on screen. You shouldn’t try to change the behaviour of your program by inspecting it.

I know that sometimes this isn’t possible, and as someone pointed out on twitter, this advice doesn’t apply to writing tests. Never the less, comparing the string form of an error is, in my opinion, a code smell, and you should try to avoid it.

As pointed out in the last section, there are good reasons to do this in tests.

If you find your self in the situation, where you need to compare the output of errors in your tests, this small helper may become handy.

License

This code is licensed 2021 by Elblox AG under the MIT license (see LICENSE for the full text).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(is *is.I, expected, actual error)

Compare provides a convinient function to compare errors as helper in tests.

func Contains

func Contains(is *is.I, expected, actual error)

Contains provides a convenient function to compare errors based on string.Contains as helper in tests.

func MustMatch

func MustMatch(is *is.I, expected, actual error)

Match provides a convinient function to compare errors based on regexp.MatchString as helper in tests.

Types

type T

type T interface {
	Fail()
	FailNow()
}

T reports when failures occur. testing.T implements this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL