Skip to content

Commit 248da00

Browse files
Fix warnings for multiple root pages with improved test reliability
1 parent a8d4721 commit 248da00

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,8 @@ public class DocumentationContext {
24112411
&& rootModules.contains { $0.url.lastPathComponent == "Root" }
24122412

24132413
if !isTestCase {
2414-
let mainModuleNames = rootModules.map { $0.url.lastPathComponent }.joined(separator: ", ")
2414+
// Sort module names to ensure consistent warning message
2415+
let mainModuleNames = rootModules.map { $0.url.lastPathComponent }.sorted().joined(separator: ", ")
24152416
let diagnostic = Diagnostic(
24162417
source: nil,
24172418
severity: .warning,
@@ -2420,7 +2421,7 @@ public class DocumentationContext {
24202421
summary: "Documentation contains symbol graphs for multiple main modules: \(mainModuleNames)",
24212422
explanation: "Having multiple root modules may lead to unexpected behavior when using DocC."
24222423
)
2423-
diagnosticEngine.emit(Problem(diagnostic: diagnostic, possibleSolutions: []))
2424+
diagnosticEngine.emit(Problem(diagnostic: diagnostic))
24242425
}
24252426
}
24262427

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContext+RootPageTests.swift

+14-23
Original file line numberDiff line numberDiff line change
@@ -173,34 +173,28 @@ class DocumentationContext_RootPageTests: XCTestCase {
173173
//Multiple Root Warnings Tests
174174

175175
func testMultipleSymbolGraphModulesWarning() throws {
176-
//created a test bundle with two symbol graph files for different modules
177176
let tempURL = try createTemporaryDirectory()
178177
let bundleURL = tempURL.appendingPathComponent("test.docc")
179178
try FileManager.default.createDirectory(at: bundleURL, withIntermediateDirectories: true)
180179

181-
//created two symbol graph files for different modules
182180
let module1GraphURL = bundleURL.appendingPathComponent("Module1.symbols.json")
183181
let module2GraphURL = bundleURL.appendingPathComponent("Module2.symbols.json")
184182

185-
// Symbol graph content for Module1
186183
let module1Graph = makeSymbolGraph(
187184
moduleName: "Module1",
188185
symbols: [],
189186
relationships: []
190187
)
191188

192-
//symbol graph content for Module2
193189
let module2Graph = makeSymbolGraph(
194190
moduleName: "Module2",
195191
symbols: [],
196192
relationships: []
197193
)
198194

199-
//symbol graphs to files
200195
try JSONEncoder().encode(module1Graph).write(to: module1GraphURL)
201196
try JSONEncoder().encode(module2Graph).write(to: module2GraphURL)
202197

203-
//created the Info.plist file
204198
let infoPlistURL = bundleURL.appendingPathComponent("Info.plist")
205199
let infoPlist = """
206200
<?xml version="1.0" encoding="UTF-8"?>
@@ -218,17 +212,19 @@ class DocumentationContext_RootPageTests: XCTestCase {
218212
"""
219213
try infoPlist.write(to: infoPlistURL, atomically: true, encoding: .utf8)
220214

221-
//bundle
222215
let (_, _, context) = try loadBundle(from: bundleURL)
223216

224-
//checks for the warning about multiple symbol graph modules
225217
let multipleModuleWarning = context.problems.first {
226-
$0.diagnostic.identifier == "org.swift.docc.MultipleSymbolGraphRoots"
218+
$0.diagnostic.identifier == "org.swift.docc.MultipleRootModules"
227219
}
228220
XCTAssertNotNil(multipleModuleWarning, "Should emit warning about multiple symbol graph modules")
229-
XCTAssertEqual(multipleModuleWarning?.diagnostic.summary, "Documentation has multiple symbol graph modules as root pages")
230-
XCTAssertTrue(multipleModuleWarning?.diagnostic.explanation?.contains("Module1") ?? false)
231-
XCTAssertTrue(multipleModuleWarning?.diagnostic.explanation?.contains("Module2") ?? false)
221+
222+
// Check that both module names are present in the warning message, regardless of order
223+
let warningMessage = multipleModuleWarning?.diagnostic.summary ?? ""
224+
XCTAssertTrue(warningMessage.contains("Module1") && warningMessage.contains("Module2"),
225+
"Warning should mention both modules")
226+
XCTAssertTrue(warningMessage.contains("Documentation contains symbol graphs for multiple main modules"),
227+
"Warning should have correct summary")
232228
}
233229

234230
func testMixedRootTypesWarning() throws {
@@ -362,7 +358,6 @@ class DocumentationContext_RootPageTests: XCTestCase {
362358
func testMultipleRootPagesWarning() throws {
363359
let (_, context) = try loadBundle(catalog:
364360
Folder(name: "test.docc", content: [
365-
// First root page
366361
TextFile(name: "FirstRoot.md", utf8Content: """
367362
# First Root
368363
@Metadata {
@@ -371,7 +366,6 @@ class DocumentationContext_RootPageTests: XCTestCase {
371366
First root page.
372367
"""),
373368

374-
// Second root page
375369
TextFile(name: "SecondRoot.md", utf8Content: """
376370
# Second Root
377371
@Metadata {
@@ -380,7 +374,6 @@ class DocumentationContext_RootPageTests: XCTestCase {
380374
Second root page.
381375
"""),
382376

383-
// Third root page
384377
TextFile(name: "ThirdRoot.md", utf8Content: """
385378
# Third Root
386379
@Metadata {
@@ -419,29 +412,24 @@ class DocumentationContext_RootPageTests: XCTestCase {
419412
let bundleURL = tempURL.appendingPathComponent("test.docc")
420413
try FileManager.default.createDirectory(at: bundleURL, withIntermediateDirectories: true)
421414

422-
// Create two symbol graph files for different modules
423415
let module1GraphURL = bundleURL.appendingPathComponent("Module1.symbols.json")
424416
let module2GraphURL = bundleURL.appendingPathComponent("Module2.symbols.json")
425417

426-
// Symbol graph content for Module1
427418
let module1Graph = makeSymbolGraph(
428419
moduleName: "Module1",
429420
symbols: [],
430421
relationships: []
431422
)
432423

433-
// Symbol graph content for Module2
434424
let module2Graph = makeSymbolGraph(
435425
moduleName: "Module2",
436426
symbols: [],
437427
relationships: []
438428
)
439429

440-
// Write symbol graphs to files
441430
try JSONEncoder().encode(module1Graph).write(to: module1GraphURL)
442431
try JSONEncoder().encode(module2Graph).write(to: module2GraphURL)
443432

444-
// Create the Info.plist file
445433
let infoPlistURL = bundleURL.appendingPathComponent("Info.plist")
446434
let infoPlist = """
447435
<?xml version="1.0" encoding="UTF-8"?>
@@ -459,16 +447,19 @@ class DocumentationContext_RootPageTests: XCTestCase {
459447
"""
460448
try infoPlist.write(to: infoPlistURL, atomically: true, encoding: .utf8)
461449

462-
// Load the bundle
463450
let (_, _, context) = try loadBundle(from: bundleURL)
464451

465-
// Check for the warning about multiple root modules
466452
let multipleRootModulesWarnings = context.problems.filter {
467453
$0.diagnostic.identifier == "org.swift.docc.MultipleRootModules"
468454
}
469455

470456
XCTAssertEqual(multipleRootModulesWarnings.count, 1)
471-
XCTAssertEqual(multipleRootModulesWarnings[0].diagnostic.summary, "Documentation contains symbol graphs for multiple main modules: Module1, Module2")
457+
// Check that both module names are present in the warning message, regardless of order
458+
let warningMessage = multipleRootModulesWarnings[0].diagnostic.summary
459+
XCTAssertTrue(warningMessage.contains("Module1") && warningMessage.contains("Module2"),
460+
"Warning should mention both modules")
461+
XCTAssertTrue(warningMessage.contains("Documentation contains symbol graphs for multiple main modules"),
462+
"Warning should have correct summary prefix")
472463
XCTAssertEqual(multipleRootModulesWarnings[0].diagnostic.explanation, "Having multiple root modules may lead to unexpected behavior when using DocC.")
473464
}
474465
}

0 commit comments

Comments
 (0)