Skip to content

Commit

Permalink
src/goTest: always mark workspace uri as directory
Browse files Browse the repository at this point in the history
This completes the bug https://go-review.googlesource.com/c/vscode-go/+/242642
intended to fix  - isModSupported treats the first parameter as a directory
only if the second parameter is set. I don't know why I thought we shouldn't
set when there is active text editer. workspace file path should be always
a directory.

This bug made the `testWorkspace` function (in goTest.ts) to incorrectly
populate testConfig's isMod field. That caused the `goTest` function failed to
compute the pkgMap correctly when the workspace has go.mod. (See line 308-321
of testUtils.ts).

Without pkgMap, `processTestResultLineInStandardMode` couldn't compute
the path-to-directory path mapping. As a result,
  - the file name expansion (expandFIlePathInOutput) couldn't work, and
  - the test output was buffered until all tests in the workspace
    finished. (#917)

While we are here, this CL updates the test output match regexp
to capture the line like `? pkgpath [no test files]`, and fixes two lint errors
reported by eslint (goModules.ts)

Fixes #917

Change-Id: Ib3c9e66a1295a0673c8fed1b45399c4d156cd3b0
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/269917
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
  • Loading branch information
hyangah committed Nov 13, 2020
1 parent f05c05e commit e6ab6f4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/goModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function runGoModEnv(folderPath: string): Promise<string> {
cp.execFile(goExecutable, ['env', 'GOMOD'], { cwd: folderPath, env }, (err, stdout) => {
if (err) {
console.warn(`Error when running go env GOMOD: ${err}`);
return resolve();
return resolve('');
}
const [goMod] = stdout.split('\n');
resolve(goMod);
Expand Down Expand Up @@ -179,7 +179,7 @@ export async function getCurrentPackage(cwd: string): Promise<string> {
.split('\n')
.filter((line) => line && line.indexOf(' ') === -1);
if (pkgs.length !== 1) {
resolve();
resolve('');
return;
}
folderToPackageMapping[cwd] = pkgs[0];
Expand Down
4 changes: 1 addition & 3 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,11 @@ export function testWorkspace(goConfig: vscode.WorkspaceConfiguration, args: any
vscode.window.showInformationMessage('No workspace is open to run tests.');
return;
}
let workspaceUriIsDir = true;
let workspaceUri = vscode.workspace.workspaceFolders[0].uri;
if (
vscode.window.activeTextEditor &&
vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)
) {
workspaceUriIsDir = false;
workspaceUri = vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri).uri;
}

Expand All @@ -260,7 +258,7 @@ export function testWorkspace(goConfig: vscode.WorkspaceConfiguration, args: any
// Remember this config as the last executed test.
lastTestConfig = testConfig;

isModSupported(workspaceUri, workspaceUriIsDir).then((isMod) => {
isModSupported(workspaceUri, true).then((isMod) => {
testConfig.isMod = isMod;
goTest(testConfig).then(null, (err) => {
console.error(err);
Expand Down
4 changes: 2 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ function processTestResultLineInStandardMode(
currentGoWorkspace: string,
testResultLines: string[],
outputChannel: vscode.OutputChannel) {
// 1=ok/FAIL, 2=package, 3=time/(cached)
const packageResultLineRE = /^(ok|FAIL)\s+(\S+)\s+([0-9\.]+s|\(cached\))/;
// 1=ok/FAIL/?, 2=package, 3=time/(cached)/[no test files]
const packageResultLineRE = /^(ok|FAIL|\?)\s+(\S+)\s+([0-9\.]+s|\(cached\)|\[no test files\])/;
const lineWithErrorRE = /^(\t|\s\s\s\s)\S/;

return (line: string) => {
Expand Down

0 comments on commit e6ab6f4

Please sign in to comment.