@@ -17,23 +17,26 @@ import TSCLibc
17
17
class FileSystemTests : XCTestCase {
18
18
19
19
// MARK: LocalFS Tests
20
-
21
20
func testLocalBasics( ) throws {
22
21
let fs = TSCBasic . localFileSystem
22
+ #if os(Windows)
23
+ XCTSkip ( " FIXME: withTemporaryDirectory(removeTreeOnDeinit: true) will throw on Windows " )
24
+ return
25
+ #endif
23
26
try ! withTemporaryFile { file in
24
27
try ! withTemporaryDirectory ( removeTreeOnDeinit: true ) { tempDirPath in
25
28
// exists()
26
- XCTAssert ( fs. exists ( AbsolutePath ( " / " ) ) )
27
- XCTAssert ( !fs. exists ( AbsolutePath ( " /does-not-exist " ) ) )
29
+ XCTAssert ( fs. exists ( AbsolutePath . withPOSIX ( path : " / " ) ) )
30
+ XCTAssert ( !fs. exists ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) ) )
28
31
29
32
// isFile()
30
33
XCTAssertTrue ( fs. exists ( file. path) )
31
34
XCTAssertTrue ( fs. isFile ( file. path) )
32
35
XCTAssertEqual ( try fs. getFileInfo ( file. path) . fileType, . typeRegular)
33
36
XCTAssertFalse ( fs. isDirectory ( file. path) )
34
- XCTAssertFalse ( fs. isFile ( AbsolutePath ( " /does-not-exist " ) ) )
35
- XCTAssertFalse ( fs. isSymlink ( AbsolutePath ( " /does-not-exist " ) ) )
36
- XCTAssertThrowsError ( try fs. getFileInfo ( AbsolutePath ( " /does-not-exist " ) ) )
37
+ XCTAssertFalse ( fs. isFile ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) ) )
38
+ XCTAssertFalse ( fs. isSymlink ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) ) )
39
+ XCTAssertThrowsError ( try fs. getFileInfo ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) ) )
37
40
38
41
// isSymlink()
39
42
let sym = tempDirPath. appending ( component: " hello " )
@@ -46,7 +49,7 @@ class FileSystemTests: XCTestCase {
46
49
// isExecutableFile
47
50
let executable = tempDirPath. appending ( component: " exec-foo " )
48
51
let executableSym = tempDirPath. appending ( component: " exec-sym " )
49
- try ! fs. createSymbolicLink ( executableSym, pointingAt: executable, relative: false )
52
+ try fs. createSymbolicLink ( executableSym, pointingAt: executable, relative: false )
50
53
let stream = BufferedOutputByteStream ( )
51
54
stream <<< """
52
55
#!/bin/sh
@@ -61,16 +64,16 @@ class FileSystemTests: XCTestCase {
61
64
XCTAssertTrue ( fs. isSymlink ( executableSym) )
62
65
XCTAssertFalse ( fs. isExecutableFile ( sym) )
63
66
XCTAssertFalse ( fs. isExecutableFile ( file. path) )
64
- XCTAssertFalse ( fs. isExecutableFile ( AbsolutePath ( " /does-not-exist " ) ) )
65
- XCTAssertFalse ( fs. isExecutableFile ( AbsolutePath ( " / " ) ) )
67
+ XCTAssertFalse ( fs. isExecutableFile ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) ) )
68
+ XCTAssertFalse ( fs. isExecutableFile ( AbsolutePath . withPOSIX ( path : " / " ) ) )
66
69
67
70
// isDirectory()
68
- XCTAssert ( fs. isDirectory ( AbsolutePath ( " / " ) ) )
69
- XCTAssert ( !fs. isDirectory ( AbsolutePath ( " /does-not-exist " ) ) )
71
+ XCTAssert ( fs. isDirectory ( AbsolutePath . withPOSIX ( path : " / " ) ) )
72
+ XCTAssert ( !fs. isDirectory ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) ) )
70
73
71
74
// getDirectoryContents()
72
75
do {
73
- _ = try fs. getDirectoryContents ( AbsolutePath ( " /does-not-exist " ) )
76
+ _ = try fs. getDirectoryContents ( AbsolutePath . withPOSIX ( path : " /does-not-exist " ) )
74
77
XCTFail ( " Unexpected success " )
75
78
} catch {
76
79
XCTAssertEqual ( error. localizedDescription, " The folder “does-not-exist” doesn’t exist. " )
@@ -219,7 +222,7 @@ class FileSystemTests: XCTestCase {
219
222
XCTAssertEqual ( data, ByteString ( testData) )
220
223
221
224
// Atomic writes
222
- let inMemoryFilePath = AbsolutePath ( " /file.text " )
225
+ let inMemoryFilePath = AbsolutePath . withPOSIX ( path : " /file.text " )
223
226
XCTAssertNoThrow ( try TSCBasic . InMemoryFileSystem ( files: [ : ] ) . writeFileContents ( inMemoryFilePath, bytes: ByteString ( testData) , atomically: true ) )
224
227
XCTAssertNoThrow ( try TSCBasic . InMemoryFileSystem ( files: [ : ] ) . writeFileContents ( inMemoryFilePath, bytes: ByteString ( testData) , atomically: false ) )
225
228
// Local file system does support atomic writes, so it doesn't throw.
@@ -255,9 +258,9 @@ class FileSystemTests: XCTestCase {
255
258
256
259
// Check read/write against root.
257
260
#if os(Android)
258
- let root = AbsolutePath ( " /system/ " )
261
+ let root = AbsolutePath . withPOSIX ( path : " /system/ " )
259
262
#else
260
- let root = AbsolutePath ( " / " )
263
+ let root = AbsolutePath . withPOSIX ( path : " / " )
261
264
#endif
262
265
XCTAssertThrows ( FileSystemError ( . ioError( code: TSCLibc . EPERM) , root) ) {
263
266
_ = try fs. readFileContents ( root)
@@ -376,7 +379,7 @@ class FileSystemTests: XCTestCase {
376
379
377
380
func testInMemoryBasics( ) throws {
378
381
let fs = InMemoryFileSystem ( )
379
- let doesNotExist = AbsolutePath ( " /does-not-exist " )
382
+ let doesNotExist = AbsolutePath . withPOSIX ( path : " /does-not-exist " )
380
383
381
384
// exists()
382
385
XCTAssert ( !fs. exists ( doesNotExist) )
@@ -396,22 +399,22 @@ class FileSystemTests: XCTestCase {
396
399
}
397
400
398
401
// createDirectory()
399
- XCTAssert ( !fs. isDirectory ( AbsolutePath ( " /new-dir " ) ) )
400
- try fs. createDirectory ( AbsolutePath ( " /new-dir/subdir " ) , recursive: true )
401
- XCTAssert ( fs. isDirectory ( AbsolutePath ( " /new-dir " ) ) )
402
- XCTAssert ( fs. isDirectory ( AbsolutePath ( " /new-dir/subdir " ) ) )
403
- XCTAssertEqual ( try fs. getDirectoryContents ( AbsolutePath ( " / " ) ) , [ " new-dir " ] )
404
- XCTAssertEqual ( try fs. getDirectoryContents ( AbsolutePath ( " /new-dir " ) ) , [ " subdir " ] )
402
+ XCTAssert ( !fs. isDirectory ( AbsolutePath . withPOSIX ( path : " /new-dir " ) ) )
403
+ try fs. createDirectory ( AbsolutePath . withPOSIX ( path : " /new-dir/subdir " ) , recursive: true )
404
+ XCTAssert ( fs. isDirectory ( AbsolutePath . withPOSIX ( path : " /new-dir " ) ) )
405
+ XCTAssert ( fs. isDirectory ( AbsolutePath . withPOSIX ( path : " /new-dir/subdir " ) ) )
406
+ XCTAssertEqual ( try fs. getDirectoryContents ( AbsolutePath . withPOSIX ( path : " / " ) ) , [ " new-dir " ] )
407
+ XCTAssertEqual ( try fs. getDirectoryContents ( AbsolutePath . withPOSIX ( path : " /new-dir " ) ) , [ " subdir " ] )
405
408
}
406
409
407
410
func testInMemoryCreateDirectory( ) {
408
411
let fs = InMemoryFileSystem ( )
409
412
// Make sure root entry isn't created.
410
- try ! fs. createDirectory ( AbsolutePath ( " / " ) , recursive: true )
413
+ try ! fs. createDirectory ( AbsolutePath . withPOSIX ( path : " / " ) , recursive: true )
411
414
let rootContents = try ! fs. getDirectoryContents ( . root)
412
415
XCTAssertEqual ( rootContents, [ ] )
413
416
414
- let subdir = AbsolutePath ( " /new-dir/subdir " )
417
+ let subdir = AbsolutePath . withPOSIX ( path : " /new-dir/subdir " )
415
418
try ! fs. createDirectory ( subdir, recursive: true )
416
419
XCTAssert ( fs. isDirectory ( subdir) )
417
420
@@ -426,7 +429,7 @@ class FileSystemTests: XCTestCase {
426
429
XCTAssert ( fs. isDirectory ( subsubdir) )
427
430
428
431
// Check non-recursive failing subdir case.
429
- let veryNewDir = AbsolutePath ( " /very-new-dir " )
432
+ let veryNewDir = AbsolutePath . withPOSIX ( path : " /very-new-dir " )
430
433
let newsubdir = veryNewDir. appending ( component: " subdir " )
431
434
XCTAssert ( !fs. isDirectory ( newsubdir) )
432
435
XCTAssertThrows ( FileSystemError ( . noEntry, veryNewDir) ) {
@@ -435,7 +438,7 @@ class FileSystemTests: XCTestCase {
435
438
XCTAssert ( !fs. isDirectory ( newsubdir) )
436
439
437
440
// Check directory creation over a file.
438
- let filePath = AbsolutePath ( " /mach_kernel " )
441
+ let filePath = AbsolutePath . withPOSIX ( path : " /mach_kernel " )
439
442
try ! fs. writeFileContents ( filePath, bytes: [ 0xCD , 0x0D ] )
440
443
XCTAssert ( fs. exists ( filePath) && !fs. isDirectory ( filePath) )
441
444
XCTAssertThrows ( FileSystemError ( . notDirectory, filePath) ) {
@@ -480,10 +483,10 @@ class FileSystemTests: XCTestCase {
480
483
481
484
func testInMemoryReadWriteFile( ) {
482
485
let fs = InMemoryFileSystem ( )
483
- try ! fs. createDirectory ( AbsolutePath ( " /new-dir/subdir " ) , recursive: true )
486
+ try ! fs. createDirectory ( AbsolutePath . withPOSIX ( path : " /new-dir/subdir " ) , recursive: true )
484
487
485
488
// Check read/write of a simple file.
486
- let filePath = AbsolutePath ( " /new-dir/subdir " ) . appending ( component: " new-file.txt " )
489
+ let filePath = AbsolutePath . withPOSIX ( path : " /new-dir/subdir " ) . appending ( component: " new-file.txt " )
487
490
XCTAssert ( !fs. exists ( filePath) )
488
491
XCTAssertFalse ( fs. isFile ( filePath) )
489
492
try ! fs. writeFileContents ( filePath, bytes: " Hello, world! " )
@@ -507,7 +510,7 @@ class FileSystemTests: XCTestCase {
507
510
XCTAssertEqual ( try ! fs. readFileContents ( filePath) , " Hello, new world! " )
508
511
509
512
// Check read/write against root.
510
- let root = AbsolutePath ( " / " )
513
+ let root = AbsolutePath . withPOSIX ( path : " / " )
511
514
XCTAssertThrows ( FileSystemError ( . isDirectory, root) ) {
512
515
_ = try fs. readFileContents ( root)
513
516
}
@@ -528,7 +531,7 @@ class FileSystemTests: XCTestCase {
528
531
XCTAssert ( fs. exists ( filePath) )
529
532
530
533
// Check read/write into a missing directory.
531
- let missingParent = AbsolutePath ( " /does/not " )
534
+ let missingParent = AbsolutePath . withPOSIX ( path : " /does/not " )
532
535
let missingFile = missingParent. appending ( component: " exist " )
533
536
XCTAssertThrows ( FileSystemError ( . noEntry, missingFile) ) {
534
537
_ = try fs. readFileContents ( missingFile)
@@ -541,8 +544,8 @@ class FileSystemTests: XCTestCase {
541
544
542
545
func testInMemoryFsCopy( ) throws {
543
546
let fs = InMemoryFileSystem ( )
544
- try ! fs. createDirectory ( AbsolutePath ( " /new-dir/subdir " ) , recursive: true )
545
- let filePath = AbsolutePath ( " /new-dir/subdir " ) . appending ( component: " new-file.txt " )
547
+ try ! fs. createDirectory ( AbsolutePath . withPOSIX ( path : " /new-dir/subdir " ) , recursive: true )
548
+ let filePath = AbsolutePath . withPOSIX ( path : " /new-dir/subdir " ) . appending ( component: " new-file.txt " )
546
549
try ! fs. writeFileContents ( filePath, bytes: " Hello, world! " )
547
550
XCTAssertEqual ( try ! fs. readFileContents ( filePath) , " Hello, world! " )
548
551
@@ -561,7 +564,7 @@ class FileSystemTests: XCTestCase {
561
564
562
565
func testInMemCopyAndMoveItem( ) throws {
563
566
let fs = InMemoryFileSystem ( )
564
- let path = AbsolutePath ( " /tmp " )
567
+ let path = AbsolutePath . withPOSIX ( path : " /tmp " )
565
568
try fs. createDirectory ( path)
566
569
let source = path. appending ( component: " source " )
567
570
let destination = path. appending ( component: " destination " )
@@ -639,33 +642,33 @@ class FileSystemTests: XCTestCase {
639
642
func testRootedFileSystem( ) throws {
640
643
// Create the test file system.
641
644
let baseFileSystem = InMemoryFileSystem ( ) as FileSystem
642
- try baseFileSystem. createDirectory ( AbsolutePath ( " /base/rootIsHere/subdir " ) , recursive: true )
643
- try baseFileSystem. writeFileContents ( AbsolutePath ( " /base/rootIsHere/subdir/file " ) , bytes: " Hello, world! " )
645
+ try baseFileSystem. createDirectory ( AbsolutePath . withPOSIX ( path : " /base/rootIsHere/subdir " ) , recursive: true )
646
+ try baseFileSystem. writeFileContents ( AbsolutePath . withPOSIX ( path : " /base/rootIsHere/subdir/file " ) , bytes: " Hello, world! " )
644
647
645
648
// Create the rooted file system.
646
- let rerootedFileSystem = RerootedFileSystemView ( baseFileSystem, rootedAt: AbsolutePath ( " /base/rootIsHere " ) )
649
+ let rerootedFileSystem = RerootedFileSystemView ( baseFileSystem, rootedAt: AbsolutePath . withPOSIX ( path : " /base/rootIsHere " ) )
647
650
648
651
// Check that it has the appropriate view.
649
- XCTAssert ( rerootedFileSystem. exists ( AbsolutePath ( " /subdir " ) ) )
650
- XCTAssert ( rerootedFileSystem. isDirectory ( AbsolutePath ( " /subdir " ) ) )
651
- XCTAssert ( rerootedFileSystem. exists ( AbsolutePath ( " /subdir/file " ) ) )
652
- XCTAssertEqual ( try rerootedFileSystem. readFileContents ( AbsolutePath ( " /subdir/file " ) ) , " Hello, world! " )
652
+ XCTAssert ( rerootedFileSystem. exists ( AbsolutePath . withPOSIX ( path : " /subdir " ) ) )
653
+ XCTAssert ( rerootedFileSystem. isDirectory ( AbsolutePath . withPOSIX ( path : " /subdir " ) ) )
654
+ XCTAssert ( rerootedFileSystem. exists ( AbsolutePath . withPOSIX ( path : " /subdir/file " ) ) )
655
+ XCTAssertEqual ( try rerootedFileSystem. readFileContents ( AbsolutePath . withPOSIX ( path : " /subdir/file " ) ) , " Hello, world! " )
653
656
654
657
// Check that mutations work appropriately.
655
- XCTAssert ( !baseFileSystem. exists ( AbsolutePath ( " /base/rootIsHere/subdir2 " ) ) )
656
- try rerootedFileSystem. createDirectory ( AbsolutePath ( " /subdir2 " ) )
657
- XCTAssert ( baseFileSystem. isDirectory ( AbsolutePath ( " /base/rootIsHere/subdir2 " ) ) )
658
+ XCTAssert ( !baseFileSystem. exists ( AbsolutePath . withPOSIX ( path : " /base/rootIsHere/subdir2 " ) ) )
659
+ try rerootedFileSystem. createDirectory ( AbsolutePath . withPOSIX ( path : " /subdir2 " ) )
660
+ XCTAssert ( baseFileSystem. isDirectory ( AbsolutePath . withPOSIX ( path : " /base/rootIsHere/subdir2 " ) ) )
658
661
}
659
662
660
663
func testRootedCreateSymlink( ) throws {
661
664
// Create the test file system.
662
665
let baseFileSystem = InMemoryFileSystem ( ) as FileSystem
663
- try baseFileSystem. createDirectory ( AbsolutePath ( " /base/rootIsHere/subdir " ) , recursive: true )
666
+ try baseFileSystem. createDirectory ( AbsolutePath . withPOSIX ( path : " /base/rootIsHere/subdir " ) , recursive: true )
664
667
665
668
// Create the rooted file system.
666
- let fs = RerootedFileSystemView ( baseFileSystem, rootedAt: AbsolutePath ( " /base/rootIsHere " ) )
669
+ let fs = RerootedFileSystemView ( baseFileSystem, rootedAt: AbsolutePath . withPOSIX ( path : " /base/rootIsHere " ) )
667
670
668
- let path = AbsolutePath ( " /test " )
671
+ let path = AbsolutePath . withPOSIX ( path : " /test " )
669
672
try fs. createDirectory ( path, recursive: true )
670
673
671
674
let source = path. appending ( component: " source " )
@@ -750,7 +753,7 @@ class FileSystemTests: XCTestCase {
750
753
751
754
func testInMemoryFileSystemFileLock( ) throws {
752
755
let fs = InMemoryFileSystem ( )
753
- let path = AbsolutePath ( " / " )
756
+ let path = AbsolutePath . withPOSIX ( path : " / " )
754
757
try fs. createDirectory ( path)
755
758
756
759
let fileA = path. appending ( component: " fileA " )
@@ -772,11 +775,11 @@ class FileSystemTests: XCTestCase {
772
775
773
776
func testRerootedFileSystemViewFileLock( ) throws {
774
777
let inMemoryFS = InMemoryFileSystem ( )
775
- let rootPath = AbsolutePath ( " /tmp " )
778
+ let rootPath = AbsolutePath . withPOSIX ( path : " /tmp " )
776
779
try inMemoryFS. createDirectory ( rootPath)
777
780
778
781
let fs = RerootedFileSystemView ( inMemoryFS, rootedAt: rootPath)
779
- let path = AbsolutePath ( " / " )
782
+ let path = AbsolutePath . withPOSIX ( path : " / " )
780
783
try fs. createDirectory ( path)
781
784
782
785
let fileA = path. appending ( component: " fileA " )
0 commit comments