Skip to content

Commit a5be296

Browse files
committed
Tests: Add automated tests to verify dead code strip
Add an automated tests that validates SwiftBuild build system sets the dead code stip setting accordingly. Fixes: #9326 Issue: rdar://163962003
1 parent 5f7cf54 commit a5be296

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Tests/SwiftBuildSupportTests/SwiftBuildSystemTests.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func withInstantiatedSwiftBuildSystem(
4646
let observabilitySystem: TestingObservability = ObservabilitySystem.makeForTesting()
4747
let toolchain = try UserToolchain.default
4848
let workspace = try Workspace(
49-
fileSystem: localFileSystem,
49+
fileSystem: fileSystem,
5050
forRootPackage: fixturePath,
5151
customManifestLoader: ManifestLoader(toolchain: toolchain),
5252
)
@@ -235,4 +235,38 @@ struct SwiftBuildSystemTests {
235235
#expect(synthesizedArgs.table["CLANG_INDEX_STORE_PATH"] == expectedPathValue)
236236
}
237237
}
238+
239+
@Test(
240+
.serialized,
241+
arguments: [
242+
(linkerDeadStripUT: true, expectedValue: "YES"),
243+
(linkerDeadStripUT: false, expectedValue: nil),
244+
]
245+
)
246+
func validateDeadStripSetting(
247+
linkerDeadStripUT: Bool,
248+
expectedValue: String?
249+
) async throws {
250+
try await withInstantiatedSwiftBuildSystem(
251+
fromFixture: "PIFBuilder/Simple",
252+
buildParameters: mockBuildParameters(
253+
destination: .host,
254+
linkerDeadStrip: linkerDeadStripUT,
255+
),
256+
) { swiftBuild, session, observabilityScope, buildParameters in
257+
258+
let buildSettings = try await swiftBuild.makeBuildParameters(
259+
session: session,
260+
symbolGraphOptions: nil,
261+
setToolchainSetting: false, // Set this to false as SwiftBuild checks the toolchain path
262+
)
263+
264+
let synthesizedArgs = try #require(buildSettings.overrides.synthesized)
265+
let actual = synthesizedArgs.table["DEAD_CODE_STRIPPING"]
266+
#expect(
267+
actual == expectedValue,
268+
"dead strip: \(linkerDeadStripUT) >>> Actual: '\(actual)' expected: '\(String(describing: expectedValue))'",
269+
)
270+
}
271+
}
238272
}

0 commit comments

Comments
 (0)