go-fail

Fail is a Go package designed to easily create human-readable failure reports for different kinds of failed tests. It is not a testing or assertion framework.
go get github.com/roeldev/go-fail
import "github.com/roeldev/go-fail"
Show differences
Below examples creates a diff report that shows the difference between the actual and expected values.
func TestAnything(t *testing.T) {
have := Anything()
want := "expected value"
if have != want {
t.Error(fail.Diff{
Func: "Anything",
Msg: "this is a meaningful message",
Have: have,
Want: want,
})
}
}
The output result is something similar like:
Anything() this is a meaningful message
string(
- "actual value",
+ "expected value",
)
Unexpected error
func TestDoSomething(t *testing.T) {
if err := DoSomething(); err != nil {
// display the error that should not occur
t.Error(fail.Err{
Func: "DoSomething",
Err: err,
})
}
}
The output result is something similar like:
DoSomething() unexpected error:
some error occurred while doing important stuff...
Documentation
Additional detailed documentation is available at go.dev
Created with

License
GPL-3.0+ © 2019 Roel Schut