Skip to content

Commit 849d2b7

Browse files
authored
Merge pull request #2911 from readdle/temporary-for-real
Improve cleanup in FileManager tests
2 parents e4eb545 + ea501f4 commit 849d2b7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Tests/Foundation/Tests/TestFileManager.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ class TestFileManager : XCTestCase {
208208
func test_isReadableFile() {
209209
let fm = FileManager.default
210210
let path = NSTemporaryDirectory() + "test_isReadableFile\(NSUUID().uuidString)"
211+
defer {
212+
try? fm.removeItem(atPath: path)
213+
}
211214

212215
do {
213216
// create test file
@@ -233,6 +236,9 @@ class TestFileManager : XCTestCase {
233236
func test_isWritableFile() {
234237
let fm = FileManager.default
235238
let path = NSTemporaryDirectory() + "test_isWritableFile\(NSUUID().uuidString)"
239+
defer {
240+
try? fm.removeItem(atPath: path)
241+
}
236242

237243
do {
238244
// create test file
@@ -253,6 +259,9 @@ class TestFileManager : XCTestCase {
253259
func test_isExecutableFile() {
254260
let fm = FileManager.default
255261
let path = NSTemporaryDirectory() + "test_isExecutableFile\(NSUUID().uuidString)"
262+
defer {
263+
try? fm.removeItem(atPath: path)
264+
}
256265

257266
do {
258267
// create test file
@@ -280,6 +289,9 @@ class TestFileManager : XCTestCase {
280289

281290
do {
282291
let dir_path = NSTemporaryDirectory() + "/test_isDeletableFile_dir/"
292+
defer {
293+
try? fm.removeItem(atPath: dir_path)
294+
}
283295
let file_path = dir_path + "test_isDeletableFile\(NSUUID().uuidString)"
284296
// create test directory
285297
try fm.createDirectory(atPath: dir_path, withIntermediateDirectories: true)
@@ -452,8 +464,9 @@ class TestFileManager : XCTestCase {
452464
let itemPath = NSTemporaryDirectory() + "\(testDirName)/item"
453465
let basePath2 = NSTemporaryDirectory() + "\(testDirName)/path2"
454466
let itemPath2 = NSTemporaryDirectory() + "\(testDirName)/path2/item"
455-
456-
try? fm.removeItem(atPath: basePath)
467+
defer {
468+
try? fm.removeItem(atPath: basePath)
469+
}
457470

458471
do {
459472
try fm.createDirectory(atPath: basePath, withIntermediateDirectories: false, attributes: nil)
@@ -786,6 +799,10 @@ class TestFileManager : XCTestCase {
786799
try? fm.removeItem(atPath: destPath)
787800
}
788801

802+
defer {
803+
cleanup()
804+
}
805+
789806
func createDirectory(atPath path: String) {
790807
do {
791808
try fm.createDirectory(atPath: path, withIntermediateDirectories: false, attributes: nil)

0 commit comments

Comments
 (0)