Skip to content

Commit 755fdb1

Browse files
committed
Avoid passing non-sendable FileManager into addTeardownBlock in test
1 parent 0e98b48 commit 755fdb1

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Sources/SwiftDocCTestUtilities/XCTestCase+TemporaryDirectory.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ public extension XCTestCase {
3636
///
3737
/// - Parameters:
3838
/// - pathComponents: The name of the temporary directory.
39-
/// - fileManager: The file manager that will create the directory.
4039
/// - Returns: The URL of the newly created directory.
41-
func createTemporaryDirectory(named: String, fileManager: FileManager = .default) throws -> URL {
40+
func createTemporaryDirectory(named: String) throws -> URL {
4241
try createTemporaryDirectory(pathComponents: named)
4342
}
4443

@@ -48,9 +47,8 @@ public extension XCTestCase {
4847
///
4948
/// - Parameters:
5049
/// - pathComponents: Additional path components to add to the temporary URL.
51-
/// - fileManager: The file manager that will create the directory.
5250
/// - Returns: The URL of the newly created directory.
53-
func createTemporaryDirectory(pathComponents: String..., fileManager: FileManager = .default) throws -> URL {
51+
func createTemporaryDirectory(pathComponents: String...) throws -> URL {
5452
let bundleParentDir = Bundle(for: Self.self).bundleURL.deletingLastPathComponent()
5553
let baseURL = bundleParentDir.appendingPathComponent(name.replacingWhitespaceAndPunctuation(with: "-"))
5654

@@ -62,20 +60,20 @@ public extension XCTestCase {
6260

6361
addTeardownBlock {
6462
do {
65-
if fileManager.fileExists(atPath: baseURL.path) {
66-
try fileManager.removeItem(at: baseURL)
63+
if FileManager.default.fileExists(atPath: baseURL.path) {
64+
try FileManager.default.removeItem(at: baseURL)
6765
}
6866
} catch {
6967
XCTFail("Failed to remove temporary directory: '\(error)'")
7068
}
7169
}
7270

73-
if !fileManager.fileExists(atPath: bundleParentDir.path) {
71+
if !FileManager.default.fileExists(atPath: bundleParentDir.path) {
7472
// Create the base URL directory without intermediate directories so that an error is raised if the parent directory doesn't exist.
75-
try fileManager.createDirectory(at: baseURL, withIntermediateDirectories: false, attributes: nil)
73+
try FileManager.default.createDirectory(at: baseURL, withIntermediateDirectories: false, attributes: nil)
7674
}
7775

78-
try fileManager.createDirectory(at: tempURL, withIntermediateDirectories: true, attributes: nil)
76+
try FileManager.default.createDirectory(at: tempURL, withIntermediateDirectories: true, attributes: nil)
7977

8078
return tempURL
8179
}

0 commit comments

Comments
 (0)