Skip to content

testing: support explicitly running non-hermetic (or non-deterministic) examples #31310

Open
@mvdan

Description

@mvdan

We can have examples which show up in the godoc but aren't runnable, and runnable examples which are run as part of go test.

What about examples which are too slow or unreliable for go test, for example those needing access to the internet? I can make them non-runnable, but what if a user wants to give one a try? go test -run ExampleSlow doesn't work, and the next best option is copy-pasting into a main func, which is awkward.

The only other option, which is what I tend to do, is to stick examples as main packages elsewhere. But that's also icky; if the example packages aren't hidden, go install ./... will include them, and if they're hidden in another repo or in _examples, they are hard to find.

Another disadvantage of hiding the examples in a separate dir/repo is that go test ./... won't check if they compile fine; one has to remember to check that dir/repo too.

For some context, I'm trying to collapse the https://github.com/chromedp/examples into the main repo, starting with an example_test.go file. The second and third examples are quick, but the first accesses the internet and is slow. I don't want to run it with go test, but I want it to show up in godoc and allow people to run it easily to try it out.

I'm not labelling this as a proposal, because I don't have a specific solution in mind; this is just a description of a problem I have when trying to document packages with non-trivial examples.

/cc @acln0 @mpvl @bcmills @ianlancetaylor

Metadata

Metadata

Assignees

No one assigned

    Labels

    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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions