Skip to content

Commit af9a873

Browse files
committed
Move the test for the ClangPackageWithRelativePublicHeadersPath package to FrameworkModuleMapGeneratorTests
1 parent 0945489 commit af9a873

File tree

2 files changed

+29
-68
lines changed

2 files changed

+29
-68
lines changed

Tests/ScipioKitTests/FrameworkModuleMapGeneratorTests.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ private let fixturesPath = URL(fileURLWithPath: #filePath)
77
.appendingPathComponent("Resources")
88
.appendingPathComponent("Fixtures")
99
private let clangPackageWithUmbrellaDirectoryPath = fixturesPath.appendingPathComponent("ClangPackageWithUmbrellaDirectory")
10+
private let clangPackageWithRelativePublicHeadersPath = fixturesPath.appendingPathComponent("ClangPackageWithRelativePublicHeadersPath")
1011

1112
private struct PackageLocatorMock: PackageLocator {
1213
let packageDirectory: URL
@@ -29,6 +30,8 @@ struct FrameworkModuleMapGeneratorTests {
2930
defer { try? fileSystem.removeFileTree(outputDirectory) }
3031

3132
let generatedModuleMapContents = try await generateModuleMap(
33+
for: clangPackageWithUmbrellaDirectoryPath,
34+
moduleName: "MyTarget",
3235
keepPublicHeadersStructure: false,
3336
outputDirectory: outputDirectory
3437
)
@@ -51,6 +54,8 @@ framework module MyTarget {
5154
defer { try? fileSystem.removeFileTree(outputDirectory) }
5255

5356
let generatedModuleMapContents = try await generateModuleMap(
57+
for: clangPackageWithUmbrellaDirectoryPath,
58+
moduleName: "MyTarget",
5459
keepPublicHeadersStructure: true,
5560
outputDirectory: outputDirectory
5661
)
@@ -67,7 +72,29 @@ framework module MyTarget {
6772
#expect(generatedModuleMapContents == expectedModuleMapContents)
6873
}
6974

75+
@Test
76+
func generate_keepPublicHeadersStructure_withRelativePublicHeadersPath_is_true() async throws {
77+
let outputDirectory = temporaryDirectory.appending(component: #function)
78+
defer { try? fileSystem.removeFileTree(outputDirectory) }
79+
80+
let generatedModuleMapContents = try await generateModuleMap(
81+
for: clangPackageWithRelativePublicHeadersPath,
82+
moduleName: "ClangPackageWithRelativePublicHeadersPath",
83+
keepPublicHeadersStructure: true,
84+
outputDirectory: outputDirectory
85+
)
86+
let expectedModuleMapContents = """
87+
framework module ClangPackageWithRelativePublicHeadersPath {
88+
header "ClangPackageWithRelativePublicHeadersPath/add.h"
89+
export *
90+
}
91+
"""
92+
#expect(generatedModuleMapContents == expectedModuleMapContents)
93+
}
94+
7095
private func generateModuleMap(
96+
for packageDirectory: URL,
97+
moduleName: String,
7198
keepPublicHeadersStructure: Bool,
7299
outputDirectory: URL
73100
) async throws -> String {
@@ -78,12 +105,12 @@ framework module MyTarget {
78105
)
79106

80107
let descriptionPackage = try await DescriptionPackage(
81-
packageDirectory: clangPackageWithUmbrellaDirectoryPath,
108+
packageDirectory: packageDirectory,
82109
mode: .createPackage,
83110
onlyUseVersionsFromResolvedFile: false
84111
)
85112
let generatedModuleMapPath = try generator.generate(
86-
resolvedTarget: #require(descriptionPackage.graph.module(for: "MyTarget")),
113+
resolvedTarget: #require(descriptionPackage.graph.module(for: moduleName)),
87114
sdk: SDK.macOS,
88115
keepPublicHeadersStructure: keepPublicHeadersStructure
89116
)

Tests/ScipioKitTests/RunnerTests.swift

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ private let clangPackagePath = fixturePath.appendingPathComponent("ClangPackage"
1515
private let clangPackageWithSymbolicLinkHeadersPath = fixturePath.appendingPathComponent("ClangPackageWithSymbolicLinkHeaders")
1616
private let clangPackageWithCustomModuleMapPath = fixturePath.appendingPathComponent("ClangPackageWithCustomModuleMap")
1717
private let clangPackageWithUmbrellaDirectoryPath = fixturePath.appendingPathComponent("ClangPackageWithUmbrellaDirectory")
18-
private let clangPackageWithRelativePublicHeadersPath = fixturePath.appendingPathComponent("ClangPackageWithRelativePublicHeadersPath")
1918

2019
private struct InfoPlist: Decodable {
2120
var bundleVersion: String
@@ -269,71 +268,6 @@ final class RunnerTests: XCTestCase {
269268
}
270269
}
271270

272-
func testBuildClangPackageWithRelativePublicHeadersPath() async throws {
273-
defer {
274-
try? fileManager.removeItem(at: clangPackageWithRelativePublicHeadersPath.appending(component: ".build"))
275-
}
276-
277-
let runner = Runner(
278-
mode: .createPackage,
279-
options: .init(
280-
baseBuildOptions: .init(isSimulatorSupported: false),
281-
buildOptionsMatrix: [
282-
"ClangPackageWithRelativePublicHeadersPath": .init(
283-
keepPublicHeadersStructure: true
284-
),
285-
],
286-
shouldOnlyUseVersionsFromResolvedFile: true
287-
)
288-
)
289-
do {
290-
try await runner.run(packageDirectory: clangPackageWithRelativePublicHeadersPath,
291-
frameworkOutputDir: .custom(frameworkOutputDir))
292-
} catch {
293-
XCTFail("Build should be succeeded. \(error.localizedDescription)")
294-
}
295-
296-
let libraryName = "ClangPackageWithRelativePublicHeadersPath"
297-
let xcFramework = frameworkOutputDir.appendingPathComponent("\(libraryName).xcframework")
298-
let versionFile = frameworkOutputDir.appendingPathComponent(".\(libraryName).version")
299-
let framework = xcFramework.appendingPathComponent("ios-arm64")
300-
.appendingPathComponent("\(libraryName).framework")
301-
302-
XCTAssertTrue(
303-
fileManager.fileExists(
304-
atPath: framework.appending(
305-
components: ["Headers", "ClangPackageWithRelativePublicHeadersPath", "add.h"]
306-
)
307-
.path(percentEncoded: false)
308-
),
309-
"Should exist a header while preserving the public header structure"
310-
)
311-
312-
let moduleMapPath = framework.appending(components: ["Modules", "module.modulemap"])
313-
.path(percentEncoded: false)
314-
315-
XCTAssertTrue(
316-
fileManager.fileExists(atPath: moduleMapPath),
317-
"Should exist a modulemap"
318-
)
319-
let moduleMapContents = try XCTUnwrap(fileManager.contents(atPath: moduleMapPath).flatMap { String(decoding: $0, as: UTF8.self) })
320-
XCTAssertEqual(
321-
moduleMapContents,
322-
"""
323-
framework module ClangPackageWithRelativePublicHeadersPath {
324-
header "ClangPackageWithRelativePublicHeadersPath/add.h"
325-
export *
326-
}
327-
""",
328-
"modulemap should be converted for frameworks"
329-
)
330-
331-
XCTAssertTrue(fileManager.fileExists(atPath: xcFramework.path),
332-
"Should create \(libraryName).xcframework")
333-
XCTAssertFalse(fileManager.fileExists(atPath: versionFile.path),
334-
"Should not create .\(libraryName).version in create mode")
335-
}
336-
337271
func testCacheIsValid() async throws {
338272
let descriptionPackage = try await DescriptionPackage(
339273
packageDirectory: testPackagePath,

0 commit comments

Comments
 (0)