@@ -39,108 +39,108 @@ func testWithTemporaryDirectory(
3939struct  VFSTests  { 
4040    @Test  
4141    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 . writeFileContents ( file,  string:  " best " ) 
61- 
62-                     let  sym  =  tempDirPath. appending ( " hello " ) 
63-                     try . createSymbolicLink ( sym,  pointingAt:  file,  relative:  false ) 
64- 
65-                     let  executable  =  tempDirPath. appending ( " exec-foo " ) 
66-                     try . writeFileContents ( executable,  bytes:  ByteString ( contents) ) 
67-     #if !os(Windows) 
68-                     try . chmod ( . executable,  path:  executable,  options:  [ ] ) 
69-     #endif 
70- 
71-                     let  executableSym  =  tempDirPath. appending ( " exec-sym " ) 
72-                     try . createSymbolicLink ( executableSym,  pointingAt:  executable,  relative:  false ) 
73- 
74-                     try . createDirectory ( tempDirPath. appending ( " dir " ) ) 
75-                     try . 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 . 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 . 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 . 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 . 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 . getDirectoryContents ( AbsolutePath ( " / " ) ) 
126-                 #expect( dirContents. sorted ( )  ==  [ " best " ,  " dir " ,  " exec-foo " ,  " exec-sym " ,  " hello " ] ) 
127-                 #expect { try . 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 . 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 . getDirectoryContents ( AbsolutePath ( " /dir " ) ) 
137-                 #expect( contents ==  [ " file " ] ) 
138- 
139-                 let  fileContents  =  try . readFileContents ( AbsolutePath ( " /dir/file " ) ) 
140-                 #expect( fileContents ==  " " ) 
141-             } 
142-         }  when:  { 
143-             ProcessInfo . hostOperatingSystem ==  . windows
42+         // tiny PE binary from: https://archive.is/w01DO
43+         let  contents :  [ UInt8 ]  =  [ 
44+             0x4d ,  0x5a ,  0x00 ,  0x00 ,  0x50 ,  0x45 ,  0x00 ,  0x00 ,  0x4c ,  0x01 ,  0x01 ,  0x00 , 
45+             0x6a ,  0x2a ,  0x58 ,  0xc3 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 , 
46+             0x04 ,  0x00 ,  0x03 ,  0x01 ,  0x0b ,  0x01 ,  0x08 ,  0x00 ,  0x04 ,  0x00 ,  0x00 ,  0x00 , 
47+             0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x04 ,  0x00 ,  0x00 ,  0x00 ,  0x0c ,  0x00 ,  0x00 ,  0x00 , 
48+             0x04 ,  0x00 ,  0x00 ,  0x00 ,  0x0c ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x40 ,  0x00 , 
49+             0x04 ,  0x00 ,  0x00 ,  0x00 ,  0x04 ,  0x00 ,  0x00 ,  0x00 ,  0x04 ,  0x00 ,  0x00 ,  0x00 , 
50+             0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x04 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 , 
51+             0x68 ,  0x00 ,  0x00 ,  0x00 ,  0x64 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 ,  0x00 , 
52+             0x02 
53+         ] 
54+ 
55+         let  fs  =  localFileSystem
56+         let  vfsPath  =  try withTemporaryFile ( deleteOnClose:  true )  {  $0 } 
57+         try withTemporaryDirectory ( removeTreeOnDeinit:  true )  {  [ contents]  tempDirPath in 
58+             let  file  =  tempDirPath. appending ( " best " ) 
59+             try . writeFileContents ( file,  string:  " best " ) 
60+ 
61+             let  sym  =  tempDirPath. appending ( " hello " ) 
62+             try . createSymbolicLink ( sym,  pointingAt:  file,  relative:  false ) 
63+ 
64+             let  executable  =  tempDirPath. appending ( " exec-foo " ) 
65+             try . writeFileContents ( executable,  bytes:  ByteString ( contents) ) 
66+ #if !os(Windows) 
67+             try . chmod ( . executable,  path:  executable,  options:  [ ] ) 
68+ #endif 
69+ 
70+             let  executableSym  =  tempDirPath. appending ( " exec-sym " ) 
71+             try . createSymbolicLink ( executableSym,  pointingAt:  executable,  relative:  false ) 
72+ 
73+             try . createDirectory ( tempDirPath. appending ( " dir " ) ) 
74+             try . writeFileContents ( tempDirPath. appending ( components:  [ " dir " ,  " file " ] ) ,  bytes:  [ ] ) 
75+ 
76+ #if os(Windows) 
77+             // Cannot open the file again on windows
78+             try . fileHandle. close ( )      
79+ #endif        
80+             try VirtualFileSystem . serializeDirectoryTree ( tempDirPath,  into:  AbsolutePath ( vfsPath. path) ,  fs:  fs,  includeContents:  [ executable] ) 
14481        } 
82+ 
83+         let  vfs  =  try VirtualFileSystem ( path:  vfsPath. path,  fs:  fs) 
84+ 
85+         // exists()
86+         #expect( vfs. exists ( AbsolutePath ( " / " ) ) ) 
87+         #expect( !vfs. exists ( AbsolutePath ( " /does-not-exist " ) ) ) 
88+ 
89+         // isFile()
90+         let  filePath  =  AbsolutePath ( " /best " ) 
91+         #expect( vfs. exists ( filePath) ) 
92+         #expect( vfs. isFile ( filePath) ) 
93+         #expect( try . getFileInfo ( filePath) . fileType ==  . typeRegular) 
94+         #expect( !vfs. isDirectory ( filePath) ) 
95+         #expect( !vfs. isFile ( AbsolutePath ( " /does-not-exist " ) ) ) 
96+         #expect( !vfs. isSymlink ( AbsolutePath ( " /does-not-exist " ) ) ) 
97+         #expect( throws:  ( any  Error ) . self)  {  
98+             try . getFileInfo ( AbsolutePath ( " /does-not-exist " ) ) 
99+         } 
100+ 
101+         // isSymlink()
102+         let  symPath  =  AbsolutePath ( " /hello " ) 
103+         #expect( vfs. isSymlink ( symPath) ) 
104+         #expect( vfs. isFile ( symPath) ) 
105+         #expect( try . getFileInfo ( symPath) . fileType ==  . typeSymbolicLink) 
106+         #expect( !vfs. isDirectory ( symPath) ) 
107+ 
108+         // isExecutableFile
109+         let  executablePath  =  AbsolutePath ( " /exec-foo " ) 
110+         let  executableSymPath  =  AbsolutePath ( " /exec-sym " ) 
111+ #if !os(Windows) 
112+         #expect( vfs. isExecutableFile ( executablePath) ) 
113+         #expect( vfs. isExecutableFile ( executableSymPath) ) 
114+ #endif 
115+         #expect( vfs. isSymlink ( executableSymPath) ) 
116+         #expect( !vfs. isExecutableFile ( symPath) ) 
117+         #expect( !vfs. isExecutableFile ( filePath) ) 
118+         #expect( !vfs. isExecutableFile ( AbsolutePath ( " /does-not-exist " ) ) ) 
119+         #expect( !vfs. isExecutableFile ( AbsolutePath ( " / " ) ) ) 
120+         // readFileContents
121+         let  execFileContents  =  try . readFileContents ( executablePath) 
122+         #expect( execFileContents ==  ByteString ( contents) ) 
123+ 
124+         // isDirectory()
125+         #expect( vfs. isDirectory ( AbsolutePath ( " / " ) ) ) 
126+         #expect( !vfs. isDirectory ( AbsolutePath ( " /does-not-exist " ) ) ) 
127+ 
128+         // getDirectoryContents()
129+         let  dirContents  =  try . getDirectoryContents ( AbsolutePath ( " / " ) ) 
130+         #expect( dirContents. sorted ( )  ==  [ " best " ,  " dir " ,  " exec-foo " ,  " exec-sym " ,  " hello " ] ) 
131+         #expect { try . getDirectoryContents ( AbsolutePath ( " /does-not-exist " ) ) }  throws:  {  error in 
132+             ( error. localizedDescription ==  " no such file or directory:  \( AbsolutePath ( " /does-not-exist " ) ) " ) 
133+         } 
134+ 
135+         let  thisDirectoryContents  =  try . getDirectoryContents ( AbsolutePath ( " / " ) ) 
136+         #expect( !thisDirectoryContents. contains ( where:  {  $0 ==  " . "  } ) ) 
137+         #expect( !thisDirectoryContents. contains ( where:  {  $0 ==  " .. "  } ) ) 
138+         #expect( thisDirectoryContents. sorted ( )  ==  [ " best " ,  " dir " ,  " exec-foo " ,  " exec-sym " ,  " hello " ] ) 
139+ 
140+         let  _contents  =  try . getDirectoryContents ( AbsolutePath ( " /dir " ) ) 
141+         #expect( _contents ==  [ " file " ] ) 
142+ 
143+         let  fileContents  =  try . readFileContents ( AbsolutePath ( " /dir/file " ) ) 
144+         #expect( fileContents ==  " " ) 
145145    } 
146146} 
0 commit comments