Skip to content

Commit 32cb840

Browse files
authored
Always use unified testing binary (#1049)
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 eaabdf1 commit 32cb840

File tree

2 files changed

+25
-69
lines changed

2 files changed

+25
-69
lines changed

src/TestExplorer/TestRunner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ export class TestRunner {
577577
fifoPipePath,
578578
attachmentFolder
579579
);
580-
const testBuildConfig = await TestingConfigurationFactory.swiftTestingConfig(
580+
const testBuildConfig = TestingConfigurationFactory.swiftTestingConfig(
581581
this.folderContext,
582582
swiftTestingArgs,
583583
this.testKind,
@@ -612,7 +612,7 @@ export class TestRunner {
612612
}
613613

614614
if (this.testArgs.hasXCTests) {
615-
const testBuildConfig = await TestingConfigurationFactory.xcTestConfig(
615+
const testBuildConfig = TestingConfigurationFactory.xcTestConfig(
616616
this.folderContext,
617617
this.testKind,
618618
this.testArgs.xcTestArgs,
@@ -862,7 +862,7 @@ export class TestRunner {
862862
attachmentFolder
863863
);
864864

865-
const swiftTestBuildConfig = await TestingConfigurationFactory.swiftTestingConfig(
865+
const swiftTestBuildConfig = TestingConfigurationFactory.swiftTestingConfig(
866866
this.folderContext,
867867
swiftTestingArgs,
868868
this.testKind,
@@ -896,7 +896,7 @@ export class TestRunner {
896896

897897
// create launch config for testing
898898
if (this.testArgs.hasXCTests) {
899-
const xcTestBuildConfig = await TestingConfigurationFactory.xcTestConfig(
899+
const xcTestBuildConfig = TestingConfigurationFactory.xcTestConfig(
900900
this.folderContext,
901901
this.testKind,
902902
this.testArgs.xcTestArgs,

src/debugger/buildConfig.ts

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ export class SwiftTestingConfigurationSetup {
186186
* and `xcTestConfig` functions to create
187187
*/
188188
export class TestingConfigurationFactory {
189-
public static async swiftTestingConfig(
189+
public static swiftTestingConfig(
190190
ctx: FolderContext,
191191
buildArguments: SwiftTestingBuildAguments,
192192
testKind: TestKind,
193193
testList: string[],
194194
expandEnvVariables = false
195-
): Promise<vscode.DebugConfiguration | null> {
195+
): vscode.DebugConfiguration | null {
196196
return new TestingConfigurationFactory(
197197
ctx,
198198
testKind,
@@ -203,12 +203,12 @@ export class TestingConfigurationFactory {
203203
).build();
204204
}
205205

206-
public static async xcTestConfig(
206+
public static xcTestConfig(
207207
ctx: FolderContext,
208208
testKind: TestKind,
209209
testList: string[],
210210
expandEnvVariables = false
211-
): Promise<vscode.DebugConfiguration | null> {
211+
): vscode.DebugConfiguration | null {
212212
return new TestingConfigurationFactory(
213213
ctx,
214214
testKind,
@@ -219,11 +219,11 @@ export class TestingConfigurationFactory {
219219
).build();
220220
}
221221

222-
public static async testExecutableOutputPath(
222+
public static testExecutableOutputPath(
223223
ctx: FolderContext,
224224
testKind: TestKind,
225225
testLibrary: TestLibrary
226-
): Promise<string> {
226+
): string {
227227
return new TestingConfigurationFactory(
228228
ctx,
229229
testKind,
@@ -251,7 +251,7 @@ export class TestingConfigurationFactory {
251251
* - Test Kind (coverage, debugging)
252252
* - Test Library (XCTest, swift-testing)
253253
*/
254-
private async build(): Promise<vscode.DebugConfiguration | null> {
254+
private build(): vscode.DebugConfiguration | null {
255255
if (!this.hasTestTarget) {
256256
return null;
257257
}
@@ -267,7 +267,7 @@ export class TestingConfigurationFactory {
267267
}
268268

269269
/* eslint-disable no-case-declarations */
270-
private async buildWindowsConfig(): Promise<vscode.DebugConfiguration | null> {
270+
private buildWindowsConfig(): vscode.DebugConfiguration | null {
271271
if (isDebugging(this.testKind)) {
272272
const testEnv = {
273273
...swiftRuntimeEnv(),
@@ -288,8 +288,8 @@ export class TestingConfigurationFactory {
288288

289289
return {
290290
...this.baseConfig,
291-
program: await this.testExecutableOutputPath(),
292-
args: await this.debuggingTestExecutableArgs(),
291+
program: this.testExecutableOutputPath(),
292+
args: this.debuggingTestExecutableArgs(),
293293
env: testEnv,
294294
};
295295
} else {
@@ -298,12 +298,12 @@ export class TestingConfigurationFactory {
298298
}
299299

300300
/* eslint-disable no-case-declarations */
301-
private async buildLinuxConfig(): Promise<vscode.DebugConfiguration | null> {
301+
private buildLinuxConfig(): vscode.DebugConfiguration | null {
302302
if (isDebugging(this.testKind) && this.testLibrary === TestLibrary.xctest) {
303303
return {
304304
...this.baseConfig,
305-
program: await this.testExecutableOutputPath(),
306-
args: await this.debuggingTestExecutableArgs(),
305+
program: this.testExecutableOutputPath(),
306+
args: this.debuggingTestExecutableArgs(),
307307
env: {
308308
...swiftRuntimeEnv(
309309
process.env,
@@ -313,11 +313,11 @@ export class TestingConfigurationFactory {
313313
},
314314
};
315315
} else {
316-
return await this.buildDarwinConfig();
316+
return this.buildDarwinConfig();
317317
}
318318
}
319319

320-
private async buildDarwinConfig(): Promise<vscode.DebugConfiguration | null> {
320+
private buildDarwinConfig(): vscode.DebugConfiguration | null {
321321
switch (this.testLibrary) {
322322
case TestLibrary.swiftTesting:
323323
switch (this.testKind) {
@@ -362,8 +362,8 @@ export class TestingConfigurationFactory {
362362

363363
const result = {
364364
...this.baseConfig,
365-
program: await this.testExecutableOutputPath(),
366-
args: await this.debuggingTestExecutableArgs(),
365+
program: this.testExecutableOutputPath(),
366+
args: this.debuggingTestExecutableArgs(),
367367
env: {
368368
...this.testEnv,
369369
...this.sanitizerRuntimeEnvironment,
@@ -631,45 +631,6 @@ export class TestingConfigurationFactory {
631631
);
632632
}
633633

634-
private swiftTestingOutputPath(): string {
635-
return path.join(
636-
this.buildDirectory,
637-
this.artifactFolderForTestKind,
638-
`${this.ctx.swiftPackage.name}PackageTests.swift-testing`
639-
);
640-
}
641-
642-
private buildDescriptionPath(): string {
643-
return path.join(this.buildDirectory, this.artifactFolderForTestKind, "description.json");
644-
}
645-
646-
private async isUnifiedTestingBinary(): Promise<boolean> {
647-
// Toolchains that contain https://github.com/swiftlang/swift-package-manager/commit/844bd137070dcd18d0f46dd95885ef7907ea0697
648-
// no longer produce a .swift-testing binary, instead we want to use `unifiedTestingOutputPath`.
649-
// In order to determine if we're working with a unified binary we need to check if the .swift-testing
650-
// binary was produced by the latest build. If it was then we are not using a unified binary.
651-
652-
// TODO: When Swift 6 is released and enough time has passed that we're sure no one is building the .swift-testing
653-
// binary anymore this workaround can be removed and `swiftTestingPath` can be returned, and the build config
654-
// generation can be made synchronous again.
655-
656-
try {
657-
const buildDescriptionStr = await fs.readFile(this.buildDescriptionPath(), "utf-8");
658-
const buildDescription = JSON.parse(buildDescriptionStr);
659-
const testProducts = buildDescription.builtTestProducts as { binaryPath: string }[];
660-
if (!testProducts) {
661-
return false;
662-
}
663-
const testBinaryPaths = testProducts.map(({ binaryPath }) => binaryPath);
664-
const swiftTestingBinaryRealPath = await fs.realpath(this.swiftTestingOutputPath());
665-
return !testBinaryPaths.includes(swiftTestingBinaryRealPath);
666-
} catch {
667-
// If the .swift-testing binary wasn't produced by the latest build then we assume the
668-
// swift-testing tests are in the unified binary.
669-
return true;
670-
}
671-
}
672-
673634
private unifiedTestingOutputPath(): string {
674635
// The unified binary that contains both swift-testing and XCTests
675636
// is named the same as the old style .xctest binary. The swiftpm-testing-helper
@@ -686,24 +647,19 @@ export class TestingConfigurationFactory {
686647
}
687648
}
688649

689-
private async testExecutableOutputPath(): Promise<string> {
650+
private testExecutableOutputPath(): string {
690651
switch (this.testLibrary) {
691652
case TestLibrary.swiftTesting:
692-
return (await this.isUnifiedTestingBinary())
693-
? this.unifiedTestingOutputPath()
694-
: this.swiftTestingOutputPath();
653+
return this.unifiedTestingOutputPath();
695654
case TestLibrary.xctest:
696655
return this.xcTestOutputPath();
697656
}
698657
}
699658

700-
private async debuggingTestExecutableArgs(): Promise<string[]> {
659+
private debuggingTestExecutableArgs(): string[] {
701660
switch (this.testLibrary) {
702661
case TestLibrary.swiftTesting: {
703-
const isUnifiedBinary = await this.isUnifiedTestingBinary();
704-
const swiftTestingArgs = isUnifiedBinary
705-
? ["--testing-library", "swift-testing"]
706-
: [];
662+
const swiftTestingArgs = ["--testing-library", "swift-testing"];
707663

708664
return this.addBuildOptionsToArgs(
709665
this.addTestsToArgs(this.addSwiftTestingFlagsArgs(swiftTestingArgs))

0 commit comments

Comments
 (0)