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

Fix for issue 1836 #2027

Closed
wants to merge 8 commits into from
Closed

Conversation

MagnumOpus21
Copy link

Fixes #1836.
@ramya-rao-a
These are the images I get after making the modifications.
This image is that of a passing test case.
pass_golang
This image is for a failing test case.
fails_golang
This is for one passing case and one failing case. (Package wide)
onepass.
I have tested this with all the options from the command palette.
Do tell me if I need to add more to the PR, to make it even better :)

Copy link
Contributor

@ramya-rao-a ramya-rao-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MagnumOpus21 Thanks for the PR. I believe there has been some misunderstanding on the issue that we are trying to fix here.

Below is a picture of your second case.

image

The text rounded up in red is the bug. When you run the test in the terminal, you get the timestamp followed by the file details. This line should not be picked up by expandFilePathInOutput

Only lines in the output that correspond to actual test failure should be picked up by expandFilePathInOutput

@MagnumOpus21
Copy link
Author

Ah my bad. I thought the "prepended" by --- FAIL : was a mistake. I shall rectify this in the following commit.

@MagnumOpus21
Copy link
Author

MagnumOpus21 commented Oct 21, 2018

I modified the regex inside expandPathLinesOutput.

Why

When golang prints something to the console, it appends the timestamp with the file path to the console inside the tests. For the failures, it doesn't have this stated behavior. So, the regex now only captures failure of test cases since they don't have the timestamp at the beginning of the output.
Also, file names are supposed to be in snake_case and the regex captures this.

How I arrived at this conclusion

I noticied that I was getting the lines, one by one, instead of having them all at once. I couldn't access the previous lines. I printed it to the console, and found this out. I have no idea why previously I could check for the next line (lines[i + 1]).
When I tried this for lines[i - 1] it didn't process the lines at all. (Because we have one line and the value at i -1 th index is undefined). If I am missing something do correct me. This is my very first experience working with TypeScript.

Output with this commit.

I believe this was the intended fix. I apologize for not getting the correct behavior initially.
v2

src/testUtils.ts Outdated
@@ -340,7 +340,7 @@ export function cancelRunningTests(): Thenable<boolean> {
function expandFilePathInOutput(output: string, cwd: string): string {
let lines = output.split('\n');
for (let i = 0; i < lines.length; i++) {
let matches = lines[i].match(/^\s*(.+.go):(\d+):/);
let matches = lines[i].match(/^\s*(\s*\w+.go):(\d+):/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to capture the spaces here? Is this to cater to the case when the file name contains a space?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought spaces might be present at the beginning of the file. This has another bug, where if we have spaces in the filename like file name.go the regex will fail to pick this. Another commit inc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a compile error in your code and then run the test. The test output will now show the build error in the below format:
.\reverse_test.go:23:12: undefined: sring

Now, with the current change, the above will not get expanded because \w will not match .\

@MagnumOpus21
Copy link
Author

Also, I notice that the hyperlinks break after a space inside the output terminal in vscode. Is this the expected behavior?
v3

@ramya-rao-a
Copy link
Contributor

@MagnumOpus21 Are you sure the last commit makes a difference?

File names with spaces would have worked even without that commit as far as I understand.

Since that is a very corner case, I am ok not supporting the scenario where file name has spaces.
I am more concerned about #2027 (comment)

@MagnumOpus21
Copy link
Author

MagnumOpus21 commented Oct 22, 2018

The GitHub outage prevented me from viewing your previous message with the regex for the build errors. I could see your why not this regex suggestion earlier in the day, now I am not able to spot it at all. Still am not sure if I can see all the suggestions after the outage started on outdated thread 😅.

@MagnumOpus21
Copy link
Author

@ramya-rao-a Now it should capture all the failures on non-Windows platforms as well. I was just testing the extension on Windows. 😓

src/testUtils.ts Outdated
@@ -340,7 +340,7 @@ export function cancelRunningTests(): Thenable<boolean> {
function expandFilePathInOutput(output: string, cwd: string): string {
let lines = output.split('\n');
for (let i = 0; i < lines.length; i++) {
let matches = lines[i].match(/^\s*(.+.go):(\d+):/);
let matches = lines[i].match(/^\s*([(\.\/)?\w+\s*]+.go):(\d+):/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things inside the [] dont need the quantifiers like ?, + or *. [] defines the allowed characters not their quantity or order.

Also, this will not work for Windows.

Can you make this an exported function and add some tests to cover the different scenarios?

You can add the tests in https://github.com/Microsoft/vscode-go/blob/master/test/unit/utils.test.ts

@MagnumOpus21
Copy link
Author

Sorry for the no progress during the past weeks. Hectic school session in progress. I will finish the PR during Thanksgiving week. Thanks for your patience.

@ramya-rao-a
Copy link
Contributor

No problem @MagnumOpus21, take your time.

@peergynt
Copy link

@MagnumOpus21 did you see my comment in the original issue (#1836) by any chance?
It seems like checking that the line starts with at least a tab or four spaces could help.

@MagnumOpus21
Copy link
Author

I'm sorry 😔. I was busy with school. I'll take a look at this and finish this fast. It's been far too long. Apologize for the lateness @peergynt

@msftclas
Copy link

msftclas commented Mar 12, 2019

CLA assistant check
All CLA requirements met.

@MagnumOpus21
Copy link
Author

@ramya-rao-a Do I have to do anything to get the Go Extension tests to pass for go1.11. It passes for the other versions of golang on Travis.

@ramya-rao-a
Copy link
Contributor

Hey @MagnumOpus21

My apologies for not getting to this sooner

I tried a few more cases with the code in this PR

  • some random things C:/my/folder/fine.go:21: fails as expected because the path is already expanded
  • some random things /my/folder/fine.go:21: does not fail even though the path is an absolute path in non Windows machines.

I am starting to feel that we are getting into risky areas by trying to cater to extract the right relative path that needs to be expanded.

We know what the expanded path needs to look like because we have access to cwd, so I am leaning towards checking the existence of cwd in the output line should be taken as a sign as to not to bother expanding the file path.

Thoughts?

@ramya-rao-a
Copy link
Contributor

Hey @MagnumOpus21

Since working with regexes still left some corner cases not covered, I've decided to take a different approach here. Please see #1836 (comment)

Thanks for all the work here & Happy Coding!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attempt to get absolute path on every line of test output causes wrongful paths
4 participants