diff --git a/src/TestExplorer/TestRunner.ts b/src/TestExplorer/TestRunner.ts index d9fae8a14..be6edb59c 100644 --- a/src/TestExplorer/TestRunner.ts +++ b/src/TestExplorer/TestRunner.ts @@ -577,7 +577,7 @@ export class TestRunner { fifoPipePath, attachmentFolder ); - const testBuildConfig = await TestingConfigurationFactory.swiftTestingConfig( + const testBuildConfig = TestingConfigurationFactory.swiftTestingConfig( this.folderContext, swiftTestingArgs, this.testKind, @@ -612,7 +612,7 @@ export class TestRunner { } if (this.testArgs.hasXCTests) { - const testBuildConfig = await TestingConfigurationFactory.xcTestConfig( + const testBuildConfig = TestingConfigurationFactory.xcTestConfig( this.folderContext, this.testKind, this.testArgs.xcTestArgs, @@ -861,7 +861,7 @@ export class TestRunner { attachmentFolder ); - const swiftTestBuildConfig = await TestingConfigurationFactory.swiftTestingConfig( + const swiftTestBuildConfig = TestingConfigurationFactory.swiftTestingConfig( this.folderContext, swiftTestingArgs, this.testKind, @@ -895,7 +895,7 @@ export class TestRunner { // create launch config for testing if (this.testArgs.hasXCTests) { - const xcTestBuildConfig = await TestingConfigurationFactory.xcTestConfig( + const xcTestBuildConfig = TestingConfigurationFactory.xcTestConfig( this.folderContext, this.testKind, this.testArgs.xcTestArgs, diff --git a/src/debugger/buildConfig.ts b/src/debugger/buildConfig.ts index 8722336e0..a066a4bf7 100644 --- a/src/debugger/buildConfig.ts +++ b/src/debugger/buildConfig.ts @@ -186,13 +186,13 @@ export class SwiftTestingConfigurationSetup { * and `xcTestConfig` functions to create */ export class TestingConfigurationFactory { - public static async swiftTestingConfig( + public static swiftTestingConfig( ctx: FolderContext, buildArguments: SwiftTestingBuildAguments, testKind: TestKind, testList: string[], expandEnvVariables = false - ): Promise { + ): vscode.DebugConfiguration | null { return new TestingConfigurationFactory( ctx, testKind, @@ -203,12 +203,12 @@ export class TestingConfigurationFactory { ).build(); } - public static async xcTestConfig( + public static xcTestConfig( ctx: FolderContext, testKind: TestKind, testList: string[], expandEnvVariables = false - ): Promise { + ): vscode.DebugConfiguration | null { return new TestingConfigurationFactory( ctx, testKind, @@ -219,11 +219,11 @@ export class TestingConfigurationFactory { ).build(); } - public static async testExecutableOutputPath( + public static testExecutableOutputPath( ctx: FolderContext, testKind: TestKind, testLibrary: TestLibrary - ): Promise { + ): string { return new TestingConfigurationFactory( ctx, testKind, @@ -251,7 +251,7 @@ export class TestingConfigurationFactory { * - Test Kind (coverage, debugging) * - Test Library (XCTest, swift-testing) */ - private async build(): Promise { + private build(): vscode.DebugConfiguration | null { if (!this.hasTestTarget) { return null; } @@ -267,7 +267,7 @@ export class TestingConfigurationFactory { } /* eslint-disable no-case-declarations */ - private async buildWindowsConfig(): Promise { + private buildWindowsConfig(): vscode.DebugConfiguration | null { if (isDebugging(this.testKind)) { const testEnv = { ...swiftRuntimeEnv(), @@ -288,8 +288,8 @@ export class TestingConfigurationFactory { return { ...this.baseConfig, - program: await this.testExecutableOutputPath(), - args: await this.debuggingTestExecutableArgs(), + program: this.testExecutableOutputPath(), + args: this.debuggingTestExecutableArgs(), env: testEnv, }; } else { @@ -298,12 +298,12 @@ export class TestingConfigurationFactory { } /* eslint-disable no-case-declarations */ - private async buildLinuxConfig(): Promise { + private buildLinuxConfig(): vscode.DebugConfiguration | null { if (isDebugging(this.testKind) && this.testLibrary === TestLibrary.xctest) { return { ...this.baseConfig, - program: await this.testExecutableOutputPath(), - args: await this.debuggingTestExecutableArgs(), + program: this.testExecutableOutputPath(), + args: this.debuggingTestExecutableArgs(), env: { ...swiftRuntimeEnv( process.env, @@ -313,11 +313,11 @@ export class TestingConfigurationFactory { }, }; } else { - return await this.buildDarwinConfig(); + return this.buildDarwinConfig(); } } - private async buildDarwinConfig(): Promise { + private buildDarwinConfig(): vscode.DebugConfiguration | null { switch (this.testLibrary) { case TestLibrary.swiftTesting: switch (this.testKind) { @@ -362,8 +362,8 @@ export class TestingConfigurationFactory { const result = { ...this.baseConfig, - program: await this.testExecutableOutputPath(), - args: await this.debuggingTestExecutableArgs(), + program: this.testExecutableOutputPath(), + args: this.debuggingTestExecutableArgs(), env: { ...this.testEnv, ...this.sanitizerRuntimeEnvironment, @@ -631,45 +631,6 @@ export class TestingConfigurationFactory { ); } - private swiftTestingOutputPath(): string { - return path.join( - this.buildDirectory, - this.artifactFolderForTestKind, - `${this.ctx.swiftPackage.name}PackageTests.swift-testing` - ); - } - - private buildDescriptionPath(): string { - return path.join(this.buildDirectory, this.artifactFolderForTestKind, "description.json"); - } - - private async isUnifiedTestingBinary(): Promise { - // Toolchains that contain https://github.com/swiftlang/swift-package-manager/commit/844bd137070dcd18d0f46dd95885ef7907ea0697 - // no longer produce a .swift-testing binary, instead we want to use `unifiedTestingOutputPath`. - // In order to determine if we're working with a unified binary we need to check if the .swift-testing - // binary was produced by the latest build. If it was then we are not using a unified binary. - - // TODO: When Swift 6 is released and enough time has passed that we're sure no one is building the .swift-testing - // binary anymore this workaround can be removed and `swiftTestingPath` can be returned, and the build config - // generation can be made synchronous again. - - try { - const buildDescriptionStr = await fs.readFile(this.buildDescriptionPath(), "utf-8"); - const buildDescription = JSON.parse(buildDescriptionStr); - const testProducts = buildDescription.builtTestProducts as { binaryPath: string }[]; - if (!testProducts) { - return false; - } - const testBinaryPaths = testProducts.map(({ binaryPath }) => binaryPath); - const swiftTestingBinaryRealPath = await fs.realpath(this.swiftTestingOutputPath()); - return !testBinaryPaths.includes(swiftTestingBinaryRealPath); - } catch { - // If the .swift-testing binary wasn't produced by the latest build then we assume the - // swift-testing tests are in the unified binary. - return true; - } - } - private unifiedTestingOutputPath(): string { // The unified binary that contains both swift-testing and XCTests // is named the same as the old style .xctest binary. The swiftpm-testing-helper @@ -686,24 +647,19 @@ export class TestingConfigurationFactory { } } - private async testExecutableOutputPath(): Promise { + private testExecutableOutputPath(): string { switch (this.testLibrary) { case TestLibrary.swiftTesting: - return (await this.isUnifiedTestingBinary()) - ? this.unifiedTestingOutputPath() - : this.swiftTestingOutputPath(); + return this.unifiedTestingOutputPath(); case TestLibrary.xctest: return this.xcTestOutputPath(); } } - private async debuggingTestExecutableArgs(): Promise { + private debuggingTestExecutableArgs(): string[] { switch (this.testLibrary) { case TestLibrary.swiftTesting: { - const isUnifiedBinary = await this.isUnifiedTestingBinary(); - const swiftTestingArgs = isUnifiedBinary - ? ["--testing-library", "swift-testing"] - : []; + const swiftTestingArgs = ["--testing-library", "swift-testing"]; return this.addBuildOptionsToArgs( this.addTestsToArgs(this.addSwiftTestingFlagsArgs(swiftTestingArgs))