Skip to content

Commit 132d1cb

Browse files
committed
Adjust file manager tests to use unique path names generated by NSUUID
1 parent 8b5ff77 commit 132d1cb

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

TestFoundation/TestNSFileManager.swift

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TestNSFileManager : XCTestCase {
3838

3939
func test_createDirectory() {
4040
let fm = NSFileManager.defaultManager()
41-
let path = "/tmp/testdir"
41+
let path = "/tmp/testdir\(NSUUID().UUIDString)"
4242

4343
ignoreError { try fm.removeItem(atPath: path) }
4444

@@ -63,7 +63,7 @@ class TestNSFileManager : XCTestCase {
6363

6464
func test_createFile() {
6565
let fm = NSFileManager.defaultManager()
66-
let path = "/tmp/testfile"
66+
let path = "/tmp/testfile\(NSUUID().UUIDString)"
6767

6868
ignoreError { try fm.removeItem(atPath: path) }
6969

@@ -83,8 +83,8 @@ class TestNSFileManager : XCTestCase {
8383

8484
func test_moveFile() {
8585
let fm = NSFileManager.defaultManager()
86-
let path = "/tmp/testfile"
87-
let path2 = "/tmp/testfile2"
86+
let path = "/tmp/testfile\(NSUUID().UUIDString)"
87+
let path2 = "/tmp/testfile2\(NSUUID().UUIDString)"
8888

8989
func cleanup() {
9090
ignoreError { try fm.removeItem(atPath: path) }
@@ -179,14 +179,21 @@ class TestNSFileManager : XCTestCase {
179179
XCTAssert((attributes[NSFilePosixPermissions] as? NSNumber)?.int16Value == 0o0600)
180180
}
181181
catch { XCTFail("\(error)") }
182+
183+
do {
184+
try fm.removeItem(atPath: path)
185+
} catch {
186+
XCTFail("Failed to clean up files")
187+
}
182188
}
183189

184190
func test_pathEnumerator() {
185191
let fm = NSFileManager.defaultManager()
186-
let basePath = "/tmp/testdir"
187-
let itemPath = "/tmp/testdir/item"
188-
let basePath2 = "/tmp/testdir/path2"
189-
let itemPath2 = "/tmp/testdir/path2/item"
192+
let testDirName = "testdir\(NSUUID().UUIDString)"
193+
let basePath = "/tmp/\(testDirName)"
194+
let itemPath = "/tmp/\(testDirName)/item"
195+
let basePath2 = "/tmp/\(testDirName)/path2"
196+
let itemPath2 = "/tmp/\(testDirName)/path2/item"
190197

191198
ignoreError { try fm.removeItem(atPath: basePath) }
192199

@@ -215,8 +222,9 @@ class TestNSFileManager : XCTestCase {
215222

216223
func test_directoryEnumerator() {
217224
let fm = NSFileManager.defaultManager()
218-
let path = "/tmp/testdir"
219-
let itemPath = "/tmp/testdir/item"
225+
let testDirName = "testdir\(NSUUID().UUIDString)"
226+
let path = "/tmp/\(testDirName)"
227+
let itemPath = "/tmp/\(testDirName)/item"
220228

221229
ignoreError { try fm.removeItem(atPath: path) }
222230

@@ -239,8 +247,8 @@ class TestNSFileManager : XCTestCase {
239247
XCTFail()
240248
}
241249

242-
let subDirPath = "/tmp/testdir/testdir2"
243-
let subDirItemPath = "/tmp/testdir/testdir2/item"
250+
let subDirPath = "/tmp/\(testDirName)/testdir2"
251+
let subDirItemPath = "/tmp/\(testDirName)/testdir2/item"
244252
do {
245253
try fm.createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
246254
fm.createFile(atPath: subDirItemPath, contents: NSData(), attributes: nil)
@@ -320,9 +328,10 @@ class TestNSFileManager : XCTestCase {
320328

321329
func test_contentsOfDirectoryAtPath() {
322330
let fm = NSFileManager.defaultManager()
323-
let path = "/tmp/testdir"
324-
let itemPath1 = "/tmp/testdir/item"
325-
let itemPath2 = "/tmp/testdir/item2"
331+
let testDirName = "testdir\(NSUUID().UUIDString)"
332+
let path = "/tmp/\(testDirName)"
333+
let itemPath1 = "/tmp/\(testDirName)/item"
334+
let itemPath2 = "/tmp/\(testDirName)/item2"
326335

327336
ignoreError { try fm.removeItem(atPath: path) }
328337

0 commit comments

Comments
 (0)