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

Fix file path expansion for subpackages in go test output. #1651

Merged
merged 2 commits into from
May 11, 2018

Conversation

doxxx
Copy link
Contributor

@doxxx doxxx commented May 2, 2018

This fixes #1626 by using the package name from the go test output combined with the workspace root folder path to expand filenames to their correct path. go test itself buffers all test output in a package until all the tests in a package have completed, so adding our own per-package buffering does not have a visible effect on the latency of test reporting.

@msftclas
Copy link

msftclas commented May 2, 2018

CLA assistant check
All CLA requirements met.

@doxxx
Copy link
Contributor Author

doxxx commented May 8, 2018

@ramya-rao-a Is there anything else needed here?

src/testUtils.ts Outdated
const result = line.match(packageResultLineRE);
if (result) {
const packageNameArr = result[2].split('/');
const baseDir = path.join(workspaceRoot, ...packageNameArr.slice(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Using workspaceRoot doesn't work always here.

For example, assume I have opened the golang example repo in vscode and assume that a test in the stringutil package is failing

workspaceRoot will be /Users/myGopath/src/github.com/golang/example
packageNameArr after the slice will be [golang, example, stringutil]
baseDir becomes /Users/myGopath/src/github.com/golang/example/golang/example/stringutil which is wrong

currentGoWorkspace variable on the other hand has what you need. So use that instead
`const baseDir = path.join(currentGoWorkspace, ...packageNameArr);

Note that currentGoWorkspace can be undefined when we cannot determine the gopath or if current file doesn't not belong to current workspace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

src/testUtils.ts Outdated
const packageNameArr = result[2].split('/');
const baseDir = path.join(workspaceRoot, ...packageNameArr.slice(1));
testResultLines.forEach(line => outputChannel.appendLine(expandFilePathInOutput(line, baseDir)));
testResultLines.splice(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is to reset the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It removes the elements without allocating a new array.

src/testUtils.ts Outdated
if (result) {
const packageNameArr = result[2].split('/');
const baseDir = path.join(workspaceRoot, ...packageNameArr.slice(1));
testResultLines.forEach(line => outputChannel.appendLine(expandFilePathInOutput(line, baseDir)));
Copy link
Contributor

Choose a reason for hiding this comment

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

For any which reason, in case go test changes the way it outputs result, then we will end up not showing anything in the output channel. I would prefer to pull the printing to the output channel out of the if block here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've fixed this by emitting any remaining lines at the end of the test output. If the regex doesn't match because the go test output has changed, this should emit all the results at the end. It's not ideal since none of the results will be visible until all of the tests have finished, but there's not much else I can do.

- Use the current Go workspace to resolve the full path to packages.
- Don't expand file paths if the current Go workspace is not defined.
- If there are any remaining buffered test result lines, emit them at the end.
@ramya-rao-a ramya-rao-a merged commit 1bbafb2 into microsoft:master May 11, 2018
@ramya-rao-a
Copy link
Contributor

Thanks!

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.

Links to source files in go test output are not correct for when testing all pkgs in workspace
3 participants