Skip to content

Commit fa153a8

Browse files
author
Anthony Eid
committed
Create test modules under technology root warnings
The two test created are testModuleUnderAncestorOfTechnologyRoot, and testModuleUnderTechnologyRoot. These test verify that technology roots, nor ancestors of technology roots generate errors when linking to a module. testCrawlDiagnostics() already verifies that regular articles generate an error when linking to modules. So creating that testcase is not needed. Issue: 735
1 parent 668850a commit fa153a8

File tree

5 files changed

+823
-4
lines changed

5 files changed

+823
-4
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,13 @@ struct DocumentationCurator {
232232

233233

234234
// If a module has a path with a manual technology root there shouldn't
235-
// be an error messsage. Using an if statement allows fallthrough behavior
236-
// in that specific case
235+
// be an error messsage. This is an if statement instead of a guard because
236+
// when there's no warning we still curate the node
237237
if childDocumentationNode.kind == .module {
238238

239-
let hasTechnologyRoot = context.pathsTo(nodeReference).contains { path in
239+
var hasTechnologyRoot = documentationNode.kind.isSymbol == false
240+
241+
hasTechnologyRoot = hasTechnologyRoot || context.pathsTo(nodeReference).contains { path in
240242
if path.count == 0 {
241243
return false
242244
}
@@ -246,7 +248,7 @@ struct DocumentationCurator {
246248
}
247249

248250
if !hasTechnologyRoot {
249-
problems.append(Problem(diagnostic: Diagnostic(source: source(), severity: .warning, range: range(), identifier: "org.swift.docc.ModuleCuration", summary: "Linking to \((link.destination ?? "").singleQuoted) from a Topics group in \(nodeReference.absoluteString.singleQuoted) isn't allowed", explanation: "The former is a module, and modules only exist at the root"), possibleSolutions: []))
251+
problems.append(Problem(diagnostic: Diagnostic(source: source(), severity: .warning, range: range(), identifier: "org.swift.docc.ModuleCuration", summary: "Linking to \((link.destination ?? "").singleQuoted) from a Topics group in \(nodeReference.absoluteString.singleQuoted) isn't allowed", explanation: "The former is a module test, and modules only exist at the root"), possibleSolutions: []))
250252
continue
251253
}
252254

Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,96 @@ class DocumentationCuratorTests: XCTestCase {
145145
)
146146
}
147147

148+
func testModuleUnderTechnologyRoot() throws {
149+
let (_, bundle, context) = try testBundleAndContext(copying: "ModuleUnderTechnologyRoot") { url in
150+
try """
151+
# Another Awesome Project
152+
153+
Technology Root
154+
155+
@Metadata {
156+
@TechnologyRoot
157+
}
158+
159+
## Overview
160+
161+
This shouldn't create a warning because it's a technologyRoot
162+
163+
## Topics
164+
165+
### Code Reference
166+
- ``MyAwesomeApp``
167+
168+
""".write(to: url.appendingPathComponent("Root.md"), atomically: true, encoding: .utf8)
169+
}
170+
171+
var crawler = DocumentationCurator.init(in: context, bundle: bundle)
172+
XCTAssert(context.problems.isEmpty, "Expected no problems. Found: \(context.problems.map(\.diagnostic.summary))")
173+
174+
for node in context.rootModules {
175+
XCTAssertNoThrow(try crawler.crawlChildren(of: node, prepareForCuration: { _ in }, relateNodes: { _, _ in }))
176+
}
177+
178+
XCTAssertEqual(crawler.problems.count, 0)
179+
180+
}
181+
182+
func testModuleUnderAncestorOfTechnologyRoot() throws {
183+
let (_, bundle, context) = try testBundleAndContext(copying: "ModuleUnderTechnologyRoot") { url in
184+
try """
185+
# Another Awesome Project
186+
187+
Technology Root
188+
189+
@Metadata {
190+
@TechnologyRoot
191+
}
192+
193+
## Overview
194+
195+
This shouldn't create a warning because it's a technologyRoot
196+
197+
## Topics
198+
- <doc:Ancestor>
199+
200+
### Code Reference
201+
202+
""".write(to: url.appendingPathComponent("Root.md"), atomically: true, encoding: .utf8)
203+
204+
try """
205+
# MyAwesomeApp Project
206+
207+
Random summary
208+
209+
## Overview
210+
211+
This is a project to test that no errors are created when a technology root refers to a
212+
module.
213+
214+
This should create a warning because it links to a module without being a technology root
215+
216+
## Topics
217+
218+
219+
### Code Reference
220+
221+
- ``MyAwesomeApp``
222+
223+
""".write(to: url.appendingPathComponent("Ancestor.md"), atomically: true, encoding: .utf8)
224+
}
225+
226+
var crawler = DocumentationCurator.init(in: context, bundle: bundle)
227+
XCTAssert(context.problems.isEmpty, "Expected no problems. Found: \(context.problems.map(\.diagnostic.summary))")
228+
229+
for node in context.rootModules {
230+
XCTAssertNoThrow(try crawler.crawlChildren(of: node, prepareForCuration: { _ in }, relateNodes: { _, _ in }))
231+
}
232+
233+
234+
XCTAssertEqual(crawler.problems.count, 0)
235+
}
236+
237+
148238
func testSymbolLinkResolving() throws {
149239
let workspace = DocumentationWorkspace()
150240
let context = try DocumentationContext(dataProvider: workspace)

0 commit comments

Comments
 (0)