Documentation
¶
Overview ¶
Package efft from efftesting checks expectations and optionally rewrites them if the EFFUP=1 envvar is set. Just write `efft.Effect(any arg here)`, efftesting deterministically stringifies the arguments and maintains the expectation for the result.
Example usage:
func TestSplit(t *testing.T) {
efft.Init(t)
// simple cut, omits the success flag to keep things short
efft.Effect(strings.CutPrefix("hello world", "hello")).Equals(" world")
// failing cut, stringifies the success flag too on failure
efft.Effect(strings.CutPrefix("hello world", "world")).Equals(`
[
"hello world",
false
]`)
}
You only need to write `efft.Expect(some-expression)` and `EFFUP=1 go test ./...` does the rest. I.e. write only this and the runner will rewrite it to the above:
func TestSplit(t *testing.T) {
efft.Init(t)
// simple cut
efft.Effect(strings.CutPrefix("hello world", "hello"))
// failing cut
efft.Effect(strings.CutPrefix("hello world", "world"))
}
Note that if the function's last arg is a nil error or true boolean then it's automatically omitted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Context = 2
Context is the number of lines to display before and after the diff starts and ends.
var Diff = dummydiff
Diff is the function to diff the expectation against the got value. Defaults to a very simple diff treats all lines changed from the first until the last change.
var Note string
Note to include in the error message when there's a diff between the effect's got and wanted value.
Functions ¶
func Effect ¶ added in v0.260131.0
func Effect(args ...any) result
Effect sets up an expectation. Effect accepts a list of any args so it can be used with functions that return multiple values. This is why the expectation has to be given in a separate function. See the package comment how to use this.
func FatalEffect ¶ added in v0.260131.0
func FatalEffect(args ...any) result
FatalEffect is same as Effect but aborts the test if the expectation doesn't match.
func Init ¶
Init setup efft for this testcase. Note that efft doesn't support sub- or parallel tests.
func Must ¶
func Must(err any)
Must fails the current test if err is `false` or is a non-nil error. This is a convenience helper.
func Must1 ¶
Must1 fails the current test if err is `false` or is a non-nil error. The other return values are returned otherwise. This is a convenience helper.
func Must2 ¶
Must2 fails the current test if err is `false` or is a non-nil error. The other return values are returned otherwise. This is a convenience helper.
func Override ¶
func Override[T any](p *T, v T)
Override overrides `p` for the duration of the test. Its value is reset when the test ends. This is a convenience helper.
func Stringify ¶ added in v0.251225.1
Stringify stringifies an expression. Can be used to stringify a single value or even as "efft.Stringify(somefunc())". If there are multiple args and the last one indicates an error then only that part is stringified. Otherwise the rest of the args are stringified into a reasonable format. This is a convenience helper.
Types ¶
This section is empty.