Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Attempt to get absolute path on every line of test output causes wrongful paths #1836

Closed
Hunsin opened this issue Aug 10, 2018 · 12 comments
Closed

Comments

@Hunsin
Copy link

Hunsin commented Aug 10, 2018

Plugin version: 0.6.85
Go version: 1.10.3

Just a simple file, example_test.go:

// ...
logger := log.New(os.Stdout, "", log.Lshortfile)
logger.Println("Hello!")
// output: example_test.go:10: Hello
// I miss a "!" so that it will show FAIL when running test

This is the output by clicking run package tests from plugin:
log_shortfile_1

And this is the output from terminal directly, also what I expected:
log_shortfile_2

Any idea?

@ramya-rao-a
Copy link
Contributor

Well, we intentional present the complete path so that it is clickable and the corresponding file opens in the editor on the right line number :)

@Hunsin
Copy link
Author

Hunsin commented Aug 13, 2018

Ah..., I see.
Is there any document about it? Something like overwriting the outputs.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Aug 14, 2018

There is no option to override it at the moment.

The output channel doesnt support relative links but the integrated terminal does.
So if we move to using tasks to run tests and then show the results in the terminal, then we can make do with the relative links

@haleyrc
Copy link

haleyrc commented Oct 11, 2018

This recently caused some confusion for me as the heuristic is overly greedy and will prepend the absolute path even if the short filename isn't the first item in the entry such as when you use both log.Ltime and log.Lshortfile. In fact, it does this even if using log.Llongfile.

@ramya-rao-a
Copy link
Contributor

@haleyrc Can you give a small code sample where you see the issue so that I can take a look at what's causing it?

@haleyrc
Copy link

haleyrc commented Oct 17, 2018

@ramya-rao-a Absolutely, and sorry for the delay. https://github.com/haleyrc/vscode-go-issue demonstrates the issue I'm having.

@ramya-rao-a
Copy link
Contributor

Interesting... I see it now.

I believe this only happens when you are using the -v flag and then use the log pkg to print anything.

The fix should be pretty straight-forward. We shouldnt be attempting to get the absolute path on an output line unless it is for a test failure. Such lines are always preceeded by a --- FAIL:, so we can make use of that.

PRs are most welcome to fix this issue.

Code Pointers:

@ramya-rao-a ramya-rao-a changed the title log shortfile path override? Attempt to get absolute path on every line of test output causes wrongful paths Oct 17, 2018
@MagnumOpus21
Copy link

Okay this is something I can work on if no one else has dibs on this 😁

@ramya-rao-a
Copy link
Contributor

Go ahead @MagnumOpus21 :)

Remember to test all the 4 test commands:

  • Test at cursor
  • Test file
  • Test package
  • Test workspace

@peergynt
Copy link

peergynt commented Dec 20, 2018

It's probably worth mentioning the following issue here: golang/go#25369

It looks like a possible "fix" for this issue is to make sure that the output line starts with at least a tab (pre go-1.11) or with 4 spaces (go1.11+).

Note @andybons comment:

I think it’s fine. If someone is relying on the textual output of tests instead of using the JSON output, then this will be a good reason for them to switch :)

It doesn't look like using the JSON output would help though because the filename still ends up in the 'Output' field.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Mar 26, 2020

Hey all,

I've pushed 2 changes to restrict the attempts to expand text that looks like a relative path

  • Skip doing so when test passes 893b29b
  • Follow @peergynt's suggestion above to look for lines in error output starting with tab or 4 spaces. 92d149c

Please try the latest beta version of this extension that has these changes and let me know how it fares

@ramya-rao-a
Copy link
Contributor

The above mentioned changes are now available in the latest version of this extension.

@vscodebot vscodebot bot locked and limited conversation to collaborators May 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants