Skip to content

proposal: testing: add Testing constant #60737

@FiloSottile

Description

@FiloSottile

In cryptographic packages, I would like to perform extra consistency checks that are unsuitable for production either for performance reasons (they might be slow or cause inliner or escape analysis issues) or because they are not safe (they might be non-constant time or expose undesirable attack surface). In other languages, this is usually done with debug mode asserts, but really they are mostly exercised during tests.

I propose we add a constant to testing that is always true if building with go test and false otherwise. I couldn't come up with a better name than testing.Testing.

Then, I could gate all my testing assertions with if testing.Testing and (depending on the order of optimization passes), count on dead code removal to make the effects of that code disappear in production builds. This feels like a technique that would make sense beyond cryptography, too, although for other packages it might be less important for it to be a constant, so it can be emulated with init() in a _test.go file setting a variable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions