Skip to content

Add XCTest.dll path to Path when testing on Windows #977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/debugger/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,42 @@ export class TestingDebugConfigurationFactory {

switch (process.platform) {
case "darwin":
return this.buildDarwinConfg();
return this.buildDarwinConfig();
case "win32":
return this.buildWindowsConfig();
default:
return this.buildNonDarwinConfig();
return this.buildLinuxConfig();
}
}

/* eslint-disable no-case-declarations */
private buildNonDarwinConfig(): vscode.DebugConfiguration | null {
private buildWindowsConfig(): vscode.DebugConfiguration | null {
if (isDebugging(this.testKind) && this.testLibrary === TestLibrary.xctest) {
const testEnv = {
...swiftRuntimeEnv(),
...configuration.folder(this.ctx.workspaceFolder).testEnvironmentVariables,
};
// On Windows, add XCTest.dll to the Path
// and run the .xctest executable from the .build directory.
const runtimePath = this.ctx.workspaceContext.toolchain.runtimePath;
const xcTestPath = this.ctx.workspaceContext.toolchain.xcTestPath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible xcTestPath could be undefined, check that it isn't undefined as well before adding it to the Path

if (xcTestPath && xcTestPath !== runtimePath) {
testEnv.Path = `${xcTestPath};${testEnv.Path ?? process.env.Path}`;
}

return {
...this.baseConfig,
program: this.xcTestOutputPath,
args: this.testList,
env: testEnv,
};
} else {
return this.buildDarwinConfig();
}
}

/* eslint-disable no-case-declarations */
private buildLinuxConfig(): vscode.DebugConfiguration | null {
if (isDebugging(this.testKind) && this.testLibrary === TestLibrary.xctest) {
return {
...this.baseConfig,
Expand All @@ -108,11 +136,11 @@ export class TestingDebugConfigurationFactory {
},
};
} else {
return this.buildDarwinConfg();
return this.buildDarwinConfig();
}
}

private buildDarwinConfg(): vscode.DebugConfiguration | null {
private buildDarwinConfig(): vscode.DebugConfiguration | null {
switch (this.testLibrary) {
case TestLibrary.swiftTesting:
switch (this.testKind) {
Expand Down