Skip to content

Commit 1b8c1ea

Browse files
authored
Fix up tests for Windows (#5074)
* Disable crashing URLSession test * Fix URL test failures * Fix TestProcessInfo failures * Fix a bundle test * Fix Process tests * Fix FileManager failures * Fix linking failure * Disable failing FileManager test * Disable crashing Thread tests
1 parent a39f398 commit 1b8c1ea

10 files changed

+136
-122
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if let environmentPath = Context.environment["ZLIB_LIBRARY_PATH"] {
7474
var libxmlLinkFlags: [LinkerSetting] = [
7575
.linkedLibrary("libxml2s.lib", .when(platforms: [.windows]))
7676
]
77-
if let environmentPath = Context.environment["LIBXML2_LIBRARY_PATH"] {
77+
if let environmentPath = Context.environment["LIBXML_LIBRARY_PATH"] {
7878
libxmlLinkFlags.append(.unsafeFlags([
7979
"-L\(environmentPath)"
8080
]))

Sources/Foundation/NSPathUtilities.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ let validPathSeps: [Character] = ["/"]
2121
#endif
2222

2323
public func NSTemporaryDirectory() -> String {
24-
FileManager.default.temporaryDirectory.path()
24+
FileManager.default.temporaryDirectory.withUnsafeFileSystemRepresentation {
25+
String(cString: $0!)
26+
} + String(validPathSeps[0])
2527
}
2628

2729
extension String {
@@ -614,12 +616,16 @@ public func NSSearchPathForDirectoriesInDomains(_ directory: FileManager.SearchP
614616
}
615617

616618
public func NSHomeDirectory() -> String {
617-
FileManager.default.homeDirectoryForCurrentUser.path
619+
FileManager.default.homeDirectoryForCurrentUser.withUnsafeFileSystemRepresentation {
620+
String(cString: $0!)
621+
}
618622
}
619623

620624
public func NSHomeDirectoryForUser(_ user: String?) -> String? {
621625
guard let user else { return NSHomeDirectory() }
622-
return FileManager.default.homeDirectory(forUser: user)?.path
626+
return FileManager.default.homeDirectory(forUser: user)?.withUnsafeFileSystemRepresentation {
627+
String(cString: $0!)
628+
}
623629
}
624630

625631
public func NSUserName() -> String {

Tests/Foundation/TestBundle.swift

+20-6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ class BundlePlayground {
7878
#endif
7979
}
8080
}
81+
82+
var fileNameSuffix: String? {
83+
#if os(Windows) && DEBUG
84+
"_debug"
85+
#else
86+
nil
87+
#endif
88+
}
8189

8290
var flatPathExtension: String? {
8391
#if os(Windows)
@@ -216,7 +224,7 @@ class BundlePlayground {
216224

217225
// Make a main and an auxiliary executable:
218226
self.mainExecutableURL = bundleURL
219-
.appendingPathComponent(bundleName)
227+
.appendingPathComponent(bundleName + (executableType.fileNameSuffix ?? ""))
220228

221229
if let ext = executableType.flatPathExtension {
222230
self.mainExecutableURL.appendPathExtension(ext)
@@ -227,7 +235,7 @@ class BundlePlayground {
227235
}
228236

229237
var auxiliaryExecutableURL = bundleURL
230-
.appendingPathComponent(auxiliaryExecutableName)
238+
.appendingPathComponent(auxiliaryExecutableName + (executableType.fileNameSuffix ?? ""))
231239

232240
if let ext = executableType.flatPathExtension {
233241
auxiliaryExecutableURL.appendPathExtension(ext)
@@ -270,7 +278,7 @@ class BundlePlayground {
270278
// Make a main and an auxiliary executable:
271279
self.mainExecutableURL = temporaryDirectory
272280
.appendingPathComponent(executableType.fhsPrefix)
273-
.appendingPathComponent(executableType.nonFlatFilePrefix + bundleName)
281+
.appendingPathComponent(executableType.nonFlatFilePrefix + bundleName + (executableType.fileNameSuffix ?? ""))
274282

275283
if let ext = executableType.pathExtension {
276284
self.mainExecutableURL.appendPathExtension(ext)
@@ -280,7 +288,7 @@ class BundlePlayground {
280288
let executablesDirectory = temporaryDirectory.appendingPathComponent("libexec").appendingPathComponent("\(bundleName).executables")
281289
try FileManager.default.createDirectory(atPath: executablesDirectory.path, withIntermediateDirectories: true, attributes: nil)
282290
var auxiliaryExecutableURL = executablesDirectory
283-
.appendingPathComponent(executableType.nonFlatFilePrefix + auxiliaryExecutableName)
291+
.appendingPathComponent(executableType.nonFlatFilePrefix + auxiliaryExecutableName + (executableType.fileNameSuffix ?? ""))
284292

285293
if let ext = executableType.pathExtension {
286294
auxiliaryExecutableURL.appendPathExtension(ext)
@@ -317,7 +325,7 @@ class BundlePlayground {
317325

318326
// Make a main executable:
319327
self.mainExecutableURL = temporaryDirectory
320-
.appendingPathComponent(executableType.nonFlatFilePrefix + bundleName)
328+
.appendingPathComponent(executableType.nonFlatFilePrefix + bundleName + (executableType.fileNameSuffix ?? ""))
321329

322330
if let ext = executableType.pathExtension {
323331
self.mainExecutableURL.appendPathExtension(ext)
@@ -330,7 +338,7 @@ class BundlePlayground {
330338

331339
// Make an auxiliary executable:
332340
var auxiliaryExecutableURL = resourcesDirectory
333-
.appendingPathComponent(executableType.nonFlatFilePrefix + auxiliaryExecutableName)
341+
.appendingPathComponent(executableType.nonFlatFilePrefix + auxiliaryExecutableName + (executableType.fileNameSuffix ?? ""))
334342
if let ext = executableType.pathExtension {
335343
auxiliaryExecutableURL.appendPathExtension(ext)
336344
}
@@ -516,11 +524,14 @@ class TestBundle : XCTestCase {
516524
XCTFail("should not fail to load")
517525
}
518526

527+
// This causes a dialog box to appear on Windows which will suspend the tests, so skip testing this on Windows for now
528+
#if !os(Windows)
519529
// Executable cannot be located
520530
try! _withEachPlaygroundLayout { (playground) in
521531
let bundle = Bundle(path: playground.bundlePath)
522532
XCTAssertThrowsError(try bundle!.loadAndReturnError())
523533
}
534+
#endif
524535
}
525536

526537
func test_bundleWithInvalidPath() {
@@ -531,12 +542,15 @@ class TestBundle : XCTestCase {
531542
func test_bundlePreflight() {
532543
XCTAssertNoThrow(try testBundle(executable: true).preflight())
533544

545+
// Windows DLL bundles are always executable
546+
#if !os(Windows)
534547
try! _withEachPlaygroundLayout { (playground) in
535548
let bundle = Bundle(path: playground.bundlePath)!
536549

537550
// Must throw as the main executable is a dummy empty file.
538551
XCTAssertThrowsError(try bundle.preflight())
539552
}
553+
#endif
540554
}
541555

542556
func test_bundleFindExecutable() {

0 commit comments

Comments
 (0)