You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: optionally include full (or relative) path name #37708
Currently, t.Error calls print only the base name of the source file.
This is fine when running a single test, but in larger projects, it is a significant productivity boost to have relative (or full) path names, which make the “jump to next compilation error” feature in popular editors work.
I understand the outcome of #21119 (can’t change the default), but I suggest adding a knob to opt into printing relative or full paths.
Perhaps this could be similar to log.SetFlags, where you can specify Llongfile or Lshortfile?
Let me know if this would be okay, and I’d be happy to send a CL.
@rogpeppe, @myitcv and myself discussed a very similar idea not too long ago.
It's unfortunate that we can't change the default. However, there is some precedent for such an opt-in flag:
$ go tool compile -h 2>&1 | grep -- -L
-L show full file names in error messages
I also wonder if go test could transform filename paths transparently, when it buffers output from test binaries. The only case where the test binary output goes straight to the terminal is when go test is run without arguments - and, in that case, the paths are already relative to the current directory, as we're testing the package in the current directory too. Transforming paths should be possible to do, given that test2json does very similar parsing of plaintext test output.
#55976 was closed as a duplicate of this issue, but this one seems to be stuck in the backlog. Can we turn this into a proposal?
Moving my comment here for consideration:
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 t.Helper is used correctly. The tooling that is reading the output doesn't necessarily know which directory is the current working directory because tests can be run from any directory.
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 -json flag on go test could be used to enable output of absolute paths instead of filenames.
1c72ee7 recently added -test.v=json, which I think allows testing to detect if -json is set or not.
changed the title [-]testing: optionally include full (or relative) path name[/-][+]proposal: testing: optionally include full (or relative) path name[/+]on Dec 21, 2022
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group
Excited to see that the proposal will be reviewed at the weekly proposal review meeting!
It would be great if there was an option to print the full/relative path of the source file even when the test succeeds.
For my company's repos, I'm working on associating tests with owners (using a CODEOWNERS file within the repo). We have large packages that multiple teams contribute too, so it's impossible to assign ownership based on package unless we take on a large amount of refactoring work. It's fairly easy however to assign ownership by files.
I'm able to assign ownership to a testcase when it fails based on the filename printed, however, I haven't been able to assign ownership for tests that pass. Printing the full/relative path of the source file for every test run would enable this.
This will help vscode go extension's job much easier. (vscode runs go test or dlv test from the open file's directory).
Can we extend this flag apply to produce absolute path names for build errors? (-gcflags=all=-L should do it in theory, but it doesn't do it now)
That way, when a test fails due to build error, the full path will be shown with the build errors.
Activity
mvdan commentedon Mar 6, 2020
@rogpeppe, @myitcv and myself discussed a very similar idea not too long ago.
It's unfortunate that we can't change the default. However, there is some precedent for such an opt-in flag:
I also wonder if
go testcould transform filename paths transparently, when it buffers output from test binaries. The only case where the test binary output goes straight to the terminal is whengo testis run without arguments - and, in that case, the paths are already relative to the current directory, as we're testing the package in the current directory too. Transforming paths should be possible to do, given thattest2jsondoes very similar parsing of plaintext test output.toothrot commentedon Mar 9, 2020
also ccing @mpvl
aryman-glympse commentedon Jun 11, 2021
Is there anyway we can do this similar to how the log package sets flags for log outputs?
Proposed:
dnephin commentedon Dec 17, 2022
#55976 was closed as a duplicate of this issue, but this one seems to be stuck in the backlog. Can we turn this into a proposal?
Moving my comment here for consideration:
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
t.Helperis used correctly. The tooling that is reading the output doesn't necessarily know which directory is the current working directory because tests can be run from any directory.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
-jsonflag ongo testcould be used to enable output of absolute paths instead of filenames.1c72ee7 recently added
-test.v=json, which I think allowstestingto detect if-jsonis set or not.[-]testing: optionally include full (or relative) path name[/-][+]proposal: testing: optionally include full (or relative) path name[/+]rsc commentedon Dec 21, 2022
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group
jmhwang7 commentedon Dec 22, 2022
Excited to see that the proposal will be reviewed at the weekly proposal review meeting!
It would be great if there was an option to print the full/relative path of the source file even when the test succeeds.
For my company's repos, I'm working on associating tests with owners (using a CODEOWNERS file within the repo). We have large packages that multiple teams contribute too, so it's impossible to assign ownership based on package unless we take on a large amount of refactoring work. It's fairly easy however to assign ownership by files.
I'm able to assign ownership to a testcase when it fails based on the filename printed, however, I haven't been able to assign ownership for tests that pass. Printing the full/relative path of the source file for every test run would enable this.
14 remaining items
empire commentedon Jan 26, 2023
@stapelberg, I've prepared a CL for this, and I'll send it in the next few days.
hyangah commentedon Jan 26, 2023
This will help vscode go extension's job much easier. (vscode runs
go testordlv testfrom the open file's directory).Can we extend this flag apply to produce absolute path names for build errors? (
-gcflags=all=-Lshould do it in theory, but it doesn't do it now)That way, when a test fails due to build error, the full path will be shown with the build errors.
gopherbot commentedon Jan 27, 2023
Change https://go.dev/cl/463837 mentions this issue:
testing: add -fullpath to go teststapelberg commentedon Feb 23, 2023
I can confirm that setting
-fullpathworks as expected in Emacs’s compilation-mode :)Pressing
M-g nbrings me into the correct file and line 🎉Thanks for getting this implemented :)
gopherbot commentedon May 25, 2023
Change https://go.dev/cl/498396 mentions this issue:
doc/go1.21: mention new go test -fullpath optiondoc/go1.21: mention new go test -fullpath option
testing: add -fullpath to go test