Skip to content

Commit 5aa2c45

Browse files
authored
Discourage using unrealistic catalog inputs in tests (#1106)
* Discourage future use of the "TestBundle" by renaming it. This example catalog contains significant handcrafted data that doesn't reflect realistic inputs. * Update tests that don't need a catalog input to use an empty context. * Update `SymbolGraphRelationshipsBuilderTests` to not load any catalog * Update name of test specifically about the unrealistic test catalog * Create minimal catalog for final remaining `ChoiceTests` test case * Create minimal catalog for final remaining `VolumeTests` test case * Avoid referencing an input catalog for image size test * Create minimal catalog for `NonInclusiveLanguageCheckerTests` * Create minimal catalog for `DiagnosticTests` * Create minimal catalogs for some `DocumentationContextTests` * Update more tests that don't need a catalog input to use an empty context. * Create minimal catalogs for more `DocumentationContextTests` * Create minimal catalogs for some `VideoMediaTests` * Create minimal catalogs for two `SemaToRenderNodeTests` * Create minimal catalogs for a few more `DocumentationContextTests` * Load test catalogs from in-memory file system in many more tests * Rename legacy test bundle again * Resolve some warnings in tests about using `var` for unmutated action
1 parent cd3f5ba commit 5aa2c45

File tree

184 files changed

+971
-925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+971
-925
lines changed

Tests/SwiftDocCTests/Benchmark/ExternalTopicsHashTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
3939

4040
func testNoMetricAddedIfNoExternalTopicsAreResolved() throws {
4141
// Load bundle without using external resolvers
42-
let (_, context) = try testBundleAndContext(named: "TestBundle")
42+
let (_, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
4343
XCTAssertTrue(context.externallyResolvedLinks.isEmpty)
4444

4545
// Try adding external topics metrics
@@ -55,7 +55,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
5555

5656
// Add external links and verify the checksum is always the same
5757
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
58-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
58+
let (_, _, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
5959
try """
6060
# ``SideKit/SideClass``
6161
@@ -93,7 +93,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
9393

9494
// Add external links and verify the checksum is always the same
9595
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
96-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver], externalSymbolResolver: externalSymbolResolver) { url in
96+
let (_, _, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver], externalSymbolResolver: externalSymbolResolver) { url in
9797
try """
9898
# ``SideKit/SideClass``
9999
@@ -131,7 +131,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
131131
let externalResolver = self.externalResolver
132132

133133
// Load a bundle with external links
134-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
134+
let (_, _, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
135135
try """
136136
# ``SideKit/SideClass``
137137

Tests/SwiftDocCTests/Benchmark/TopicGraphHashTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414
class TopicGraphHashTests: XCTestCase {
1515
func testTopicGraphSameHash() throws {
1616
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
17-
let (_, context) = try testBundleAndContext(named: "TestBundle")
17+
let (_, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1818
let testBenchmark = Benchmark()
1919
benchmark(add: Benchmark.TopicGraphHash(context: context), benchmarkLog: testBenchmark)
2020
return testBenchmark.metrics[0].result
@@ -32,7 +32,7 @@ class TopicGraphHashTests: XCTestCase {
3232
func testTopicGraphChangedHash() throws {
3333
// Verify that the hash changes if we change the topic graph
3434
let initialHash: String
35-
let (_, context) = try testBundleAndContext(named: "TestBundle")
35+
let (_, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
3636

3737
do {
3838
let testBenchmark = Benchmark()
@@ -88,7 +88,7 @@ class TopicGraphHashTests: XCTestCase {
8888
"/externally/resolved/path/to/article2": .success(.init(referencePath: "/externally/resolved/path/to/article2")),
8989
]
9090

91-
let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [
91+
let (_, bundle, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [
9292
"com.external.testbundle" : resolver
9393
]) { url in
9494
// Add external links to the MyKit Topics.

Tests/SwiftDocCTests/Checker/Checkers/NonInclusiveLanguageCheckerTests.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import XCTest
1212
import Markdown
1313
@testable import SwiftDocC
14+
import SwiftDocCTestUtilities
1415

1516
class NonInclusiveLanguageCheckerTests: XCTestCase {
1617

@@ -167,9 +168,9 @@ func aBlackListedFunc() {
167168
}
168169

169170
private let nonInclusiveContent = """
170-
# ``SideKit``
171+
# Some root page
171172
172-
SideKit module root symbol. And here is a ~~whitelist~~:
173+
Some custom root page. And here is a ~~whitelist~~:
173174
174175
- item one
175176
- item two
@@ -178,11 +179,12 @@ func aBlackListedFunc() {
178179

179180
func testDisabledByDefault() throws {
180181
// Create a test bundle with some non-inclusive content.
181-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", diagnosticEngine: .init(filterLevel: .error)) { url in
182-
try self.nonInclusiveContent.write(to: url.appendingPathComponent("documentation").appendingPathComponent("sidekit.md"), atomically: true, encoding: .utf8)
183-
}
182+
let catalog = Folder(name: "unit-test.docc", content: [
183+
TextFile(name: "Root.md", utf8Content: nonInclusiveContent)
184+
])
185+
let (_, context) = try loadBundle(catalog: catalog)
184186

185-
XCTAssertEqual(context.problems.count, 0)
187+
XCTAssertEqual(context.problems.count, 0) // Non-inclusive content is an info-level diagnostic, so it's filtered out.
186188
}
187189

188190
func testEnablingTheChecker() throws {
@@ -196,9 +198,12 @@ func aBlackListedFunc() {
196198
]
197199

198200
for (severity, enabled) in expectations {
199-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", diagnosticEngine: .init(filterLevel: severity)) { url in
200-
try self.nonInclusiveContent.write(to: url.appendingPathComponent("documentation").appendingPathComponent("sidekit.md"), atomically: true, encoding: .utf8)
201-
}
201+
let catalog = Folder(name: "unit-test.docc", content: [
202+
TextFile(name: "Root.md", utf8Content: nonInclusiveContent)
203+
])
204+
var configuration = DocumentationContext.Configuration()
205+
configuration.externalMetadata.diagnosticLevel = severity
206+
let (_, context) = try loadBundle(catalog: catalog, diagnosticEngine: .init(filterLevel: severity), configuration: configuration)
202207

203208
// Verify that checker diagnostics were emitted or not, depending on the diagnostic level set.
204209
XCTAssertEqual(context.problems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.NonInclusiveLanguage" }), enabled)

Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414

1515
class DocumentationContextConverterTests: XCTestCase {
1616
func testRenderNodesAreIdentical() throws {
17-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
17+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1818

1919
// We'll use this to convert nodes ad-hoc
2020
let perNodeConverter = DocumentationNodeConverter(bundle: bundle, context: context)
@@ -41,7 +41,7 @@ class DocumentationContextConverterTests: XCTestCase {
4141
}
4242

4343
func testSymbolLocationsAreOnlyIncludedWhenRequested() throws {
44-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
44+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
4545
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
4646

4747
let fillIntroducedSymbolNode = try XCTUnwrap(
@@ -71,7 +71,7 @@ class DocumentationContextConverterTests: XCTestCase {
7171
}
7272

7373
func testSymbolAccessLevelsAreOnlyIncludedWhenRequested() throws {
74-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
74+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
7575
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
7676

7777
let fillIntroducedSymbolNode = try XCTUnwrap(

Tests/SwiftDocCTests/Converter/RenderContextTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414

1515
class RenderContextTests: XCTestCase {
1616
func testCreatesRenderReferences() throws {
17-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
17+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1818

1919
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
2020

Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
158158
/// Verifies that when JSON encoder should sort keys, the custom render reference cache
159159
/// respects that setting and prints the referencs in alphabetical order.
160160
func testSortedReferences() throws {
161-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
161+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
162162
let converter = DocumentationNodeConverter(bundle: bundle, context: context)
163163

164164
// Create a JSON encoder
@@ -218,7 +218,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
218218

219219
// Verifies that there is no extra comma at the end of the references list.
220220
func testRemovesLastReferencesListDelimiter() throws {
221-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
221+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
222222
let converter = DocumentationNodeConverter(bundle: bundle, context: context)
223223

224224
// Create a JSON encoder

Tests/SwiftDocCTests/Diagnostics/DiagnosticConsoleWriterDefaultFormattingTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class DiagnosticConsoleWriterDefaultFormattingTest: XCTestCase {
229229
let summary = "Test diagnostic summary"
230230
let explanation = "Test diagnostic explanation."
231231
let baseURL = Bundle.module.url(
232-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
232+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
233233
let source = baseURL.appendingPathComponent("TestTutorial.tutorial")
234234
let range = SourceLocation(line: 44, column: 59, source: source)..<SourceLocation(line: 44, column: 138, source: source)
235235

@@ -307,7 +307,7 @@ class DiagnosticConsoleWriterDefaultFormattingTest: XCTestCase {
307307
let summary = "Test diagnostic summary"
308308
let explanation = "Test diagnostic explanation."
309309
let baseURL = Bundle.module.url(
310-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
310+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
311311
let source = baseURL.appendingPathComponent("TestTutorial.tutorial")
312312
let diagnosticRange = SourceLocation(line: 44, column: 59, source: source)..<SourceLocation(line: 44, column: 138, source: source)
313313
let diagnostic = Diagnostic(source: source, severity: .warning, range: diagnosticRange, identifier: identifier, summary: summary, explanation: explanation)

Tests/SwiftDocCTests/Diagnostics/DiagnosticTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ class DiagnosticTests: XCTestCase {
7979

8080
/// Test offsetting diagnostic ranges
8181
func testOffsetDiagnostics() throws {
82-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
82+
let (bundle, context) = try loadBundle(catalog: Folder(name: "unit-test.docc", content: [
83+
JSONFile(name: "SomeModuleName.symbols.json", content: makeSymbolGraph(moduleName: "SomeModuleName"))
84+
]))
8385

8486
let content = "Test a ``Reference`` in a sentence."
8587
let markup = Document(parsing: content, source: URL(string: "/tmp/foo.symbols.json"), options: .parseSymbolLinks)
8688

87-
var resolver = ReferenceResolver(context: context, bundle: bundle, rootReference: ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift))
89+
let moduleReference = try XCTUnwrap(context.soleRootModuleReference)
90+
var resolver = ReferenceResolver(context: context, bundle: bundle, rootReference: moduleReference)
8891

8992
// Resolve references
9093
_ = resolver.visitMarkup(markup)

Tests/SwiftDocCTests/DocumentationService/ConvertService/ConvertServiceTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ class ConvertServiceTests: XCTestCase {
13831383

13841384
func testConvertAllPagesForOnDiskContent() throws {
13851385
let testBundleURL = Bundle.module.url(
1386-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
1386+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
13871387

13881388
let request = ConvertRequest(
13891389
bundleInfo: testBundleInfo,
@@ -1444,7 +1444,7 @@ class ConvertServiceTests: XCTestCase {
14441444

14451445
func testConvertSomeSymbolsAndSomeArticlesForOnDiskContent() throws {
14461446
let testBundleURL = Bundle.module.url(
1447-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
1447+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
14481448

14491449
let request = ConvertRequest(
14501450
bundleInfo: testBundleInfo,
@@ -1468,7 +1468,7 @@ class ConvertServiceTests: XCTestCase {
14681468

14691469
func testConvertNoSymbolsAndNoArticlesForOnDiskContent() throws {
14701470
let testBundleURL = Bundle.module.url(
1471-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
1471+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
14721472

14731473
let request = ConvertRequest(
14741474
bundleInfo: testBundleInfo,
@@ -1495,7 +1495,7 @@ class ConvertServiceTests: XCTestCase {
14951495
""")
14961496
#else
14971497
let (testBundleURL, _, _) = try testBundleAndContext(
1498-
copying: "TestBundle",
1498+
copying: "LegacyBundle_DoNotUseInNewTests",
14991499
excludingPaths: [
15001500
"sidekit.symbols.json",
15011501
"mykit-iOS.symbols.json",
@@ -1624,7 +1624,7 @@ class ConvertServiceTests: XCTestCase {
16241624
""")
16251625
#else
16261626
let (testBundleURL, _, _) = try testBundleAndContext(
1627-
copying: "TestBundle",
1627+
copying: "LegacyBundle_DoNotUseInNewTests",
16281628
excludingPaths: [
16291629
"mykit-iOS.symbols.json",
16301630

Tests/SwiftDocCTests/Indexing/IndexingTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IndexingTests: XCTestCase {
1515

1616
// MARK: - Tutorial
1717
func testTutorial() throws {
18-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
18+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1919
let tutorialReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorial", sourceLanguage: .swift)
2020
let node = try context.entity(with: tutorialReference)
2121
let tutorial = node.semantic as! Tutorial
@@ -89,7 +89,7 @@ class IndexingTests: XCTestCase {
8989
// MARK: - Article
9090

9191
func testArticle() throws {
92-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
92+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
9393
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/tutorials/Test-Bundle/TestTutorialArticle", sourceLanguage: .swift)
9494
let node = try context.entity(with: articleReference)
9595
let article = node.semantic as! TutorialArticle
@@ -187,7 +187,7 @@ class IndexingTests: XCTestCase {
187187
}
188188

189189
func testRootPageIndexingRecord() throws {
190-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
190+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
191191
let articleReference = ResolvedTopicReference(bundleID: "org.swift.docc.example", path: "/documentation/MyKit", sourceLanguage: .swift)
192192
let node = try context.entity(with: articleReference)
193193
let article = node.semantic as! Symbol
@@ -207,7 +207,7 @@ class IndexingTests: XCTestCase {
207207
}
208208

209209
func testSymbolIndexingRecord() throws {
210-
let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle") { url in
210+
let (_, bundle, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests") { url in
211211
// Modify the documentaion to have default availability for MyKit so that there is platform availability
212212
// information for MyProtocol (both in the render node and in the indexing record.
213213
let plistURL = url.appendingPathComponent("Info.plist")

0 commit comments

Comments
 (0)