src/goTest: always mark workspace uri as directory
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. (golang/vscode-go#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 golang/vscode-go#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>
diff --git a/src/goModules.ts b/src/goModules.ts
index ed11c1b..87f50f5 100644
--- a/src/goModules.ts
+++ b/src/goModules.ts
@@ -29,7 +29,7 @@
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);
@@ -179,7 +179,7 @@
.split('\n')
.filter((line) => line && line.indexOf(' ') === -1);
if (pkgs.length !== 1) {
- resolve();
+ resolve('');
return;
}
folderToPackageMapping[cwd] = pkgs[0];
diff --git a/src/goTest.ts b/src/goTest.ts
index 5b1576d..89ec4ad 100644
--- a/src/goTest.ts
+++ b/src/goTest.ts
@@ -241,13 +241,11 @@
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;
}
@@ -260,7 +258,7 @@
// 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);
diff --git a/src/testUtils.ts b/src/testUtils.ts
index 74fc1ae..9c8a311 100644
--- a/src/testUtils.ts
+++ b/src/testUtils.ts
@@ -452,8 +452,8 @@
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) => {