@@ -77,6 +77,9 @@ class TestURL : XCTestCase {
77
77
#elseif os(Linux)
78
78
let baseURL = URL ( fileURLWithPath: " /usr " , isDirectory: true )
79
79
let relativePath = " include "
80
+ #elseif os(Windows)
81
+ let baseURL = URL ( fileURLWithPath: homeDirectory, isDirectory: true )
82
+ let relativePath = " Documents "
80
83
#endif
81
84
// we're telling fileURLWithPath:isDirectory:relativeTo: Documents is a directory
82
85
let url1 = URL ( fileURLWithFileSystemRepresentation: relativePath, isDirectory: true , relativeTo: baseURL)
@@ -224,10 +227,7 @@ class TestURL : XCTestCase {
224
227
225
228
static let gBaseTemporaryDirectoryPath = NSTemporaryDirectory ( )
226
229
static var gBaseCurrentWorkingDirectoryPath : String {
227
- let count = Int ( 1024 ) // MAXPATHLEN is platform specific; this is the lowest common denominator for darwin and most linuxes
228
- var buf : [ Int8 ] = Array ( repeating: 0 , count: count)
229
- getcwd ( & buf, count)
230
- return String ( cString: buf)
230
+ return FileManager . default. currentDirectoryPath
231
231
}
232
232
static var gRelativeOffsetFromBaseCurrentWorkingDirectory : UInt = 0
233
233
static let gFileExistsName = " TestCFURL_file_exists \( ProcessInfo . processInfo. globallyUniqueString) "
@@ -240,21 +240,37 @@ class TestURL : XCTestCase {
240
240
static let gDirectoryDoesNotExistPath = gBaseTemporaryDirectoryPath + gDirectoryDoesNotExistName
241
241
242
242
static func setup_test_paths( ) -> Bool {
243
- if creat ( gFileExistsPath, S_IRWXU) < 0 && errno != EEXIST {
244
- return false
245
- }
246
- if unlink ( gFileDoesNotExistPath) != 0 && errno != ENOENT {
243
+ _ = FileManager . default. createFile ( atPath: gFileExistsPath, contents: nil )
244
+
245
+ do {
246
+ try FileManager . default. removeItem ( atPath: gFileDoesNotExistPath)
247
+ } catch let error as NSError {
248
+ // The error code is a CocoaError
249
+ if error. code != CocoaError . fileNoSuchFile. rawValue {
247
250
return false
251
+ }
248
252
}
249
- if mkdir ( gDirectoryExistsPath, S_IRWXU) != 0 && errno != EEXIST {
253
+
254
+ do {
255
+ try FileManager . default. createDirectory ( atPath: gDirectoryExistsPath, withIntermediateDirectories: false )
256
+ } catch let error as NSError {
257
+ // The error code is a CocoaError
258
+ if error. code != CocoaError . fileWriteFileExists. rawValue {
250
259
return false
260
+ }
251
261
}
252
- if rmdir ( gDirectoryDoesNotExistPath) != 0 && errno != ENOENT {
262
+
263
+ do {
264
+ try FileManager . default. removeItem ( atPath: gDirectoryDoesNotExistPath)
265
+ } catch let error as NSError {
266
+ // The error code is a CocoaError
267
+ if error. code != CocoaError . fileNoSuchFile. rawValue {
253
268
return false
269
+ }
254
270
}
255
-
271
+
256
272
#if os(Android)
257
- chdir ( " /data/local/tmp " )
273
+ FileManager . default . changeCurrentDirectoryPath ( " /data/local/tmp " )
258
274
#endif
259
275
260
276
let cwd = FileManager . default. currentDirectoryPath
@@ -263,8 +279,7 @@ class TestURL : XCTestCase {
263
279
cwdURL. withUnsafeFileSystemRepresentation {
264
280
gRelativeOffsetFromBaseCurrentWorkingDirectory = UInt ( strlen ( $0!) + 1 )
265
281
}
266
-
267
-
282
+
268
283
return true
269
284
}
270
285
0 commit comments