Skip to content

Commit 03ae18d

Browse files
committed
Always use unified testing binary
The .swift-testing binary is no longer output, it has been rolled in to a single binary for both XCTest and Swift Testing we no longer need to test for this distinction now that the nightly toolchains have been producing this unified binary for enough time. Issue: #994
1 parent 303d4d2 commit 03ae18d

File tree

2 files changed

+25
-70
lines changed

2 files changed

+25
-70
lines changed

Diff for: src/TestExplorer/TestRunner.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export class TestRunner {
489489
await execFile("mkfifo", [fifoPipePath], undefined, this.folderContext);
490490
}
491491

492-
const testBuildConfig = await TestingConfigurationFactory.swiftTestingConfig(
492+
const testBuildConfig = TestingConfigurationFactory.swiftTestingConfig(
493493
this.folderContext,
494494
fifoPipePath,
495495
this.testKind,
@@ -523,7 +523,7 @@ export class TestRunner {
523523
}
524524

525525
if (this.testArgs.hasXCTests) {
526-
const testBuildConfig = await TestingConfigurationFactory.xcTestConfig(
526+
const testBuildConfig = TestingConfigurationFactory.xcTestConfig(
527527
this.folderContext,
528528
this.testKind,
529529
this.testArgs.xcTestArgs,
@@ -768,7 +768,7 @@ export class TestRunner {
768768
await execFile("mkfifo", [fifoPipePath], undefined, this.folderContext);
769769
}
770770

771-
const swiftTestBuildConfig = await TestingConfigurationFactory.swiftTestingConfig(
771+
const swiftTestBuildConfig = TestingConfigurationFactory.swiftTestingConfig(
772772
this.folderContext,
773773
fifoPipePath,
774774
this.testKind,
@@ -802,7 +802,7 @@ export class TestRunner {
802802

803803
// create launch config for testing
804804
if (this.testArgs.hasXCTests) {
805-
const xcTestBuildConfig = await TestingConfigurationFactory.xcTestConfig(
805+
const xcTestBuildConfig = TestingConfigurationFactory.xcTestConfig(
806806
this.folderContext,
807807
this.testKind,
808808
this.testArgs.xcTestArgs,

Diff for: src/debugger/buildConfig.ts

+21-66
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import * as os from "os";
1616
import * as path from "path";
1717
import * as vscode from "vscode";
18-
import * as fs from "fs/promises";
1918
import configuration from "../configuration";
2019
import { FolderContext } from "../FolderContext";
2120
import { BuildFlags } from "../toolchain/BuildFlags";
@@ -104,13 +103,13 @@ export class BuildConfigurationFactory {
104103
* and `xcTestConfig` functions to create
105104
*/
106105
export class TestingConfigurationFactory {
107-
public static async swiftTestingConfig(
106+
public static swiftTestingConfig(
108107
ctx: FolderContext,
109108
fifoPipePath: string,
110109
testKind: TestKind,
111110
testList: string[],
112111
expandEnvVariables = false
113-
): Promise<vscode.DebugConfiguration | null> {
112+
): vscode.DebugConfiguration | null {
114113
return new TestingConfigurationFactory(
115114
ctx,
116115
fifoPipePath,
@@ -121,12 +120,12 @@ export class TestingConfigurationFactory {
121120
).build();
122121
}
123122

124-
public static async xcTestConfig(
123+
public static xcTestConfig(
125124
ctx: FolderContext,
126125
testKind: TestKind,
127126
testList: string[],
128127
expandEnvVariables = false
129-
): Promise<vscode.DebugConfiguration | null> {
128+
): vscode.DebugConfiguration | null {
130129
return new TestingConfigurationFactory(
131130
ctx,
132131
"",
@@ -137,11 +136,11 @@ export class TestingConfigurationFactory {
137136
).build();
138137
}
139138

140-
public static async testExecutableOutputPath(
139+
public static testExecutableOutputPath(
141140
ctx: FolderContext,
142141
testKind: TestKind,
143142
testLibrary: TestLibrary
144-
): Promise<string> {
143+
): string {
145144
return new TestingConfigurationFactory(
146145
ctx,
147146
"",
@@ -169,7 +168,7 @@ export class TestingConfigurationFactory {
169168
* - Test Kind (coverage, debugging)
170169
* - Test Library (XCTest, swift-testing)
171170
*/
172-
private async build(): Promise<vscode.DebugConfiguration | null> {
171+
private build(): vscode.DebugConfiguration | null {
173172
if (!this.hasTestTarget) {
174173
return null;
175174
}
@@ -185,7 +184,7 @@ export class TestingConfigurationFactory {
185184
}
186185

187186
/* eslint-disable no-case-declarations */
188-
private async buildWindowsConfig(): Promise<vscode.DebugConfiguration | null> {
187+
private buildWindowsConfig(): vscode.DebugConfiguration | null {
189188
if (isDebugging(this.testKind)) {
190189
const testEnv = {
191190
...swiftRuntimeEnv(),
@@ -201,8 +200,8 @@ export class TestingConfigurationFactory {
201200

202201
return {
203202
...this.baseConfig,
204-
program: await this.testExecutableOutputPath(),
205-
args: await this.debuggingTestExecutableArgs(),
203+
program: this.testExecutableOutputPath(),
204+
args: this.debuggingTestExecutableArgs(),
206205
env: testEnv,
207206
};
208207
} else {
@@ -211,23 +210,23 @@ export class TestingConfigurationFactory {
211210
}
212211

213212
/* eslint-disable no-case-declarations */
214-
private async buildLinuxConfig(): Promise<vscode.DebugConfiguration | null> {
213+
private buildLinuxConfig(): vscode.DebugConfiguration | null {
215214
if (isDebugging(this.testKind) && this.testLibrary === TestLibrary.xctest) {
216215
return {
217216
...this.baseConfig,
218-
program: await this.testExecutableOutputPath(),
219-
args: await this.debuggingTestExecutableArgs(),
217+
program: this.testExecutableOutputPath(),
218+
args: this.debuggingTestExecutableArgs(),
220219
env: {
221220
...swiftRuntimeEnv(),
222221
...configuration.folder(this.ctx.workspaceFolder).testEnvironmentVariables,
223222
},
224223
};
225224
} else {
226-
return await this.buildDarwinConfig();
225+
return this.buildDarwinConfig();
227226
}
228227
}
229228

230-
private async buildDarwinConfig(): Promise<vscode.DebugConfiguration | null> {
229+
private buildDarwinConfig(): vscode.DebugConfiguration | null {
231230
switch (this.testLibrary) {
232231
case TestLibrary.swiftTesting:
233232
switch (this.testKind) {
@@ -272,8 +271,8 @@ export class TestingConfigurationFactory {
272271

273272
const result = {
274273
...this.baseConfig,
275-
program: await this.testExecutableOutputPath(),
276-
args: await this.debuggingTestExecutableArgs(),
274+
program: this.testExecutableOutputPath(),
275+
args: this.debuggingTestExecutableArgs(),
277276
env: {
278277
...this.testEnv,
279278
...this.sanitizerRuntimeEnvironment,
@@ -519,45 +518,6 @@ export class TestingConfigurationFactory {
519518
);
520519
}
521520

522-
private swiftTestingOutputPath(): string {
523-
return path.join(
524-
this.buildDirectory,
525-
this.artifactFolderForTestKind,
526-
`${this.ctx.swiftPackage.name}PackageTests.swift-testing`
527-
);
528-
}
529-
530-
private buildDescriptionPath(): string {
531-
return path.join(this.buildDirectory, this.artifactFolderForTestKind, "description.json");
532-
}
533-
534-
private async isUnifiedTestingBinary(): Promise<boolean> {
535-
// Toolchains that contain https://github.com/swiftlang/swift-package-manager/commit/844bd137070dcd18d0f46dd95885ef7907ea0697
536-
// no longer produce a .swift-testing binary, instead we want to use `unifiedTestingOutputPath`.
537-
// In order to determine if we're working with a unified binary we need to check if the .swift-testing
538-
// binary was produced by the latest build. If it was then we are not using a unified binary.
539-
540-
// TODO: When Swift 6 is released and enough time has passed that we're sure no one is building the .swift-testing
541-
// binary anymore this workaround can be removed and `swiftTestingPath` can be returned, and the build config
542-
// generation can be made synchronous again.
543-
544-
try {
545-
const buildDescriptionStr = await fs.readFile(this.buildDescriptionPath(), "utf-8");
546-
const buildDescription = JSON.parse(buildDescriptionStr);
547-
const testProducts = buildDescription.builtTestProducts as { binaryPath: string }[];
548-
if (!testProducts) {
549-
return false;
550-
}
551-
const testBinaryPaths = testProducts.map(({ binaryPath }) => binaryPath);
552-
const swiftTestingBinaryRealPath = await fs.realpath(this.swiftTestingOutputPath());
553-
return !testBinaryPaths.includes(swiftTestingBinaryRealPath);
554-
} catch {
555-
// If the .swift-testing binary wasn't produced by the latest build then we assume the
556-
// swift-testing tests are in the unified binary.
557-
return true;
558-
}
559-
}
560-
561521
private unifiedTestingOutputPath(): string {
562522
// The unified binary that contains both swift-testing and XCTests
563523
// is named the same as the old style .xctest binary. The swiftpm-testing-helper
@@ -574,24 +534,19 @@ export class TestingConfigurationFactory {
574534
}
575535
}
576536

577-
private async testExecutableOutputPath(): Promise<string> {
537+
private testExecutableOutputPath(): string {
578538
switch (this.testLibrary) {
579539
case TestLibrary.swiftTesting:
580-
return (await this.isUnifiedTestingBinary())
581-
? this.unifiedTestingOutputPath()
582-
: this.swiftTestingOutputPath();
540+
return this.unifiedTestingOutputPath();
583541
case TestLibrary.xctest:
584542
return this.xcTestOutputPath();
585543
}
586544
}
587545

588-
private async debuggingTestExecutableArgs(): Promise<string[]> {
546+
private debuggingTestExecutableArgs(): string[] {
589547
switch (this.testLibrary) {
590548
case TestLibrary.swiftTesting: {
591-
const isUnifiedBinary = await this.isUnifiedTestingBinary();
592-
const swiftTestingArgs = isUnifiedBinary
593-
? ["--testing-library", "swift-testing"]
594-
: [];
549+
const swiftTestingArgs = ["--testing-library", "swift-testing"];
595550

596551
return this.addBuildOptionsToArgs(
597552
this.addTestsToArgs(this.addSwiftTestingFlagsArgs(swiftTestingArgs))

0 commit comments

Comments
 (0)