Skip to content

Commit a79623a

Browse files
committed
Fix process handle leak on Windows
- Add a missing CloseHandle as part of the process termination handling - Enable Process tests on Windows
1 parent 94ef6ab commit a79623a

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ let package = Package(
349349
"FoundationNetworking",
350350
"XCTest",
351351
"Testing",
352-
.target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android]))
352+
.target(name: "xdgTestHelper", condition: .when(platforms: [.linux, .android, .windows]))
353353
],
354354
resources: [
355355
.copy("Foundation/Resources")

Sources/Foundation/Process.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ open class Process: NSObject, @unchecked Sendable {
653653
process._terminationReason = .exit
654654
}
655655

656+
CloseHandle(process.processHandle)
656657
// Signal waitUntilExit() and optionally invoke termination handler.
657658
process.terminateRunLoop()
658659

Tests/Foundation/TestBundle.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,7 @@ internal func testBundleName() -> String {
4343
}
4444

4545
internal func xdgTestHelperURL() throws -> URL {
46-
#if os(Windows)
47-
// Adding the xdgTestHelper as a dependency of TestFoundation causes its object files (including the main function) to be linked into the test runner executable as well
48-
// While this works on Linux due to special linker functionality, this doesn't work on Windows and results in a collision between the two main symbols
49-
// SwiftPM also cannot support depending on this executable (to ensure it is built) without also linking its objects into the test runner
50-
// For those reasons, using the xdgTestHelper on Windows is currently unsupported and tests that rely on it must be skipped
51-
throw XCTSkip("xdgTestHelper is not supported during testing on Windows (test executables are not supported by SwiftPM on Windows)")
52-
#else
5346
testBundle().bundleURL.deletingLastPathComponent().appendingPathComponent("xdgTestHelper")
54-
#endif
5547
}
5648

5749

Tests/Foundation/TestFileManager.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,9 @@ class TestFileManager : XCTestCase {
12351235
}
12361236

12371237
func test_fetchXDGPathsFromHelper() throws {
1238+
#if os(Windows)
1239+
throw XCTSkip("This test is disabled on Windows, needs investigation.")
1240+
#endif
12381241
let prefix = NSHomeDirectory() + "/_Foundation_Test_"
12391242

12401243
let configuration = """

0 commit comments

Comments
 (0)