Skip to content

Commit 9548412

Browse files
authored
Use unified test binary when computing coverage (#997)
With the introduction of the new unified testing binary we need to supply it to lcov export instead of the .swift-testing binary.
1 parent d0c543f commit 9548412

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/coverage/LcovResults.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { BuildFlags } from "../toolchain/BuildFlags";
2525
import { TestLibrary } from "../TestExplorer/TestRunner";
2626
import { DisposableFileCollection } from "../utilities/tempFolder";
2727
import { TargetType } from "../SwiftPackage";
28+
import { TestingDebugConfigurationFactory } from "../debugger/buildConfig";
29+
import { TestKind } from "../TestExplorer/TestKind";
2830

2931
interface CodeCovFile {
3032
testLibrary: TestLibrary;
@@ -140,24 +142,26 @@ export class TestCoverage {
140142
* Exports a `.profdata` file using `llvm-cov export`, returning the result as a `Buffer`.
141143
*/
142144
private async exportProfdata(types: TestLibrary[], mergedProfileFile: string): Promise<Buffer> {
143-
const packageName = this.folderContext.swiftPackage.name;
144-
const buildDirectory = BuildFlags.buildDirectoryFromWorkspacePath(
145-
this.folderContext.folder.fsPath,
146-
true
147-
);
148-
149-
const coveredBinaries: string[] = [];
145+
const coveredBinaries = new Set<string>();
150146
if (types.includes(TestLibrary.xctest)) {
151-
let xcTestBinary = `${buildDirectory}/debug/${packageName}PackageTests.xctest`;
147+
let xcTestBinary = await TestingDebugConfigurationFactory.testExecutableOutputPath(
148+
this.folderContext,
149+
TestKind.coverage,
150+
TestLibrary.xctest
151+
);
152152
if (process.platform === "darwin") {
153-
xcTestBinary += `/Contents/MacOS/${packageName}PackageTests`;
153+
xcTestBinary += `/Contents/MacOS/${this.folderContext.swiftPackage.name}PackageTests`;
154154
}
155-
coveredBinaries.push(xcTestBinary);
155+
coveredBinaries.add(xcTestBinary);
156156
}
157157

158158
if (types.includes(TestLibrary.swiftTesting)) {
159-
const swiftTestBinary = `${buildDirectory}/debug/${packageName}PackageTests.swift-testing`;
160-
coveredBinaries.push(swiftTestBinary);
159+
const swiftTestBinary = await TestingDebugConfigurationFactory.testExecutableOutputPath(
160+
this.folderContext,
161+
TestKind.coverage,
162+
TestLibrary.swiftTesting
163+
);
164+
coveredBinaries.add(swiftTestBinary);
161165
}
162166

163167
let buffer = Buffer.alloc(0);

src/debugger/buildConfig.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ export class TestingDebugConfigurationFactory {
6969
).build();
7070
}
7171

72+
public static async testExecutableOutputPath(
73+
ctx: FolderContext,
74+
testKind: TestKind,
75+
testLibrary: TestLibrary
76+
): Promise<string> {
77+
return new TestingDebugConfigurationFactory(
78+
ctx,
79+
"",
80+
testKind,
81+
testLibrary,
82+
[],
83+
null,
84+
true
85+
).testExecutableOutputPath();
86+
}
87+
7288
private constructor(
7389
private ctx: FolderContext,
7490
private fifoPipePath: string,

0 commit comments

Comments
 (0)