@@ -37,110 +37,114 @@ func testWithTemporaryDirectory(
3737
3838
3939struct VFSTests {
40- @Test
40+ @Test (
41+ . issue( " https://github.com/swiftlang/swift-package-manager/issues/9310 " , relationship: . defect) ,
42+ . skipHostOS( . windows, " Test currently fails with: you don't have permissions. " ) ,
43+ . tags(
44+ . TestSize. medium,
45+ . Platform. FileSystem,
46+ . UserWorkflow,
47+ )
48+ )
4149 func localBasics( ) throws {
42- try withKnownIssue ( " Permission issues on Windows " ) {
43- // tiny PE binary from: https://archive.is/w01DO
44- let contents : [ UInt8 ] = [
45- 0x4d , 0x5a , 0x00 , 0x00 , 0x50 , 0x45 , 0x00 , 0x00 , 0x4c , 0x01 , 0x01 , 0x00 ,
46- 0x6a , 0x2a , 0x58 , 0xc3 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
47- 0x04 , 0x00 , 0x03 , 0x01 , 0x0b , 0x01 , 0x08 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
48- 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x0c , 0x00 , 0x00 , 0x00 ,
49- 0x04 , 0x00 , 0x00 , 0x00 , 0x0c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
50- 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
51- 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
52- 0x68 , 0x00 , 0x00 , 0x00 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
53- 0x02
54- ]
55-
56- let fs = localFileSystem
57- try withTemporaryFile { [ contents] vfsPath in
58- try withTemporaryDirectory ( removeTreeOnDeinit: true ) { [ contents] tempDirPath in
59- let file = tempDirPath. appending ( " best " )
60- try fs. writeFileContents ( file, string: " best " )
61-
62- let sym = tempDirPath. appending ( " hello " )
63- try fs. createSymbolicLink ( sym, pointingAt: file, relative: false )
64-
65- let executable = tempDirPath. appending ( " exec-foo " )
66- try fs. writeFileContents ( executable, bytes: ByteString ( contents) )
67- #if !os(Windows)
68- try fs. chmod ( . executable, path: executable, options: [ ] )
69- #endif
70-
71- let executableSym = tempDirPath. appending ( " exec-sym " )
72- try fs. createSymbolicLink ( executableSym, pointingAt: executable, relative: false )
73-
74- try fs. createDirectory ( tempDirPath. appending ( " dir " ) )
75- try fs. writeFileContents ( tempDirPath. appending ( components: [ " dir " , " file " ] ) , bytes: [ ] )
76-
77- try VirtualFileSystem . serializeDirectoryTree ( tempDirPath, into: AbsolutePath ( vfsPath. path) , fs: fs, includeContents: [ executable] )
78- }
79-
80- let vfs = try VirtualFileSystem ( path: vfsPath. path, fs: fs)
81-
82- // exists()
83- #expect( vfs. exists ( AbsolutePath ( " / " ) ) )
84- #expect( !vfs. exists ( AbsolutePath ( " /does-not-exist " ) ) )
85-
86- // isFile()
87- let filePath = AbsolutePath ( " /best " )
88- #expect( vfs. exists ( filePath) )
89- #expect( vfs. isFile ( filePath) )
90- #expect( try vfs. getFileInfo ( filePath) . fileType == . typeRegular)
91- #expect( !vfs. isDirectory ( filePath) )
92- #expect( !vfs. isFile ( AbsolutePath ( " /does-not-exist " ) ) )
93- #expect( !vfs. isSymlink ( AbsolutePath ( " /does-not-exist " ) ) )
94- #expect( throws: ( any Error ) . self) {
95- try vfs. getFileInfo ( AbsolutePath ( " /does-not-exist " ) )
96- }
97-
98- // isSymlink()
99- let symPath = AbsolutePath ( " /hello " )
100- #expect( vfs. isSymlink ( symPath) )
101- #expect( vfs. isFile ( symPath) )
102- #expect( try vfs. getFileInfo ( symPath) . fileType == . typeSymbolicLink)
103- #expect( !vfs. isDirectory ( symPath) )
104-
105- // isExecutableFile
106- let executablePath = AbsolutePath ( " /exec-foo " )
107- let executableSymPath = AbsolutePath ( " /exec-sym " )
108- #expect( vfs. isExecutableFile ( executablePath) )
109- #expect( vfs. isExecutableFile ( executableSymPath) )
110- #expect( vfs. isSymlink ( executableSymPath) )
111- #expect( !vfs. isExecutableFile ( symPath) )
112- #expect( !vfs. isExecutableFile ( filePath) )
113- #expect( !vfs. isExecutableFile ( AbsolutePath ( " /does-not-exist " ) ) )
114- #expect( !vfs. isExecutableFile ( AbsolutePath ( " / " ) ) )
115-
116- // readFileContents
117- let execFileContents = try vfs. readFileContents ( executablePath)
118- #expect( execFileContents == ByteString ( contents) )
119-
120- // isDirectory()
121- #expect( vfs. isDirectory ( AbsolutePath ( " / " ) ) )
122- #expect( !vfs. isDirectory ( AbsolutePath ( " /does-not-exist " ) ) )
123-
124- // getDirectoryContents()
125- let dirContents = try vfs. getDirectoryContents ( AbsolutePath ( " / " ) )
126- #expect( dirContents. sorted ( ) == [ " best " , " dir " , " exec-foo " , " exec-sym " , " hello " ] )
127- #expect { try vfs. getDirectoryContents ( AbsolutePath ( " /does-not-exist " ) ) } throws: { error in
128- ( error. localizedDescription == " no such file or directory: \( AbsolutePath ( " /does-not-exist " ) ) " )
129- }
130-
131- let thisDirectoryContents = try vfs. getDirectoryContents ( AbsolutePath ( " / " ) )
132- #expect( !thisDirectoryContents. contains ( where: { $0 == " . " } ) )
133- #expect( !thisDirectoryContents. contains ( where: { $0 == " .. " } ) )
134- #expect( thisDirectoryContents. sorted ( ) == [ " best " , " dir " , " exec-foo " , " exec-sym " , " hello " ] )
135-
136- let contents = try vfs. getDirectoryContents ( AbsolutePath ( " /dir " ) )
137- #expect( contents == [ " file " ] )
138-
139- let fileContents = try vfs. readFileContents ( AbsolutePath ( " /dir/file " ) )
140- #expect( fileContents == " " )
50+ // tiny PE binary from: https://archive.is/w01DO
51+ let contents : [ UInt8 ] = [
52+ 0x4d , 0x5a , 0x00 , 0x00 , 0x50 , 0x45 , 0x00 , 0x00 , 0x4c , 0x01 , 0x01 , 0x00 ,
53+ 0x6a , 0x2a , 0x58 , 0xc3 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
54+ 0x04 , 0x00 , 0x03 , 0x01 , 0x0b , 0x01 , 0x08 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
55+ 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x0c , 0x00 , 0x00 , 0x00 ,
56+ 0x04 , 0x00 , 0x00 , 0x00 , 0x0c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
57+ 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
58+ 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
59+ 0x68 , 0x00 , 0x00 , 0x00 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
60+ 0x02
61+ ]
62+
63+ let fs = localFileSystem
64+ try withTemporaryFile { [ contents] vfsPath in
65+ try withTemporaryDirectory ( removeTreeOnDeinit: true ) { [ contents] tempDirPath in
66+ let file = tempDirPath. appending ( " best " )
67+ try fs. writeFileContents ( file, string: " best " )
68+
69+ let sym = tempDirPath. appending ( " hello " )
70+ try fs. createSymbolicLink ( sym, pointingAt: file, relative: false )
71+
72+ let executable = tempDirPath. appending ( " exec-foo " )
73+ try fs. writeFileContents ( executable, bytes: ByteString ( contents) )
74+ #if !os(Windows)
75+ try fs. chmod ( . executable, path: executable, options: [ ] )
76+ #endif
77+
78+ let executableSym = tempDirPath. appending ( " exec-sym " )
79+ try fs. createSymbolicLink ( executableSym, pointingAt: executable, relative: false )
80+
81+ try fs. createDirectory ( tempDirPath. appending ( " dir " ) )
82+ try fs. writeFileContents ( tempDirPath. appending ( components: [ " dir " , " file " ] ) , bytes: [ ] )
83+
84+ try VirtualFileSystem . serializeDirectoryTree ( tempDirPath, into: AbsolutePath ( vfsPath. path) , fs: fs, includeContents: [ executable] )
14185 }
142- } when: {
143- ProcessInfo . hostOperatingSystem == . windows
86+
87+ let vfs = try VirtualFileSystem ( path: vfsPath. path, fs: fs)
88+
89+ // exists()
90+ #expect( vfs. exists ( AbsolutePath ( " / " ) ) )
91+ #expect( !vfs. exists ( AbsolutePath ( " /does-not-exist " ) ) )
92+
93+ // isFile()
94+ let filePath = AbsolutePath ( " /best " )
95+ #expect( vfs. exists ( filePath) )
96+ #expect( vfs. isFile ( filePath) )
97+ #expect( try vfs. getFileInfo ( filePath) . fileType == . typeRegular)
98+ #expect( !vfs. isDirectory ( filePath) )
99+ #expect( !vfs. isFile ( AbsolutePath ( " /does-not-exist " ) ) )
100+ #expect( !vfs. isSymlink ( AbsolutePath ( " /does-not-exist " ) ) )
101+ #expect( throws: ( any Error ) . self) {
102+ try vfs. getFileInfo ( AbsolutePath ( " /does-not-exist " ) )
103+ }
104+
105+ // isSymlink()
106+ let symPath = AbsolutePath ( " /hello " )
107+ #expect( vfs. isSymlink ( symPath) )
108+ #expect( vfs. isFile ( symPath) )
109+ #expect( try vfs. getFileInfo ( symPath) . fileType == . typeSymbolicLink)
110+ #expect( !vfs. isDirectory ( symPath) )
111+
112+ // isExecutableFile
113+ let executablePath = AbsolutePath ( " /exec-foo " )
114+ let executableSymPath = AbsolutePath ( " /exec-sym " )
115+ #expect( vfs. isExecutableFile ( executablePath) )
116+ #expect( vfs. isExecutableFile ( executableSymPath) )
117+ #expect( vfs. isSymlink ( executableSymPath) )
118+ #expect( !vfs. isExecutableFile ( symPath) )
119+ #expect( !vfs. isExecutableFile ( filePath) )
120+ #expect( !vfs. isExecutableFile ( AbsolutePath ( " /does-not-exist " ) ) )
121+ #expect( !vfs. isExecutableFile ( AbsolutePath ( " / " ) ) )
122+
123+ // readFileContents
124+ let execFileContents = try vfs. readFileContents ( executablePath)
125+ #expect( execFileContents == ByteString ( contents) )
126+
127+ // isDirectory()
128+ #expect( vfs. isDirectory ( AbsolutePath ( " / " ) ) )
129+ #expect( !vfs. isDirectory ( AbsolutePath ( " /does-not-exist " ) ) )
130+
131+ // getDirectoryContents()
132+ let dirContents = try vfs. getDirectoryContents ( AbsolutePath ( " / " ) )
133+ #expect( dirContents. sorted ( ) == [ " best " , " dir " , " exec-foo " , " exec-sym " , " hello " ] )
134+ #expect { try vfs. getDirectoryContents ( AbsolutePath ( " /does-not-exist " ) ) } throws: { error in
135+ ( error. localizedDescription == " no such file or directory: \( AbsolutePath ( " /does-not-exist " ) ) " )
136+ }
137+
138+ let thisDirectoryContents = try vfs. getDirectoryContents ( AbsolutePath ( " / " ) )
139+ #expect( !thisDirectoryContents. contains ( where: { $0 == " . " } ) )
140+ #expect( !thisDirectoryContents. contains ( where: { $0 == " .. " } ) )
141+ #expect( thisDirectoryContents. sorted ( ) == [ " best " , " dir " , " exec-foo " , " exec-sym " , " hello " ] )
142+
143+ let contents = try vfs. getDirectoryContents ( AbsolutePath ( " /dir " ) )
144+ #expect( contents == [ " file " ] )
145+
146+ let fileContents = try vfs. readFileContents ( AbsolutePath ( " /dir/file " ) )
147+ #expect( fileContents == " " )
144148 }
145149 }
146150}
0 commit comments