Skip to content

Commit 47f6dfa

Browse files
committed
test/integration/goTest: fix populateModulePathCache
And reenable affected tests. The tests were broken due to a bug in composing the file Uris for files in a directory from the directory Uri. path.join uses the platform specific separator (\ on windows). To ensure the correct encoding, convert the directory Uri to its fsPath, construct the file path of the file, and convert the file path to Uri. For #832 For #1788 Change-Id: I3dfc44e04f1683b1b862b339b7257b432c3f2241 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/418545 Reviewed-by: Suzy Mueller <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 1adebbb commit 47f6dfa

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

src/goModules.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ export function isModSupported(fileuri?: vscode.Uri, isDir?: boolean): Promise<b
4848
return getModFolderPath(fileuri, isDir).then((modPath) => !!modPath);
4949
}
5050

51+
// packagePathToGoModPathMap is a cache that maps from a file path (of a package directory)
52+
// to the module root directory path (directory of `go env GOMOD`) if the file belongs to a module.
5153
export const packagePathToGoModPathMap: { [key: string]: string } = {};
5254

55+
// getModFolderPath returns the module root of the file. '' or undefined value indicates
56+
// the file is outside of any module or Go module is disabled.
5357
export async function getModFolderPath(fileuri?: vscode.Uri, isDir?: boolean): Promise<string | undefined> {
5458
const pkgUri = isDir ? fileuri : fileuri && vscodeUri.Utils.dirname(fileuri);
5559
const pkgPath = pkgUri?.fsPath ?? '';

test/integration/goTest.explore.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ async function forceResolve(resolver: GoTestResolver, item?: TestItem) {
5757

5858
suite('Go Test Explorer', () => {
5959
suite('Document opened', () => {
60-
if (affectedByIssue832()) {
61-
return;
62-
}
6360
class DUT extends GoTestExplorer {
6461
async _didOpen(doc: TextDocument) {
6562
await this.didOpenTextDocument(doc);
@@ -117,9 +114,6 @@ suite('Go Test Explorer', () => {
117114
});
118115

119116
suite('Document edited', async () => {
120-
if (affectedByIssue832()) {
121-
return;
122-
}
123117
class DUT extends GoTestExplorer {
124118
async _didOpen(doc: TextDocument) {
125119
await this.didOpenTextDocument(doc);

test/integration/goTest.resolve.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { GoTestResolver } from '../../src/goTest/resolve';
88
import { GoTest, GoTestKind } from '../../src/goTest/utils';
99
import { MockTestController, MockTestWorkspace } from '../mocks/MockTest';
1010
import { getSymbols_Regex, populateModulePathCache } from './goTest.utils';
11-
import { affectedByIssue832 } from './testutils';
1211

1312
type Files = Record<string, string | { contents: string; language: string }>;
1413

@@ -26,9 +25,6 @@ function setup(folders: string[], files: Files) {
2625
}
2726

2827
suite('Go Test Resolver', () => {
29-
if (affectedByIssue832()) {
30-
return;
31-
}
3228
interface TC extends TestCase {
3329
item?: ([string, string, GoTestKind] | [string, string, GoTestKind, string])[];
3430
expect: string[];

test/integration/goTest.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export function populateModulePathCache(workspace: MockTestWorkspace) {
2424
function walk(dir: Uri, modpath?: string) {
2525
const dirs: Uri[] = [];
2626
for (const [name, type] of workspace.fs.dirs.get(dir.toString()) ?? []) {
27-
const uri = dir.with({ path: path.join(dir.path, name) });
27+
const uri = Uri.file(path.join(dir.fsPath, name));
2828
if (type === FileType.Directory) {
2929
dirs.push(uri);
3030
} else if (name === 'go.mod') {
31-
modpath = dir.path;
31+
modpath = dir.fsPath;
3232
}
3333
}
34-
packagePathToGoModPathMap[dir.path] = modpath || '';
34+
packagePathToGoModPathMap[dir.fsPath] = modpath || '';
3535
for (const dir of dirs) {
3636
walk(dir, modpath);
3737
}

0 commit comments

Comments
 (0)