Skip to content

Commit e16317d

Browse files
committed
Setup Windows GH actions job
We cannot use the existing windows job setup because it launches a docker container which we cannot open a VS Code window in to run the tests as no tool like Xvfb exists for Windows Fix up some tests that fail on windows (mostly related to path separator mismatches)
1 parent a4d7b0c commit e16317d

File tree

3 files changed

+65
-29
lines changed

3 files changed

+65
-29
lines changed

.github/workflows/pull_request.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,30 @@ jobs:
3737
echo "$NODE_PATH" >> $GITHUB_PATH
3838
linux_build_command: ./docker/test.sh
3939
enable_windows_checks: false
40+
41+
tests-windows:
42+
name: Windows (${{ matrix.swift_version }})
43+
runs-on: ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
swift_version: ['5.9', '5.10', '6.0', 'nightly', 'nightly-6.0']
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v4
51+
- name: Create test script
52+
run: |
53+
mkdir $env:TEMP\test-script
54+
echo 'Set-PSDebug -Trace 1' >> $env:TEMP\test-script\run.ps1
55+
echo '$ErrorActionPreference = "Stop"' >> $env:TEMP\test-script\run.ps1
56+
echo 'winget install --id Microsoft.VisualStudio.2022.Community --exact --force --custom "--add Microsoft.VisualStudio.Component.Windows11SDK.22000 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"' >> $env:TEMP\test-script\run.ps1
57+
echo 'winget install --id Swift.Toolchain -e' >> $env:TEMP\test-script\run.ps1
58+
echo 'winget install --id Schniz.fnm -e' >> $env:TEMP\test-script\run.ps1
59+
echo 'fnm env --use-on-cd | Out-String | Invoke-Expression' >> $env:TEMP\test-script\run.ps1
60+
echo 'fnm use --install-if-missing 18.19.0' >> $env:TEMP\test-script\run.ps1
61+
echo 'refreshenv' >> $env:TEMP\test-script\run.ps1
62+
echo 'swift --version' >> $env:TEMP\test-script\run.ps1
63+
echo 'node --version' >> $env:TEMP\test-script\run.ps1
64+
echo 'cd $env:GITHUB_WORKSPACE' >> $env:TEMP\test-script\run.ps1
65+
echo 'docker\test-windows.ps1' >> $env:TEMP\test-script\run.ps1
66+
powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1

docker/test-windows.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$env:CI = "1"
2+
$env:FAST_TEST_RUN = "1"
3+
npm ci -ignore-script node-pty
4+
npm run lint
5+
npm run format
6+
npm run package
7+
npm run integration-test

test/integration-tests/tasks/SwiftTaskProvider.test.ts

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

15+
import { expect } from "chai";
1516
import * as vscode from "vscode";
1617
import * as assert from "assert";
1718
import { WorkspaceContext } from "../../../src/WorkspaceContext";
@@ -41,7 +42,7 @@ suite("SwiftTaskProvider Test Suite", () => {
4142
suiteSetup(async () => {
4243
workspaceContext = await globalWorkspaceContextPromise;
4344
toolchain = workspaceContext.toolchain;
44-
assert.notEqual(workspaceContext.folders.length, 0);
45+
expect(workspaceContext.folders).to.not.have.lengthOf(0);
4546
workspaceFolder = workspaceContext.folders[0].workspaceFolder;
4647

4748
// Make sure have another folder
@@ -61,10 +62,21 @@ suite("SwiftTaskProvider Test Suite", () => {
6162
toolchain
6263
);
6364
const { exitCode } = await executeTaskAndWaitForResult(task);
64-
assert.equal(exitCode, 0);
65-
}).timeout(10000);
65+
expect(exitCode).to.equal(0);
66+
});
6667

6768
test("Exit code on failure", async () => {
69+
const task = createSwiftTask(
70+
["invalid_swift_command"],
71+
"invalid",
72+
{ cwd: workspaceFolder.uri, scope: vscode.TaskScope.Workspace },
73+
toolchain
74+
);
75+
const { exitCode } = await executeTaskAndWaitForResult(task);
76+
expect(exitCode).to.equal(1);
77+
});
78+
79+
test("Exit code on failure to launch", async () => {
6880
const task = createSwiftTask(
6981
["--help"],
7082
"help",
@@ -82,8 +94,8 @@ suite("SwiftTaskProvider Test Suite", () => {
8294
)
8395
);
8496
const { exitCode } = await executeTaskAndWaitForResult(task);
85-
assert.equal(exitCode, 1);
86-
}).timeout(10000);
97+
expect(exitCode).to.not.equal(0);
98+
});
8799
});
88100

89101
suite("provideTasks", () => {
@@ -96,18 +108,17 @@ suite("SwiftTaskProvider Test Suite", () => {
96108
});
97109

98110
test("provided", async () => {
99-
assert.equal(
100-
task?.detail,
101-
"swift build --build-tests -Xswiftc -diagnostic-style=llvm"
102-
);
111+
expect(task?.detail)
112+
.to.include("swift build --build-tests")
113+
.and.to.include("-Xswiftc -diagnostic-style=llvm");
103114
});
104115

105116
test("executes @slow", async () => {
106117
assert(task);
107118
const exitPromise = waitForEndTaskProcess(task);
108119
await vscode.tasks.executeTask(task);
109120
const exitCode = await exitPromise;
110-
assert.equal(exitCode, 0);
121+
expect(exitCode).to.equal(0);
111122
}).timeout(180000); // 3 minutes to build
112123
});
113124

@@ -120,25 +131,24 @@ suite("SwiftTaskProvider Test Suite", () => {
120131
});
121132

122133
test("provided", async () => {
123-
assert.equal(task?.detail, "swift build --show-bin-path");
134+
expect(task?.detail).to.include("swift build --show-bin-path");
124135
});
125136

126137
test("executes", async () => {
127138
assert(task);
128139
const exitPromise = waitForEndTaskProcess(task);
129140
await vscode.tasks.executeTask(task);
130141
const exitCode = await exitPromise;
131-
assert.equal(exitCode, 0);
142+
expect(exitCode).to.equal(0);
132143
});
133144
});
134145

135146
test("includes product debug task", async () => {
136147
const tasks = await vscode.tasks.fetchTasks({ type: "swift" });
137148
const task = tasks.find(t => t.name === "Build Debug PackageExe (defaultPackage)");
138-
assert.equal(
139-
task?.detail,
140-
"swift build --product PackageExe -Xswiftc -diagnostic-style=llvm"
141-
);
149+
expect(task?.detail)
150+
.to.include("swift build --product PackageExe")
151+
.and.to.include("-Xswiftc -diagnostic-style=llvm");
142152
});
143153

144154
test("includes product release task", async () => {
@@ -147,30 +157,23 @@ suite("SwiftTaskProvider Test Suite", () => {
147157
new vscode.CancellationTokenSource().token
148158
);
149159
const task = tasks.find(t => t.name === "Build Release PackageExe (defaultPackage)");
150-
assert.equal(
151-
task?.detail,
152-
"swift build -c release --product PackageExe -Xswiftc -diagnostic-style=llvm"
153-
);
160+
expect(task?.detail).to.include("swift build -c release --product PackageExe");
154161
});
155162

156163
test("includes additional folders", async () => {
157164
const tasks = await vscode.tasks.fetchTasks({ type: "swift" });
158165
const diagnosticTasks = tasks.filter(t => t.name.endsWith("(diagnostics)"));
159-
assert.equal(diagnosticTasks.length, 3);
166+
expect(diagnosticTasks).to.have.lengthOf(3);
160167
});
161168
});
162169

163170
suite("createBuildAllTask", () => {
164171
test("should return same task instance", async () => {
165-
assert.strictEqual(
166-
createBuildAllTask(folderContext),
167-
createBuildAllTask(folderContext)
168-
);
172+
expect(createBuildAllTask(folderContext)).to.equal(createBuildAllTask(folderContext));
169173
});
170174

171175
test("different task returned for release mode", async () => {
172-
assert.notEqual(
173-
createBuildAllTask(folderContext),
176+
expect(createBuildAllTask(folderContext)).to.not.equal(
174177
createBuildAllTask(folderContext, true)
175178
);
176179
});
@@ -181,8 +184,7 @@ suite("SwiftTaskProvider Test Suite", () => {
181184

182185
test("creates build all task when it cannot find one", async () => {
183186
tasksMock.fetchTasks.resolves([]);
184-
assert.strictEqual(
185-
await getBuildAllTask(folderContext),
187+
await expect(getBuildAllTask(folderContext)).to.eventually.equal(
186188
createBuildAllTask(folderContext)
187189
);
188190
});

0 commit comments

Comments
 (0)