tools/internal: tool.Main should be refactored to simplify testing. #34291
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputThe issue
CL 194878 is making the GoPls rename functionality available from the command line. The rename test suite includes mostly successful tests (when run on this input you should get this output), but two cases are designed to generate errors, which are passed up the call chain.
tool.Main is the main entry point for the command line tools. It is explicitly intended to be called by application main() routines. If/when it encounters an error it prints the error to standard error and exists with a non-zero status (2).
tool.Main is also invoked internally and from various test functions. Exiting when the underlying functionality being exercised makes testing difficult, unnecessarily. For example, it causes false negatives (tests fail that shouldn't) in the the work-in-progress (https://go-review.googlesource.com/c/tools/+/194878/5) to implement
gopls rename
.A simple fix is to break the functionality into two parts, calling the outer from main() functions and calling the inner bits internally and in tests.
I have a change ready that implements this.
The text was updated successfully, but these errors were encountered: