-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: testing: flag to not truncate file names when logging #55976
Comments
Whenever I think about a possible new option I also like to think about whether it might be possible to change the default behavior in a reasonable way to avoid adding the new option. 😀 In this case, I wonder: would it be reasonable to change the default behavior so that files in the current package will stay as relative paths but files in any other package will always be printed as absolute paths, to avoid the ambiguity? My sense is that a test helper that fails to call (I may well be missing a situation where it's desirable to intentionally produce test logging attributed to a line that isn't in the current package, in which case I'd withdraw the above suggestion.) |
I'd be happy with anything that allows the VSCode Go extension to unambiguously identify the correct file. I suggested a flag because that means the default is no change in behavior. Regardless of why In my own work, there is an unavoidable case where |
In case it matters, if this proposal is accepted I am happy to submit the CL myself. |
Thanks for creating this proposal! I've noticed occasionally GoLand links to the wrong file when tests are run from the terminal window inside GoLand. I suspect it's for exactly the reason described above. The filename is ambiguous. There can be multiple files with the same name in a project, and when tests are run from the terminal window, it doesn't know which of those files to link to. An absolute path would allow this feature to work reliably. This problem exists even when I suspect the absolute path is really only useful when the output is being read by another application, and the filename is better when the output is being read by a human. Instead of a new flag to enable this behaviour, the existing 1c72ee7 recently added |
Duplicate of #37708 |
@seankhliao thanks for the link! This issue is labeled as a proposal, where as the other one seems to be stuck in the backlog as "needs investigation". Is there some way we can make that one a proposal as well, so that it gets some attention? Or can we keep this one since this one is correctly labelled? |
This proposal is a duplicate of a previously discussed proposal, as noted above, |
I propose to add a flag to
go test
, such as-logabspath
, that will print out the absolute path of the location of a call to(*testing.T).Log
and friends instead of just the file name.*testing.T
methods that log (via(*testing.T).log
) print out the location of the call, truncating the filename to just the basename. This may be helpful to users but it is problematic for tools like the VSCode Go extension. The Go extension's test support uses that location information to attach a log event to the source location. The extension assumes that such calls are made from files in the same package as the test, so this works in that case. However, it fails if those methods are called from a location outside of the test's package (if that location does not also call(*testing.T).Helper()
. My proposal would provide an opt-in way for tooling such as the extension to change this behavior.The text was updated successfully, but these errors were encountered: