Skip to content

testing: be clearer about when Benchmark needs Init #77499

@dominikh

Description

@dominikh

The documentation of testing.Benchmark says that

If f depends on testing flags, then [Init] must be used to register
those flags before calling Benchmark and before calling [flag.Parse].

but doesn't specify what might depend on the flags.

I ran into this when I returned inside a for b.Loop() loop, which tried to log an error, but instead panicked because logging accesses the fullPath flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions