Skip to content

go/doc: whole file is used as example even when there are tests or benchmarks #38409

Closed
@dmitshur

Description

@dmitshur

Package testing says:

The entire test file is presented as the example when it contains a single example function, at least one other function, type, variable, or constant declaration, and no test or benchmark functions.

This program produces expected results in Go 1.13:

$ go1.13.10 run .
errors.As has a whole file example: false

It stopped working in Go 1.14:

$ go1.14.2 run .      
errors.As has a whole file example: true

This is because CL 211357 added an early continue when the function being considered has parameters. The intention was to skip Example functions with parameters. However, the skip happens too early, before this check:

if isTest(name, "Test") || isTest(name, "Benchmark") {
	hasTests = true
	continue
}

Tests and benchmarks always have 1 parameter, so hasTests never has a chance to get set to true.

/cc @jayconrod @matloob

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions