Skip to content

Commit ebb7b04

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 1265093 commit ebb7b04

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
)
@@ -158,4 +158,38 @@ struct SwiftBuildSystemTests {
158158
#expect(synthesizedArgs.table["CLANG_INDEX_STORE_PATH"] == expectedPathValue)
159159
}
160160
}
161+
162+
@Test(
163+
.serialized,
164+
arguments: [
165+
(linkerDeadStripUT: true, expectedValue: "YES"),
166+
(linkerDeadStripUT: false, expectedValue: nil),
167+
]
168+
)
169+
func validateDeadStripSetting(
170+
linkerDeadStripUT: Bool,
171+
expectedValue: String?
172+
) async throws {
173+
try await withInstantiatedSwiftBuildSystem(
174+
fromFixture: "PIFBuilder/Simple",
175+
buildParameters: mockBuildParameters(
176+
destination: .host,
177+
linkerDeadStrip: linkerDeadStripUT,
178+
),
179+
) { swiftBuild, session, observabilityScope, buildParameters in
180+
181+
let buildSettings = try await swiftBuild.makeBuildParameters(
182+
session: session,
183+
symbolGraphOptions: nil,
184+
setToolchainSetting: false, // Set this to false as SwiftBuild checks the toolchain path
185+
)
186+
187+
let synthesizedArgs = try #require(buildSettings.overrides.synthesized)
188+
let actual = synthesizedArgs.table["DEAD_CODE_STRIPPING"]
189+
#expect(
190+
actual == expectedValue,
191+
"dead strip: \(linkerDeadStripUT) >>> Actual: '\(actual)' expected: '\(String(describing: expectedValue))'",
192+
)
193+
}
194+
}
161195
}

0 commit comments

Comments
 (0)