-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Currently, the testing package exports the package-level Verbose function, which maps to whether or not the -test.v flag was provided.
I'd like to propose that Verbose() bool also be added to testing.TB (and thus be implemented by testing.T and testing.B). AFAICT it would be fine for this to simply call testing.Verbose() under the hood, as the value would not change among tests in a suite or their subtests.
The primary motivation is that it's not possible to mock behavioral changes in libraries (such as test utilities) based on whether -test.v was provided or not. Many libraries provide a pseudo-testing.TB interface for mocking (which intentionally can't be mocked directly due to the unexported TB.private() interface method), but package-level functions cannot be mocked. Thus, to support testing behavior based on testing.Verbose() without a corresponding method on testing.TB, something like the following would be required:
type VerboseReader interface {
Verbose() bool
}
type verboseReader struct{}
func (verboseReader) Verbose() bool {
return testing.Verbose()
}which is, IMO, not ideal. Given that the methods currently on testing.TB are all specific to the currently-running test, testing.Verbose() indirectly influences the output behavior of each test despite being test-agnostic itself, so I think it makes sense to include as part of testing.TB.
Any thoughts, feedback, or suggestions are appreciated!