@@ -214,10 +214,20 @@ final class FileManagerTests : XCTestCase {
214
214
File ( " Baz " , contents: randomData ( ) )
215
215
}
216
216
}
217
+ Directory ( " symlinks " ) {
218
+ File ( " Foo " , contents: randomData ( ) )
219
+ SymbolicLink ( " LinkToFoo " , destination: " Foo " )
220
+ }
221
+ Directory ( " EmptyDirectory " ) { }
222
+ " EmptyFile "
217
223
} . test {
218
224
XCTAssertTrue ( $0. contentsEqual ( atPath: " dir1 " , andPath: " dir1_copy " ) )
219
225
XCTAssertFalse ( $0. contentsEqual ( atPath: " dir1/dir2 " , andPath: " dir1/dir3 " ) )
220
226
XCTAssertFalse ( $0. contentsEqual ( atPath: " dir1 " , andPath: " dir1_diffdata " ) )
227
+ XCTAssertFalse ( $0. contentsEqual ( atPath: " symlinks/LinkToFoo " , andPath: " symlinks/Foo " ) , " Symbolic link should not be equal to its destination " )
228
+ XCTAssertFalse ( $0. contentsEqual ( atPath: " symlinks/LinkToFoo " , andPath: " EmptyFile " ) , " Symbolic link should not be equal to an empty file " )
229
+ XCTAssertFalse ( $0. contentsEqual ( atPath: " symlinks/LinkToFoo " , andPath: " EmptyDirectory " ) , " Symbolic link should not be equal to an empty directory " )
230
+ XCTAssertFalse ( $0. contentsEqual ( atPath: " symlinks/EmptyDirectory " , andPath: " EmptyFile " ) , " Empty directory should not be equal to empty file " )
221
231
}
222
232
}
223
233
@@ -253,21 +263,30 @@ final class FileManagerTests : XCTestCase {
253
263
" Baz "
254
264
}
255
265
}
266
+ Directory ( " symlinks " ) {
267
+ " Foo "
268
+ SymbolicLink ( " Bar " , destination: " Foo " )
269
+ SymbolicLink ( " Parent " , destination: " .. " )
270
+ }
256
271
} . test {
257
272
XCTAssertEqual ( try $0. subpathsOfDirectory ( atPath: " dir1 " ) . sorted ( ) , [ " dir2 " , " dir2/Bar " , " dir2/Foo " , " dir3 " , " dir3/Baz " ] )
258
273
XCTAssertEqual ( try $0. subpathsOfDirectory ( atPath: " dir1/dir2 " ) . sorted ( ) , [ " Bar " , " Foo " ] )
259
274
XCTAssertEqual ( try $0. subpathsOfDirectory ( atPath: " dir1/dir3 " ) . sorted ( ) , [ " Baz " ] )
275
+
276
+ XCTAssertEqual ( try $0. subpathsOfDirectory ( atPath: " symlinks " ) . sorted ( ) , [ " Bar " , " Foo " , " Parent " ] )
277
+
260
278
XCTAssertThrowsError ( try $0. subpathsOfDirectory ( atPath: " does_not_exist " ) ) {
261
279
XCTAssertEqual ( ( $0 as? CocoaError ) ? . code, . fileReadNoSuchFile)
262
280
}
263
281
264
- let fullContents = [ " dir1 " , " dir1/dir2 " , " dir1/dir2/Bar " , " dir1/dir2/Foo " , " dir1/dir3 " , " dir1/dir3/Baz " ]
282
+ let fullContents = [ " dir1 " , " dir1/dir2 " , " dir1/dir2/Bar " , " dir1/dir2/Foo " , " dir1/dir3 " , " dir1/dir3/Baz " , " symlinks " , " symlinks/Bar " , " symlinks/Foo " , " symlinks/Parent " ]
265
283
let cwd = $0. currentDirectoryPath
266
284
XCTAssertNotEqual ( cwd. last, " / " )
267
285
let paths = [ cwd, " \( cwd) / " , " \( cwd) // " , " . " , " ./ " , " .// " ]
268
286
for path in paths {
269
287
XCTAssertEqual ( try $0. subpathsOfDirectory ( atPath: path) . sorted ( ) , fullContents)
270
288
}
289
+
271
290
}
272
291
}
273
292
@@ -345,6 +364,32 @@ final class FileManagerTests : XCTestCase {
345
364
XCTAssertEqual ( $0. delegateCaptures. shouldCopy, [ . init( " foo " , " bar " ) ] )
346
365
XCTAssertEqual ( $0. delegateCaptures. shouldProceedAfterCopyError, [ . init( " foo " , " bar " , code: . fileWriteFileExists) ] )
347
366
}
367
+
368
+ try FileManagerPlayground {
369
+ " foo "
370
+ SymbolicLink ( " bar " , destination: " foo " )
371
+ } . test ( captureDelegateCalls: true ) {
372
+ XCTAssertTrue ( $0. delegateCaptures. isEmpty)
373
+ try $0. copyItem ( atPath: " bar " , toPath: " copy " )
374
+ XCTAssertEqual ( $0. delegateCaptures. shouldCopy, [ . init( " bar " , " copy " ) ] )
375
+ XCTAssertEqual ( $0. delegateCaptures. shouldProceedAfterCopyError, [ ] )
376
+ let copyDestination = try $0. destinationOfSymbolicLink ( atPath: " copy " )
377
+ XCTAssertEqual ( copyDestination. lastPathComponent, " foo " , " Copied symbolic link points at \( copyDestination) instead of foo " )
378
+ }
379
+
380
+ try FileManagerPlayground {
381
+ Directory ( " dir " ) {
382
+ " foo "
383
+ }
384
+ SymbolicLink ( " link " , destination: " dir " )
385
+ } . test ( captureDelegateCalls: true ) {
386
+ XCTAssertTrue ( $0. delegateCaptures. isEmpty)
387
+ try $0. copyItem ( atPath: " link " , toPath: " copy " )
388
+ XCTAssertEqual ( $0. delegateCaptures. shouldCopy, [ . init( " link " , " copy " ) ] )
389
+ XCTAssertEqual ( $0. delegateCaptures. shouldProceedAfterCopyError, [ ] )
390
+ let copyDestination = try $0. destinationOfSymbolicLink ( atPath: " copy " )
391
+ XCTAssertEqual ( copyDestination. lastPathComponent, " dir " , " Copied symbolic link points at \( copyDestination) instead of foo " )
392
+ }
348
393
}
349
394
350
395
func testCreateSymbolicLinkAtPath( ) throws {
0 commit comments