@@ -183,6 +183,74 @@ class FileSystemTests: XCTestCase {
183183 }
184184 }
185185
186+ func testLocalReadableWritable( ) throws {
187+ try testWithTemporaryDirectory { tmpdir in
188+ let fs = localFileSystem
189+
190+ // directory
191+
192+ do {
193+ let directory = tmpdir. appending ( component: " directory " )
194+ try fs. createDirectory ( directory, recursive: true )
195+
196+ // should be readable and writable by default
197+ XCTAssertTrue ( fs. isReadable ( directory) )
198+ XCTAssertTrue ( fs. isWritable ( directory) )
199+
200+ // set to non-readable non-writable.
201+ _ = try Process . popen ( args: " chmod " , " -r-w " , directory. pathString)
202+ XCTAssertFalse ( fs. isReadable ( directory) )
203+ XCTAssertFalse ( fs. isWritable ( directory) )
204+
205+ // set to readable non-writable.
206+ _ = try Process . popen ( args: " chmod " , " +r-w " , directory. pathString)
207+ XCTAssertTrue ( fs. isReadable ( directory) )
208+ XCTAssertFalse ( fs. isWritable ( directory) )
209+
210+ // set to non-readable writable.
211+ _ = try Process . popen ( args: " chmod " , " -r+w " , directory. pathString)
212+ XCTAssertFalse ( fs. isReadable ( directory) )
213+ XCTAssertTrue ( fs. isWritable ( directory) )
214+
215+ // set to readable and writable.
216+ _ = try Process . popen ( args: " chmod " , " +r+w " , directory. pathString)
217+ XCTAssertTrue ( fs. isReadable ( directory) )
218+ XCTAssertTrue ( fs. isWritable ( directory) )
219+ }
220+
221+ // file
222+
223+ do {
224+ let file = tmpdir. appending ( component: " file " )
225+ try fs. writeFileContents ( file, bytes: " " )
226+
227+ // should be readable and writable by default
228+ XCTAssertTrue ( fs. isReadable ( file) )
229+ XCTAssertTrue ( fs. isWritable ( file) )
230+
231+ // set to non-readable non-writable.
232+ _ = try Process . popen ( args: " chmod " , " -r-w " , file. pathString)
233+ XCTAssertFalse ( fs. isReadable ( file) )
234+ XCTAssertFalse ( fs. isWritable ( file) )
235+
236+ // set to readable non-writable.
237+ _ = try Process . popen ( args: " chmod " , " +r-w " , file. pathString)
238+ XCTAssertTrue ( fs. isReadable ( file) )
239+ XCTAssertFalse ( fs. isWritable ( file) )
240+
241+ // set to non-readable writable.
242+ _ = try Process . popen ( args: " chmod " , " -r+w " , file. pathString)
243+ XCTAssertFalse ( fs. isReadable ( file) )
244+ XCTAssertTrue ( fs. isWritable ( file) )
245+
246+ // set to readable and writable.
247+ _ = try Process . popen ( args: " chmod " , " +r+w " , file. pathString)
248+ XCTAssertTrue ( fs. isReadable ( file) )
249+ XCTAssertTrue ( fs. isWritable ( file) )
250+ }
251+ }
252+ }
253+
186254 func testLocalCreateDirectory( ) throws {
187255 let fs = TSCBasic . localFileSystem
188256
0 commit comments