Files
Sebastiaan van Stijn 6040a2f686 fix some faulty defers in tests
Calling "defer assert.NilError(t, someCommand())" executes "someCommand()"
immediately, but doesn't assert the error until the defer.
https://go.dev/play/p/EO--y7OYerg

    package main

    import (
        "errors"
        "testing"

        "gotest.tools/v3/assert"
    )

    func TestDefer(t *testing.T) {
        doSomething := func() error {
            t.Log("doSomething failed with an error!")
            return errors.New("foo error")
        }

        defer assert.NilError(t, doSomething())

        t.Log("running test")
        t.Log("running test")
        t.Log("running test")
    }

Produces:

    === RUN   TestDefer
        prog_test.go:12: doSomething failed with an error!
        prog_test.go:18: running test
        prog_test.go:19: running test
        prog_test.go:20: running test
        prog_test.go:21: assertion failed: error is not nil: foo error
    --- FAIL: TestDefer (0.00s)
    FAIL

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-27 12:39:21 +01:00
..
2025-10-27 12:39:21 +01:00