Skip to content

proposal: cmd/vet: check for deferring test cleanup #73925

Open
@uhthomas

Description

@uhthomas

Proposal Details

I noticed recently during a code review that t.Cleanup was being deferred, which is almost certainly unintentional.

func TestABC(t *testing.T) {
    defer t.Cleanup(func() {
        // ...
    })
}

A naive search shows hundreds of results, and it's possible a more accurate search would show even more.

https://github.com/search?q=%22defer+t.Cleanup%28func%22+language%3AGo&type=code

It would be nice to have an analyser to catch this as I am not sure I see any scenario where this is actually desirable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)ProposalToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions