Skip to content

Commit cc3d57d

Browse files
committed
Use XCTUnwrap instead of force unwrap in test helper
1 parent a3035e2 commit cc3d57d

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

Tests/SwiftDocCTests/Infrastructure/DocumentationContextTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DocumentationContextTests: XCTestCase {
3939
func testResolve() throws {
4040
let workspace = DocumentationWorkspace()
4141
let context = try DocumentationContext(dataProvider: workspace)
42-
let bundle = testBundle(named: "TestBundle")
42+
let bundle = try testBundle(named: "TestBundle")
4343
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
4444
try workspace.registerProvider(dataProvider)
4545

@@ -482,7 +482,7 @@ class DocumentationContextTests: XCTestCase {
482482
func testRegisteredImages() throws {
483483
let workspace = DocumentationWorkspace()
484484
let context = try DocumentationContext(dataProvider: workspace)
485-
let bundle = testBundle(named: "TestBundle")
485+
let bundle = try testBundle(named: "TestBundle")
486486
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
487487
try workspace.registerProvider(dataProvider)
488488

@@ -513,7 +513,7 @@ class DocumentationContextTests: XCTestCase {
513513
func testDownloadAssets() throws {
514514
let workspace = DocumentationWorkspace()
515515
let context = try DocumentationContext(dataProvider: workspace)
516-
let bundle = testBundle(named: "TestBundle")
516+
let bundle = try testBundle(named: "TestBundle")
517517
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
518518
try workspace.registerProvider(dataProvider)
519519

@@ -601,7 +601,7 @@ class DocumentationContextTests: XCTestCase {
601601
context.addGlobalChecks([{ (context, reference) -> [Problem] in
602602
return [Problem(diagnostic: Diagnostic(source: reference.url, severity: DiagnosticSeverity.error, range: nil, identifier: "com.tests.testGraphChecks", summary: "test error"), possibleSolutions: [])]
603603
}])
604-
let bundle = testBundle(named: "TestBundle")
604+
let bundle = try testBundle(named: "TestBundle")
605605
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
606606
try workspace.registerProvider(dataProvider)
607607

@@ -1265,7 +1265,7 @@ let expected = """
12651265
func testLanguageForNode() throws {
12661266
let workspace = DocumentationWorkspace()
12671267
let context = try DocumentationContext(dataProvider: workspace)
1268-
let bundle = testBundle(named: "TestBundle")
1268+
let bundle = try testBundle(named: "TestBundle")
12691269
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
12701270
try workspace.registerProvider(dataProvider)
12711271
let articleReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/Test-Bundle/article", sourceLanguage: .swift)
@@ -1938,7 +1938,7 @@ let expected = """
19381938
func renderNodeForPath(path: String) throws -> (DocumentationNode, RenderNode) {
19391939
let workspace = DocumentationWorkspace()
19401940
let context = try DocumentationContext(dataProvider: workspace)
1941-
let bundle = testBundle(named: "TestBundle")
1941+
let bundle = try testBundle(named: "TestBundle")
19421942
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
19431943
try workspace.registerProvider(dataProvider)
19441944

Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DocumentationCuratorTests: XCTestCase {
2929
func testCrawl() throws {
3030
let workspace = DocumentationWorkspace()
3131
let context = try DocumentationContext(dataProvider: workspace)
32-
let bundle = testBundle(named: "TestBundle")
32+
let bundle = try testBundle(named: "TestBundle")
3333
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
3434
try workspace.registerProvider(dataProvider)
3535

@@ -148,7 +148,7 @@ class DocumentationCuratorTests: XCTestCase {
148148
func testSymbolLinkResolving() throws {
149149
let workspace = DocumentationWorkspace()
150150
let context = try DocumentationContext(dataProvider: workspace)
151-
let bundle = testBundle(named: "TestBundle")
151+
let bundle = try testBundle(named: "TestBundle")
152152
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
153153
try workspace.registerProvider(dataProvider)
154154

@@ -205,7 +205,7 @@ class DocumentationCuratorTests: XCTestCase {
205205
func testLinkResolving() throws {
206206
let workspace = DocumentationWorkspace()
207207
let context = try DocumentationContext(dataProvider: workspace)
208-
let bundle = testBundle(named: "TestBundle")
208+
let bundle = try testBundle(named: "TestBundle")
209209
let sourceRoot = Bundle.module.url(
210210
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
211211
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])

Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ExternalReferenceResolverTests: XCTestCase {
145145

146146
func testResolvesReferencesExternallyOnlyWhenFallbackResolversAreSet() throws {
147147
let workspace = DocumentationWorkspace()
148-
let bundle = testBundle(named: "TestBundle")
148+
let bundle = try testBundle(named: "TestBundle")
149149
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
150150
try workspace.registerProvider(dataProvider)
151151
let context = try DocumentationContext(dataProvider: workspace)
@@ -189,7 +189,7 @@ class ExternalReferenceResolverTests: XCTestCase {
189189

190190
func testLoadEntityForExternalReference() throws {
191191
let workspace = DocumentationWorkspace()
192-
let bundle = testBundle(named: "TestBundle")
192+
let bundle = try testBundle(named: "TestBundle")
193193
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
194194
try workspace.registerProvider(dataProvider)
195195
let context = try DocumentationContext(dataProvider: workspace)
@@ -237,7 +237,7 @@ Document @1:1-1:35
237237
externalResolver.resolvedEntityKind = resolvedEntityKind
238238
context.externalReferenceResolvers = [externalResolver.bundleIdentifier: externalResolver]
239239

240-
let bundle = testBundle(named: "TestBundle")
240+
let bundle = try testBundle(named: "TestBundle")
241241

242242
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
243243
try workspace.registerProvider(dataProvider)

Tests/SwiftDocCTests/Infrastructure/SymbolGraph/SymbolGraphRelationshipsBuilderTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SymbolGraphRelationshipsBuilderTests: XCTestCase {
4848
}
4949

5050
func testConformsRelationship() throws {
51-
let bundle = testBundle(named: "TestBundle")
51+
let bundle = try testBundle(named: "TestBundle")
5252
var symbolIndex = [String: DocumentationNode]()
5353
let engine = DiagnosticEngine()
5454

@@ -77,7 +77,7 @@ class SymbolGraphRelationshipsBuilderTests: XCTestCase {
7777
}
7878

7979
func testInheritanceRelationship() throws {
80-
let bundle = testBundle(named: "TestBundle")
80+
let bundle = try testBundle(named: "TestBundle")
8181
var symbolIndex = [String: DocumentationNode]()
8282
let engine = DiagnosticEngine()
8383

@@ -106,7 +106,7 @@ class SymbolGraphRelationshipsBuilderTests: XCTestCase {
106106
}
107107

108108
func testRequirementRelationship() throws {
109-
let bundle = testBundle(named: "TestBundle")
109+
let bundle = try testBundle(named: "TestBundle")
110110
var symbolIndex = [String: DocumentationNode]()
111111
let engine = DiagnosticEngine()
112112

Tests/SwiftDocCTests/Rendering/DefaultAvailabilityTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import SymbolKit
1616
class DefaultAvailabilityTests: XCTestCase {
1717

1818
// Test whether missing default availability key correctly produces nil availability
19-
func testBundleWithoutDefaultAvailability() {
20-
let bundle = testBundle(named: "BundleWithoutAvailability")
19+
func testBundleWithoutDefaultAvailability() throws {
20+
let bundle = try testBundle(named: "BundleWithoutAvailability")
2121
XCTAssertNil(bundle.info.defaultAvailability)
2222
}
2323

Tests/SwiftDocCTests/XCTestCase+LoadingTestData.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ extension XCTestCase {
2525
// Load the bundle using automatic discovery
2626
let automaticDataProvider = try LocalFileSystemDataProvider(rootURL: bundleURL)
2727
// Mutate the bundle to include the code listings, then apply to the workspace using a manual provider.
28-
var bundle = try automaticDataProvider.bundles().first!
28+
var bundle = try XCTUnwrap(automaticDataProvider.bundles().first)
2929
bundle.attributedCodeListings = codeListings
3030
let dataProvider = PrebuiltLocalFileSystemDataProvider(bundles: [bundle])
3131
try workspace.registerProvider(dataProvider)
3232
return (bundleURL, bundle, context)
3333
}
3434

3535
func testBundleAndContext(copying name: String, excludingPaths excludedPaths: [String] = [], codeListings: [String : AttributedCodeListing] = [:], externalResolvers: [BundleIdentifier : ExternalReferenceResolver] = [:], externalSymbolResolver: ExternalSymbolResolver? = nil, configureBundle: ((URL) throws -> Void)? = nil) throws -> (URL, DocumentationBundle, DocumentationContext) {
36-
let sourceURL = Bundle.module.url(
37-
forResource: name, withExtension: "docc", subdirectory: "Test Bundles")!
36+
let sourceURL = try XCTUnwrap(Bundle.module.url(
37+
forResource: name, withExtension: "docc", subdirectory: "Test Bundles"))
3838

3939
let sourceExists = FileManager.default.fileExists(atPath: sourceURL.path)
4040
let bundleURL = sourceExists
@@ -56,20 +56,20 @@ extension XCTestCase {
5656
}
5757

5858
func testBundleAndContext(named name: String, codeListings: [String : AttributedCodeListing] = [:], externalResolvers: [String: ExternalReferenceResolver] = [:]) throws -> (DocumentationBundle, DocumentationContext) {
59-
let bundleURL = Bundle.module.url(
60-
forResource: name, withExtension: "docc", subdirectory: "Test Bundles")!
59+
let bundleURL = try XCTUnwrap(Bundle.module.url(
60+
forResource: name, withExtension: "docc", subdirectory: "Test Bundles"))
6161
let (_, bundle, context) = try loadBundle(from: bundleURL, codeListings: codeListings, externalResolvers: externalResolvers)
6262
return (bundle, context)
6363
}
6464

65-
func testBundle(named name: String) -> DocumentationBundle {
66-
let (bundle, _) = try! testBundleAndContext(named: name)
65+
func testBundle(named name: String) throws -> DocumentationBundle {
66+
let (bundle, _) = try testBundleAndContext(named: name)
6767
return bundle
6868
}
6969

7070
func testBundleFromRootURL(named name: String) throws -> DocumentationBundle {
71-
let bundleURL = Bundle.module.url(
72-
forResource: name, withExtension: "docc", subdirectory: "Test Bundles")!
71+
let bundleURL = try XCTUnwrap(Bundle.module.url(
72+
forResource: name, withExtension: "docc", subdirectory: "Test Bundles"))
7373
let dataProvider = try LocalFileSystemDataProvider(rootURL: bundleURL)
7474

7575
let bundles = try dataProvider.bundles()

0 commit comments

Comments
 (0)