@@ -23,6 +23,7 @@ class TestFileManager : XCTestCase {
23
23
( " test_createFile " , test_createFile ) ,
24
24
( " test_moveFile " , test_moveFile) ,
25
25
( " test_fileSystemRepresentation " , test_fileSystemRepresentation) ,
26
+ ( " test_fileExists " , test_fileExists) ,
26
27
( " test_fileAttributes " , test_fileAttributes) ,
27
28
( " test_fileSystemAttributes " , test_fileSystemAttributes) ,
28
29
( " test_setFileAttributes " , test_setFileAttributes) ,
@@ -161,7 +162,53 @@ class TestFileManager : XCTestCase {
161
162
result. deallocate ( )
162
163
#endif
163
164
}
164
-
165
+
166
+ func test_fileExists( ) {
167
+ let fm = FileManager . default
168
+ let tmpDir = fm. temporaryDirectory. appendingPathComponent ( " testFileExistsDir " )
169
+ let testFile = tmpDir. appendingPathComponent ( " testFile " )
170
+ let goodSymLink = tmpDir. appendingPathComponent ( " goodSymLink " )
171
+ let badSymLink = tmpDir. appendingPathComponent ( " badSymLink " )
172
+ let dirSymLink = tmpDir. appendingPathComponent ( " dirSymlink " )
173
+
174
+ ignoreError { try fm. removeItem ( atPath: tmpDir. path) }
175
+
176
+ do {
177
+ try fm. createDirectory ( atPath: tmpDir. path, withIntermediateDirectories: false , attributes: nil )
178
+ XCTAssertTrue ( fm. createFile ( atPath: testFile. path, contents: Data ( ) ) )
179
+ try fm. createSymbolicLink ( atPath: goodSymLink. path, withDestinationPath: testFile. path)
180
+ try fm. createSymbolicLink ( atPath: badSymLink. path, withDestinationPath: " no_such_file " )
181
+ try fm. createSymbolicLink ( atPath: dirSymLink. path, withDestinationPath: " .. " )
182
+
183
+ var isDirFlag : ObjCBool = false
184
+ XCTAssertTrue ( fm. fileExists ( atPath: tmpDir. path) )
185
+ XCTAssertTrue ( fm. fileExists ( atPath: tmpDir. path, isDirectory: & isDirFlag) )
186
+ XCTAssertTrue ( isDirFlag. boolValue)
187
+
188
+ isDirFlag = true
189
+ XCTAssertTrue ( fm. fileExists ( atPath: testFile. path) )
190
+ XCTAssertTrue ( fm. fileExists ( atPath: testFile. path, isDirectory: & isDirFlag) )
191
+ XCTAssertFalse ( isDirFlag. boolValue)
192
+
193
+ isDirFlag = true
194
+ XCTAssertTrue ( fm. fileExists ( atPath: goodSymLink. path) )
195
+ XCTAssertTrue ( fm. fileExists ( atPath: goodSymLink. path, isDirectory: & isDirFlag) )
196
+ XCTAssertFalse ( isDirFlag. boolValue)
197
+
198
+ isDirFlag = true
199
+ XCTAssertFalse ( fm. fileExists ( atPath: badSymLink. path) )
200
+ XCTAssertFalse ( fm. fileExists ( atPath: badSymLink. path, isDirectory: & isDirFlag) )
201
+
202
+ isDirFlag = false
203
+ XCTAssertTrue ( fm. fileExists ( atPath: dirSymLink. path) )
204
+ XCTAssertTrue ( fm. fileExists ( atPath: dirSymLink. path, isDirectory: & isDirFlag) )
205
+ XCTAssertTrue ( isDirFlag. boolValue)
206
+ } catch {
207
+ XCTFail ( String ( describing: error) )
208
+ }
209
+ ignoreError { try fm. removeItem ( atPath: tmpDir. path) }
210
+ }
211
+
165
212
func test_fileAttributes( ) {
166
213
let fm = FileManager . default
167
214
let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
0 commit comments