|
16 | 16 | #endif
|
17 | 17 |
|
18 | 18 | class TestFileManager : XCTestCase {
|
19 |
| - |
20 |
| - static var allTests: [(String, (TestFileManager) -> () throws -> Void)] { |
21 |
| - var tests: [(String, (TestFileManager) -> () throws -> Void)] = [ |
22 |
| - ("test_createDirectory", test_createDirectory ), |
23 |
| - ("test_createFile", test_createFile ), |
24 |
| - ("test_moveFile", test_moveFile), |
25 |
| - ("test_fileSystemRepresentation", test_fileSystemRepresentation), |
26 |
| - ("test_fileExists", test_fileExists), |
27 |
| - ("test_isReadableFile", test_isReadableFile), |
28 |
| - ("test_isWritableFile", test_isWritableFile), |
29 |
| - ("test_isExecutableFile", test_isExecutableFile), |
30 |
| - ("test_isDeletableFile", test_isDeletableFile), |
31 |
| - ("test_fileAttributes", test_fileAttributes), |
32 |
| - ("test_fileSystemAttributes", test_fileSystemAttributes), |
33 |
| - ("test_setFileAttributes", test_setFileAttributes), |
34 |
| - ("test_directoryEnumerator", test_directoryEnumerator), |
35 |
| - ("test_pathEnumerator",test_pathEnumerator), |
36 |
| - ("test_contentsOfDirectoryAtPath", test_contentsOfDirectoryAtPath), |
37 |
| - ("test_subpathsOfDirectoryAtPath", test_subpathsOfDirectoryAtPath), |
38 |
| - ("test_copyItemAtPathToPath", test_copyItemAtPathToPath), |
39 |
| - ("test_linkItemAtPathToPath", test_linkItemAtPathToPath), |
40 |
| - ("test_homedirectoryForUser", test_homedirectoryForUser), |
41 |
| - ("test_temporaryDirectoryForUser", test_temporaryDirectoryForUser), |
42 |
| - ("test_creatingDirectoryWithShortIntermediatePath", test_creatingDirectoryWithShortIntermediatePath), |
43 |
| - ("test_mountedVolumeURLs", test_mountedVolumeURLs), |
44 |
| - ("test_copyItemsPermissions", test_copyItemsPermissions), |
45 |
| - ("test_emptyFilename", test_emptyFilename), |
46 |
| - ] |
47 |
| - |
48 |
| -#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT |
49 |
| - tests.append(contentsOf: [ |
50 |
| - ("test_xdgStopgapsCoverAllConstants", test_xdgStopgapsCoverAllConstants), |
51 |
| - ("test_parseXDGConfiguration", test_parseXDGConfiguration), |
52 |
| - ("test_xdgURLSelection", test_xdgURLSelection), |
53 |
| - ]) |
54 |
| -#endif |
55 |
| - |
56 |
| -#if !DEPLOYMENT_RUNTIME_OBJC |
57 |
| - tests.append(contentsOf: [ |
58 |
| - ("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper), |
59 |
| - ]) |
60 |
| -#endif |
61 |
| - |
62 |
| - return tests |
63 |
| - } |
64 | 19 |
|
65 | 20 | func test_createDirectory() {
|
66 | 21 | let fm = FileManager.default
|
@@ -1432,4 +1387,113 @@ VIDEOS=StopgapVideos
|
1432 | 1387 | // Not Implemented - XCTAssertNil(fm.componentsToDisplay(forPath: ""))
|
1433 | 1388 | // Not Implemented - XCTAssertEqual(fm.displayName(atPath: ""), "")
|
1434 | 1389 | }
|
| 1390 | + |
| 1391 | + func test_getRelationship() throws { |
| 1392 | + /* a/ |
| 1393 | + a/b |
| 1394 | + a/bb |
| 1395 | + c -> symlink to a/b |
| 1396 | + d */ |
| 1397 | + |
| 1398 | + let a = writableTestDirectoryURL.appendingPathComponent("a") |
| 1399 | + let a_b = a.appendingPathComponent("b") |
| 1400 | + let a_bb = a.appendingPathComponent("bb") |
| 1401 | + let c = writableTestDirectoryURL.appendingPathComponent("c") |
| 1402 | + let a_b_d = a_b.appendingPathComponent("d") |
| 1403 | + |
| 1404 | + let fm = FileManager.default |
| 1405 | + try fm.createDirectory(at: a, withIntermediateDirectories: true) |
| 1406 | + try fm.createDirectory(at: a_b, withIntermediateDirectories: true) |
| 1407 | + try Data().write(to: a_bb) |
| 1408 | + try Data().write(to: c) |
| 1409 | + try fm.createSymbolicLink(at: a_b_d, withDestinationURL: a) |
| 1410 | + |
| 1411 | + var relationship: FileManager.URLRelationship = .other |
| 1412 | + |
| 1413 | + try fm.getRelationship(&relationship, ofDirectoryAt: writableTestDirectoryURL, toItemAt: a) |
| 1414 | + XCTAssertEqual(relationship, .contains) |
| 1415 | + |
| 1416 | + try fm.getRelationship(&relationship, ofDirectoryAt: a, toItemAt: a_b) |
| 1417 | + XCTAssertEqual(relationship, .contains) |
| 1418 | + |
| 1419 | + // The path of one is a prefix to the other, but lacks the directory separator. |
| 1420 | + try fm.getRelationship(&relationship, ofDirectoryAt: a_b, toItemAt: a_bb) |
| 1421 | + XCTAssertEqual(relationship, .other) |
| 1422 | + |
| 1423 | + try fm.getRelationship(&relationship, ofDirectoryAt: a_b, toItemAt: c) |
| 1424 | + XCTAssertEqual(relationship, .other) |
| 1425 | + |
| 1426 | + try fm.getRelationship(&relationship, ofDirectoryAt: a_b_d, toItemAt: a) |
| 1427 | + XCTAssertEqual(relationship, .same) |
| 1428 | + } |
| 1429 | + |
| 1430 | + // ----- |
| 1431 | + |
| 1432 | + var writableTestDirectoryURL: URL! |
| 1433 | + |
| 1434 | + override func setUp() { |
| 1435 | + super.setUp() |
| 1436 | + |
| 1437 | + let pid = ProcessInfo.processInfo.processIdentifier |
| 1438 | + writableTestDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("org.swift.TestFoundation.TestFileManager.\(pid)") |
| 1439 | + } |
| 1440 | + |
| 1441 | + override func tearDown() { |
| 1442 | + if let directoryURL = writableTestDirectoryURL, |
| 1443 | + (try? FileManager.default.attributesOfItem(atPath: directoryURL.path)) != nil { |
| 1444 | + do { |
| 1445 | + try FileManager.default.removeItem(at: directoryURL) |
| 1446 | + } catch { |
| 1447 | + NSLog("Could not remove test directory at URL \(directoryURL): \(error)") |
| 1448 | + } |
| 1449 | + } |
| 1450 | + |
| 1451 | + super.tearDown() |
| 1452 | + } |
| 1453 | + |
| 1454 | + static var allTests: [(String, (TestFileManager) -> () throws -> Void)] { |
| 1455 | + var tests: [(String, (TestFileManager) -> () throws -> Void)] = [ |
| 1456 | + ("test_createDirectory", test_createDirectory ), |
| 1457 | + ("test_createFile", test_createFile ), |
| 1458 | + ("test_moveFile", test_moveFile), |
| 1459 | + ("test_fileSystemRepresentation", test_fileSystemRepresentation), |
| 1460 | + ("test_fileExists", test_fileExists), |
| 1461 | + ("test_isReadableFile", test_isReadableFile), |
| 1462 | + ("test_isWritableFile", test_isWritableFile), |
| 1463 | + ("test_isExecutableFile", test_isExecutableFile), |
| 1464 | + ("test_isDeletableFile", test_isDeletableFile), |
| 1465 | + ("test_fileAttributes", test_fileAttributes), |
| 1466 | + ("test_fileSystemAttributes", test_fileSystemAttributes), |
| 1467 | + ("test_setFileAttributes", test_setFileAttributes), |
| 1468 | + ("test_directoryEnumerator", test_directoryEnumerator), |
| 1469 | + ("test_pathEnumerator",test_pathEnumerator), |
| 1470 | + ("test_contentsOfDirectoryAtPath", test_contentsOfDirectoryAtPath), |
| 1471 | + ("test_subpathsOfDirectoryAtPath", test_subpathsOfDirectoryAtPath), |
| 1472 | + ("test_copyItemAtPathToPath", test_copyItemAtPathToPath), |
| 1473 | + ("test_linkItemAtPathToPath", test_linkItemAtPathToPath), |
| 1474 | + ("test_homedirectoryForUser", test_homedirectoryForUser), |
| 1475 | + ("test_temporaryDirectoryForUser", test_temporaryDirectoryForUser), |
| 1476 | + ("test_creatingDirectoryWithShortIntermediatePath", test_creatingDirectoryWithShortIntermediatePath), |
| 1477 | + ("test_mountedVolumeURLs", test_mountedVolumeURLs), |
| 1478 | + ("test_copyItemsPermissions", test_copyItemsPermissions), |
| 1479 | + ("test_emptyFilename", test_emptyFilename), |
| 1480 | + ("test_getRelationship", test_getRelationship), |
| 1481 | + ] |
| 1482 | + |
| 1483 | + #if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT |
| 1484 | + tests.append(contentsOf: [ |
| 1485 | + ("test_xdgStopgapsCoverAllConstants", test_xdgStopgapsCoverAllConstants), |
| 1486 | + ("test_parseXDGConfiguration", test_parseXDGConfiguration), |
| 1487 | + ("test_xdgURLSelection", test_xdgURLSelection), |
| 1488 | + ]) |
| 1489 | + #endif |
| 1490 | + |
| 1491 | + #if !DEPLOYMENT_RUNTIME_OBJC |
| 1492 | + tests.append(contentsOf: [ |
| 1493 | + ("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper), |
| 1494 | + ]) |
| 1495 | + #endif |
| 1496 | + |
| 1497 | + return tests |
| 1498 | + } |
1435 | 1499 | }
|
0 commit comments