@@ -208,9 +208,9 @@ class TestFileManager : XCTestCase {
208
208
209
209
func test_isReadableFile( ) {
210
210
let fm = FileManager . default
211
- let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
211
+ let path = NSTemporaryDirectory ( ) + " test_isReadableFile \( NSUUID ( ) . uuidString) "
212
212
213
- XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) , attributes : nil ) )
213
+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
214
214
215
215
do {
216
216
let attrs = try fm. attributesOfItem ( atPath: path)
@@ -225,41 +225,61 @@ class TestFileManager : XCTestCase {
225
225
226
226
func test_isWritableFile( ) {
227
227
let fm = FileManager . default
228
- let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
228
+ let path = NSTemporaryDirectory ( ) + " test_isWritableFile \( NSUUID ( ) . uuidString) "
229
229
230
- XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) , attributes : nil ) )
230
+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
231
231
232
232
do {
233
233
let attrs = try fm. attributesOfItem ( atPath: path)
234
234
let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
235
- let fileIsReadableFile = ( permissions & S_IWUSR == S_IWUSR)
236
- let fmIsReadableFile = fm. isReadableFile ( atPath: path)
237
- XCTAssertTrue ( fileIsReadableFile == fmIsReadableFile )
235
+ let fileIsWritableFile = ( permissions & S_IWUSR == S_IWUSR)
236
+ let fmIsWritableFile = fm. isWritableFile ( atPath: path)
237
+ XCTAssertTrue ( fileIsWritableFile == fmIsWritableFile )
238
238
} catch let e {
239
239
XCTFail ( " \( e) " )
240
240
}
241
241
}
242
242
243
243
func test_isExecutableFile( ) {
244
244
let fm = FileManager . default
245
- let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
245
+ let path = NSTemporaryDirectory ( ) + " test_isExecutableFile \( NSUUID ( ) . uuidString) "
246
246
247
- XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) , attributes : nil ) )
247
+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
248
248
249
249
do {
250
250
let attrs = try fm. attributesOfItem ( atPath: path)
251
251
let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
252
- let fileIsReadableFile = ( permissions & S_IXUSR == S_IXUSR)
253
- let fmIsReadableFile = fm. isReadableFile ( atPath: path)
254
- XCTAssertTrue ( fileIsReadableFile == fmIsReadableFile )
252
+ let fileIsExecutableFile = ( permissions & S_IXUSR == S_IXUSR)
253
+ let fmIsExecutableFile = fm. isExecutableFile ( atPath: path)
254
+ XCTAssertTrue ( fileIsExecutableFile == fmIsExecutableFile )
255
255
} catch let e {
256
256
XCTFail ( " \( e) " )
257
257
}
258
258
}
259
259
260
260
func test_isDeletableFile( ) {
261
- // TODO: Implement test
262
- // how to test?
261
+ let fm = FileManager . default
262
+
263
+ do {
264
+ let dir_path = NSTemporaryDirectory ( ) + " /test_isDeletableFile_dir/ "
265
+ let file_path = dir_path + " test_isDeletableFile \( NSUUID ( ) . uuidString) "
266
+ // create test directory
267
+ try fm. createDirectory ( atPath: dir_path, withIntermediateDirectories: true )
268
+ // create test file
269
+ XCTAssertTrue ( fm. createFile ( atPath: file_path, contents: Data ( ) ) )
270
+
271
+ // test undeletable if parent directory has no permissions
272
+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0000 ) ) ] , ofItemAtPath: dir_path)
273
+ XCTAssertFalse ( fm. isDeletableFile ( atPath: file_path) )
274
+
275
+ // test deletable if parent directory has all necessary permissions
276
+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0755 ) ) ] , ofItemAtPath: dir_path)
277
+ XCTAssertTrue ( fm. isDeletableFile ( atPath: file_path) )
278
+ }
279
+ catch { XCTFail ( " \( error) " ) }
280
+
281
+ // test against known undeletable file
282
+ XCTAssertFalse ( fm. isDeletableFile ( atPath: " /dev/null " ) )
263
283
}
264
284
265
285
func test_fileAttributes( ) {
0 commit comments