@@ -210,14 +210,17 @@ class TestFileManager : XCTestCase {
210210 let fm = FileManager . default
211211 let path = NSTemporaryDirectory ( ) + " test_isReadableFile \( NSUUID ( ) . uuidString) "
212212
213- XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
214-
215213 do {
216- let attrs = try fm. attributesOfItem ( atPath: path)
217- let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
218- let fileIsReadableFile = ( permissions & S_IRUSR == S_IRUSR)
219- let fmIsReadableFile = fm. isReadableFile ( atPath: path)
220- XCTAssertTrue ( fileIsReadableFile == fmIsReadableFile)
214+ // create test file
215+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
216+
217+ // test unReadable if file has no permissions
218+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0000 ) ) ] , ofItemAtPath: path)
219+ XCTAssertFalse ( fm. isReadableFile ( atPath: path) )
220+
221+ // test readable if file has read permissions
222+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0400 ) ) ] , ofItemAtPath: path)
223+ XCTAssertTrue ( fm. isReadableFile ( atPath: path) )
221224 } catch let e {
222225 XCTFail ( " \( e) " )
223226 }
@@ -227,14 +230,17 @@ class TestFileManager : XCTestCase {
227230 let fm = FileManager . default
228231 let path = NSTemporaryDirectory ( ) + " test_isWritableFile \( NSUUID ( ) . uuidString) "
229232
230- XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
231-
232233 do {
233- let attrs = try fm. attributesOfItem ( atPath: path)
234- let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
235- let fileIsWritableFile = ( permissions & S_IWUSR == S_IWUSR)
236- let fmIsWritableFile = fm. isWritableFile ( atPath: path)
237- XCTAssertTrue ( fileIsWritableFile == fmIsWritableFile)
234+ // create test file
235+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
236+
237+ // test unWritable if file has no permissions
238+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0000 ) ) ] , ofItemAtPath: path)
239+ XCTAssertFalse ( fm. isWritableFile ( atPath: path) )
240+
241+ // test writable if file has write permissions
242+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0200 ) ) ] , ofItemAtPath: path)
243+ XCTAssertTrue ( fm. isWritableFile ( atPath: path) )
238244 } catch let e {
239245 XCTFail ( " \( e) " )
240246 }
@@ -244,14 +250,17 @@ class TestFileManager : XCTestCase {
244250 let fm = FileManager . default
245251 let path = NSTemporaryDirectory ( ) + " test_isExecutableFile \( NSUUID ( ) . uuidString) "
246252
247- XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
248-
249253 do {
250- let attrs = try fm. attributesOfItem ( atPath: path)
251- let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
252- let fileIsExecutableFile = ( permissions & S_IXUSR == S_IXUSR)
253- let fmIsExecutableFile = fm. isExecutableFile ( atPath: path)
254- XCTAssertTrue ( fileIsExecutableFile == fmIsExecutableFile)
254+ // create test file
255+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) ) )
256+
257+ // test unExecutable if file has no permissions
258+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0000 ) ) ] , ofItemAtPath: path)
259+ XCTAssertFalse ( fm. isExecutableFile ( atPath: path) )
260+
261+ // test executable if file has execute permissions
262+ try fm. setAttributes ( [ . posixPermissions : NSNumber ( value: Int16 ( 0o0100 ) ) ] , ofItemAtPath: path)
263+ XCTAssertTrue ( fm. isExecutableFile ( atPath: path) )
255264 } catch let e {
256265 XCTFail ( " \( e) " )
257266 }
0 commit comments