Skip to content

Commit d248733

Browse files
committed
Fix error when merging a single archive
1 parent b14b0d9 commit d248733

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

Sources/SwiftDocCUtilities/Action/Actions/Merge/MergeAction+SynthesizedLandingPage.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ extension MergeAction {
3636

3737
func readRootNodeRenderReferencesIn(dataDirectory: URL) throws -> RootRenderReferences {
3838
func inner(url: URL) throws -> [RootRenderReferences.Information] {
39-
try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [])
39+
// Path might not exist (e.g. tutorials for a reference-only archive)
40+
guard let contents = try? fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [])
41+
else { return [] }
42+
return try contents
4043
.compactMap {
4144
guard $0.pathExtension == "json" else {
4245
return nil

Tests/SwiftDocCUtilitiesTests/MergeActionTests.swift

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,50 @@ class MergeActionTests: XCTestCase {
659659
"doc://org.swift.test/documentation/second.json",
660660
])
661661
}
662-
662+
663+
func testSingleReferenceOnlyArchiveMerging() async throws {
664+
let fileSystem = try TestFileSystem(
665+
folders: [
666+
Folder(name: "Output.doccarchive", content: []),
667+
Self.makeArchive(
668+
name: "First",
669+
documentationPages: [
670+
"First",
671+
"First/SomeClass",
672+
"First/SomeClass/someProperty",
673+
"First/SomeClass/someFunction(:_)",
674+
],
675+
tutorialPages: []
676+
),
677+
]
678+
)
679+
680+
let logStorage = LogHandle.LogStorage()
681+
let action = MergeAction(
682+
archives: [
683+
URL(fileURLWithPath: "/First.doccarchive"),
684+
],
685+
landingPageInfo: testLandingPageInfo,
686+
outputURL: URL(fileURLWithPath: "/Output.doccarchive"),
687+
fileManager: fileSystem
688+
)
689+
690+
_ = try await action.perform(logHandle: .memory(logStorage))
691+
XCTAssertEqual(logStorage.text, "", "The action didn't log anything")
692+
693+
let synthesizedRootNode = try fileSystem.renderNode(atPath: "/Output.doccarchive/data/documentation.json")
694+
XCTAssertEqual(synthesizedRootNode.metadata.title, "Test Landing Page Name")
695+
XCTAssertEqual(synthesizedRootNode.metadata.roleHeading, "Test Landing Page Kind")
696+
XCTAssertEqual(synthesizedRootNode.topicSectionsStyle, .detailedGrid)
697+
XCTAssertEqual(synthesizedRootNode.topicSections.flatMap { [$0.title].compactMap({ $0 }) + $0.identifiers }, [
698+
// No title
699+
"doc://org.swift.test/documentation/first.json",
700+
])
701+
XCTAssertEqual(synthesizedRootNode.references.keys.sorted(), [
702+
"doc://org.swift.test/documentation/first.json",
703+
])
704+
}
705+
663706
func testErrorWhenArchivesContainOverlappingData() async throws {
664707
let fileSystem = try TestFileSystem(
665708
folders: [

0 commit comments

Comments
 (0)