10
10
11
11
import Foundation
12
12
import XCTest
13
- @testable @ _spi ( FileManagerProtocol ) import SwiftDocC
13
+ @testable import SwiftDocC
14
14
15
15
/// A Data provider and file manager that accepts pre-built documentation bundles with files on the local filesystem.
16
16
///
@@ -40,14 +40,13 @@ import XCTest
40
40
///
41
41
/// - Note: This class is thread-safe by using a naive locking for each access to the files dictionary.
42
42
/// - Warning: Use this type for unit testing.
43
- @_spi ( FileManagerProtocol) // This needs to be SPI because it conforms to an SPI protocol
44
- public class TestFileSystem : FileManagerProtocol , DocumentationWorkspaceDataProvider {
45
- public let currentDirectoryPath = " / "
43
+ package class TestFileSystem : FileManagerProtocol , DocumentationWorkspaceDataProvider {
44
+ package let currentDirectoryPath = " / "
46
45
47
- public var identifier : String = UUID ( ) . uuidString
46
+ package var identifier : String = UUID ( ) . uuidString
48
47
49
48
private var _bundles = [ DocumentationBundle] ( )
50
- public func bundles( options: BundleDiscoveryOptions ) throws -> [ DocumentationBundle ] {
49
+ package func bundles( options: BundleDiscoveryOptions ) throws -> [ DocumentationBundle ] {
51
50
// Ignore the bundle discovery options, these test bundles are already built.
52
51
return _bundles
53
52
}
@@ -65,7 +64,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
65
64
/// A data fixture to use in the `files` index to mark folders.
66
65
static let folderFixtureData = " Folder " . data ( using: . utf8) !
67
66
68
- public convenience init ( folders: [ Folder ] ) throws {
67
+ package convenience init ( folders: [ Folder ] ) throws {
69
68
self . init ( )
70
69
71
70
// Default system paths
@@ -117,7 +116,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
117
116
}
118
117
}
119
118
120
- public func contentsOfURL( _ url: URL ) throws -> Data {
119
+ package func contentsOfURL( _ url: URL ) throws -> Data {
121
120
filesLock. lock ( )
122
121
defer { filesLock. unlock ( ) }
123
122
@@ -127,7 +126,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
127
126
return file
128
127
}
129
128
130
- public func contents( of url: URL ) throws -> Data {
129
+ package func contents( of url: URL ) throws -> Data {
131
130
try contentsOfURL ( url)
132
131
}
133
132
@@ -166,7 +165,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
166
165
return Array ( fileList. keys)
167
166
}
168
167
169
- public func fileExists( atPath path: String , isDirectory: UnsafeMutablePointer < ObjCBool > ? ) -> Bool {
168
+ package func fileExists( atPath path: String , isDirectory: UnsafeMutablePointer < ObjCBool > ? ) -> Bool {
170
169
filesLock. lock ( )
171
170
defer { filesLock. unlock ( ) }
172
171
@@ -179,14 +178,14 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
179
178
return true
180
179
}
181
180
182
- public func fileExists( atPath path: String ) -> Bool {
181
+ package func fileExists( atPath path: String ) -> Bool {
183
182
filesLock. lock ( )
184
183
defer { filesLock. unlock ( ) }
185
184
186
185
return files. keys. contains ( path)
187
186
}
188
187
189
- public func copyItem( at srcURL: URL , to dstURL: URL ) throws {
188
+ package func copyItem( at srcURL: URL , to dstURL: URL ) throws {
190
189
guard !disableWriting else { return }
191
190
192
191
filesLock. lock ( )
@@ -203,7 +202,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
203
202
}
204
203
}
205
204
206
- public func moveItem( at srcURL: URL , to dstURL: URL ) throws {
205
+ package func moveItem( at srcURL: URL , to dstURL: URL ) throws {
207
206
guard !disableWriting else { return }
208
207
209
208
filesLock. lock ( )
@@ -240,7 +239,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
240
239
files [ path] = Self . folderFixtureData
241
240
}
242
241
243
- public func createDirectory( at url: URL , withIntermediateDirectories createIntermediates: Bool , attributes: [ FileAttributeKey : Any ] ? = nil ) throws {
242
+ package func createDirectory( at url: URL , withIntermediateDirectories createIntermediates: Bool , attributes: [ FileAttributeKey : Any ] ? = nil ) throws {
244
243
guard !disableWriting else { return }
245
244
246
245
filesLock. lock ( )
@@ -249,14 +248,14 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
249
248
try createDirectory ( atPath: url. path, withIntermediateDirectories: createIntermediates)
250
249
}
251
250
252
- public func contentsEqual( atPath path1: String , andPath path2: String ) -> Bool {
251
+ package func contentsEqual( atPath path1: String , andPath path2: String ) -> Bool {
253
252
filesLock. lock ( )
254
253
defer { filesLock. unlock ( ) }
255
254
256
255
return files [ path1] == files [ path2]
257
256
}
258
257
259
- public func removeItem( at: URL ) throws {
258
+ package func removeItem( at: URL ) throws {
260
259
guard !disableWriting else { return }
261
260
262
261
filesLock. lock ( )
@@ -268,7 +267,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
268
267
}
269
268
}
270
269
271
- public func createFile( at url: URL , contents: Data ) throws {
270
+ package func createFile( at url: URL , contents: Data ) throws {
272
271
filesLock. lock ( )
273
272
defer { filesLock. unlock ( ) }
274
273
@@ -279,18 +278,18 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
279
278
}
280
279
}
281
280
282
- public func createFile( at url: URL , contents: Data , options: NSData . WritingOptions ? ) throws {
281
+ package func createFile( at url: URL , contents: Data , options: NSData . WritingOptions ? ) throws {
283
282
try createFile ( at: url, contents: contents)
284
283
}
285
284
286
- public func contents( atPath: String ) -> Data ? {
285
+ package func contents( atPath: String ) -> Data ? {
287
286
filesLock. lock ( )
288
287
defer { filesLock. unlock ( ) }
289
288
290
289
return files [ atPath]
291
290
}
292
291
293
- public func contentsOfDirectory( atPath path: String ) throws -> [ String ] {
292
+ package func contentsOfDirectory( atPath path: String ) throws -> [ String ] {
294
293
filesLock. lock ( )
295
294
defer { filesLock. unlock ( ) }
296
295
@@ -309,7 +308,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
309
308
return Array ( results)
310
309
}
311
310
312
- public func contentsOfDirectory( at url: URL , includingPropertiesForKeys keys: [ URLResourceKey ] ? , options mask: FileManager . DirectoryEnumerationOptions ) throws -> [ URL ] {
311
+ package func contentsOfDirectory( at url: URL , includingPropertiesForKeys keys: [ URLResourceKey ] ? , options mask: FileManager . DirectoryEnumerationOptions ) throws -> [ URL ] {
313
312
314
313
if let keys {
315
314
XCTAssertTrue ( keys. isEmpty, " includingPropertiesForKeys is not implemented in contentsOfDirectory in TestFileSystem " )
@@ -328,7 +327,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
328
327
return output
329
328
}
330
329
331
- public func uniqueTemporaryDirectory( ) -> URL {
330
+ package func uniqueTemporaryDirectory( ) -> URL {
332
331
URL ( fileURLWithPath: " /tmp/ \( ProcessInfo . processInfo. globallyUniqueString) " , isDirectory: true )
333
332
}
334
333
@@ -345,7 +344,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
345
344
///
346
345
/// - Parameter path: The path to the sub hierarchy to dump to a string representation.
347
346
/// - Returns: A stable string representation that can be checked in tests.
348
- public func dump( subHierarchyFrom path: String = " / " ) -> String {
347
+ package func dump( subHierarchyFrom path: String = " / " ) -> String {
349
348
filesLock. lock ( )
350
349
defer { filesLock. unlock ( ) }
351
350
@@ -368,7 +367,7 @@ public class TestFileSystem: FileManagerProtocol, DocumentationWorkspaceDataProv
368
367
}
369
368
370
369
// This is a convenience utility for testing, not FileManagerProtocol API
371
- public func recursiveContentsOfDirectory( atPath path: String ) throws -> [ String ] {
370
+ package func recursiveContentsOfDirectory( atPath path: String ) throws -> [ String ] {
372
371
var allSubpaths = try contentsOfDirectory ( atPath: path)
373
372
374
373
for subpath in allSubpaths { // This is iterating over a copy
0 commit comments