Skip to content

Commit d5933b8

Browse files
authored
Enable unit tests on Windows (#1492)
Only the integration tests were running on Windows in CI. Switch to running `npm run test` which will run both integration and unit tests, and fix path normalization issues that were preventing some tests from passing on Windows.
1 parent 3655586 commit d5933b8

File tree

7 files changed

+40
-23
lines changed

7 files changed

+40
-23
lines changed

scripts/test_windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ npm ci -ignore-script node-pty
6464
npm run lint
6565
npm run format
6666
npm run package
67-
npm run integration-test
67+
npm run test
6868
if ($LASTEXITCODE -eq 0) {
6969
Write-Host 'SUCCESS'
7070
} else {

test/unit-tests/sourcekit-lsp/LanguageClientManager.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import * as vscode from "vscode";
16+
import * as path from "path";
1617
import { expect } from "chai";
1718
import { match } from "sinon";
1819
import { FolderEvent, FolderOperation, WorkspaceContext } from "../../../src/WorkspaceContext";
@@ -301,7 +302,7 @@ suite("LanguageClientManager Suite", () => {
301302
DidChangeWorkspaceFoldersNotification.type,
302303
{
303304
event: {
304-
added: [{ name: "folder1", uri: "/folder1" }],
305+
added: [{ name: "folder1", uri: path.normalize("/folder1") }],
305306
removed: [],
306307
},
307308
} as DidChangeWorkspaceFoldersParams
@@ -320,7 +321,7 @@ suite("LanguageClientManager Suite", () => {
320321
DidChangeWorkspaceFoldersNotification.type,
321322
{
322323
event: {
323-
added: [{ name: "folder2", uri: "/folder2" }],
324+
added: [{ name: "folder2", uri: path.normalize("/folder2") }],
324325
removed: [],
325326
},
326327
} as DidChangeWorkspaceFoldersParams
@@ -340,7 +341,7 @@ suite("LanguageClientManager Suite", () => {
340341
{
341342
event: {
342343
added: [],
343-
removed: [{ name: "folder1", uri: "/folder1" }],
344+
removed: [{ name: "folder1", uri: path.normalize("/folder1") }],
344345
},
345346
} as DidChangeWorkspaceFoldersParams
346347
);
@@ -472,7 +473,7 @@ suite("LanguageClientManager Suite", () => {
472473
DidChangeActiveDocumentNotification.method,
473474
{
474475
textDocument: {
475-
uri: "/folder1/file.swift",
476+
uri: path.normalize("/folder1/file.swift"),
476477
},
477478
} as DidChangeActiveDocumentParams
478479
);
@@ -501,7 +502,7 @@ suite("LanguageClientManager Suite", () => {
501502
DidChangeActiveDocumentNotification.method,
502503
{
503504
textDocument: {
504-
uri: "/folder1/file.swift",
505+
uri: path.normalize("/folder1/file.swift"),
505506
},
506507
} as DidChangeActiveDocumentParams
507508
);

test/unit-tests/tasks/SwiftPluginTaskProvider.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import * as vscode from "vscode";
1616
import * as assert from "assert";
17+
import * as path from "path";
1718
import { match } from "sinon";
1819
import { WorkspaceContext } from "../../../src/WorkspaceContext";
1920
import { SwiftPluginTaskProvider } from "../../../src/tasks/SwiftPluginTaskProvider";
@@ -148,7 +149,10 @@ suite("SwiftPluginTaskProvider Unit Test Suite", () => {
148149
new vscode.CancellationTokenSource().token
149150
);
150151
const swiftExecution = resolvedTask.execution as SwiftExecution;
151-
assert.equal(swiftExecution.options.cwd, `${workspaceFolder.uri.fsPath}/myCWD`);
152+
assert.equal(
153+
swiftExecution.options.cwd,
154+
path.normalize(`${workspaceFolder.uri.fsPath}/myCWD`)
155+
);
152156
});
153157

154158
test("includes fallback cwd", async () => {

test/unit-tests/toolchain/BuildFlags.test.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import * as path from "path";
1516
import { expect } from "chai";
1617
import { DarwinCompatibleTarget, SwiftToolchain } from "../../../src/toolchain/toolchain";
1718
import { ArgumentFilter, BuildFlags } from "../../../src/toolchain/BuildFlags";
@@ -204,35 +205,41 @@ suite("BuildFlags Test Suite", () => {
204205

205206
expect(
206207
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
207-
).to.equal(".build");
208+
).to.equal(path.normalize(".build"));
208209

209210
expect(
210211
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
211-
).to.equal("/some/full/workspace/test/path/.build");
212+
).to.equal(path.normalize("/some/full/workspace/test/path/.build"));
212213
});
213214

214215
test("absolute configuration provided", () => {
215-
buildPathConfig.setValue("/some/other/full/test/path");
216+
buildPathConfig.setValue(path.normalize("/some/other/full/test/path"));
216217

217218
expect(
218-
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
219-
).to.equal("/some/other/full/test/path");
219+
BuildFlags.buildDirectoryFromWorkspacePath(
220+
path.normalize("/some/full/workspace/test/path"),
221+
false
222+
)
223+
).to.equal(path.normalize("/some/other/full/test/path"));
220224

221225
expect(
222-
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
223-
).to.equal("/some/other/full/test/path");
226+
BuildFlags.buildDirectoryFromWorkspacePath(
227+
path.normalize("/some/full/workspace/test/path"),
228+
true
229+
)
230+
).to.equal(path.normalize("/some/other/full/test/path"));
224231
});
225232

226233
test("relative configuration provided", () => {
227-
buildPathConfig.setValue("some/relative/test/path");
234+
buildPathConfig.setValue(path.normalize("some/relative/test/path"));
228235

229236
expect(
230237
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", false)
231-
).to.equal("some/relative/test/path");
238+
).to.equal(path.normalize("some/relative/test/path"));
232239

233240
expect(
234241
BuildFlags.buildDirectoryFromWorkspacePath("/some/full/workspace/test/path", true)
235-
).to.equal("/some/full/workspace/test/path/some/relative/test/path");
242+
).to.equal(path.normalize("/some/full/workspace/test/path/some/relative/test/path"));
236243
});
237244
});
238245

test/unit-tests/toolchain/toolchain.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import { expect } from "chai";
16+
import * as path from "path";
1617
import * as mockFS from "mock-fs";
1718
import * as utilities from "../../../src/utilities/utilities";
1819
import { SwiftToolchain } from "../../../src/toolchain/toolchain";
@@ -78,7 +79,9 @@ suite("SwiftToolchain Unit Test Suite", () => {
7879
});
7980

8081
await expect(sut.getLLDBDebugAdapter()).to.eventually.equal(
81-
"/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lldb-dap"
82+
path.normalize(
83+
"/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lldb-dap"
84+
)
8285
);
8386
});
8487

@@ -174,7 +177,7 @@ suite("SwiftToolchain Unit Test Suite", () => {
174177
});
175178

176179
await expect(sut.getLLDBDebugAdapter()).to.eventually.equal(
177-
"/toolchains/swift-6.0.0/usr/bin/lldb-dap"
180+
path.normalize("/toolchains/swift-6.0.0/usr/bin/lldb-dap")
178181
);
179182
});
180183

@@ -213,7 +216,7 @@ suite("SwiftToolchain Unit Test Suite", () => {
213216
});
214217

215218
await expect(sut.getLLDBDebugAdapter()).to.eventually.equal(
216-
"/toolchains/swift-6.0.0/usr/bin/lldb-dap.exe"
219+
path.normalize("/toolchains/swift-6.0.0/usr/bin/lldb-dap.exe")
217220
);
218221
});
219222

test/unit-tests/ui/PackageDependencyProvider.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import { expect } from "chai";
16+
import * as path from "path";
1617
import * as vscode from "vscode";
1718
import * as fs from "fs/promises";
1819
import { FileNode, PackageNode } from "../../../src/ui/ProjectPanelProvider";
@@ -100,13 +101,13 @@ suite("PackageDependencyProvider Unit Test Suite", function () {
100101
expect(childFiles).to.deep.equal([
101102
new FileNode(
102103
"file1",
103-
"/path/to/.build/swift-markdown/file1",
104+
path.normalize("/path/to/.build/swift-markdown/file1"),
104105
false,
105106
"SwiftMarkdown-1.2.3"
106107
),
107108
new FileNode(
108109
"file2",
109-
"/path/to/.build/swift-markdown/file2",
110+
path.normalize("/path/to/.build/swift-markdown/file2"),
110111
false,
111112
"SwiftMarkdown-1.2.3"
112113
),

test/unit-tests/utilities/filesystem.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import * as path from "path";
1516
import { isPathInsidePath, expandFilePathTilde } from "../../../src/utilities/filesystem";
1617
import { expect } from "chai";
1718

@@ -30,7 +31,7 @@ suite("File System Utilities Unit Test Suite", () => {
3031
suite("expandFilePathTilde", () => {
3132
test("expands tilde", () => {
3233
expect(expandFilePathTilde("~/Test", "/Users/John", "darwin")).to.equal(
33-
"/Users/John/Test"
34+
path.normalize("/Users/John/Test")
3435
);
3536
});
3637

0 commit comments

Comments
 (0)