@@ -31,6 +31,7 @@ class TestFileManager : XCTestCase {
31
31
( " test_subpathsOfDirectoryAtPath " , test_subpathsOfDirectoryAtPath) ,
32
32
( " test_copyItemAtPathToPath " , test_copyItemAtPathToPath) ,
33
33
( " test_homedirectoryForUser " , test_homedirectoryForUser) ,
34
+ ( " test_temporaryDirectoryForUser " , test_temporaryDirectoryForUser) ,
34
35
]
35
36
}
36
37
@@ -525,4 +526,25 @@ class TestFileManager : XCTestCase {
525
526
XCTAssertNil ( filemanger. homeDirectory ( forUser: " " ) )
526
527
XCTAssertNotNil ( filemanger. homeDirectoryForCurrentUser)
527
528
}
529
+
530
+ func test_temporaryDirectoryForUser( ) {
531
+ let filemanger = FileManager . default
532
+ let tmpDir = filemanger. temporaryDirectory
533
+ XCTAssertNotNil ( tmpDir)
534
+ let tmpFileUrl = tmpDir. appendingPathComponent ( " test.bin " )
535
+ let tmpFilePath = tmpFileUrl. path
536
+
537
+ do {
538
+ if filemanger. fileExists ( atPath: tmpFilePath) {
539
+ try filemanger. removeItem ( at: tmpFileUrl)
540
+ }
541
+
542
+ try " hello world " . write ( to: tmpFileUrl, atomically: false , encoding: . utf8)
543
+ XCTAssert ( filemanger. fileExists ( atPath: tmpFilePath) )
544
+
545
+ try filemanger. removeItem ( at: tmpFileUrl)
546
+ } catch {
547
+ XCTFail ( " Unable to write a file to the temporary directory: \( tmpDir) , err: \( error) " )
548
+ }
549
+ }
528
550
}
0 commit comments