Skip to content

Commit e07ce99

Browse files
Fix remaining Windows test issues (#104)
testPlatformOptionsCreateNewConsole: this test was meaning to assert that the values are different, not that they're the same. Fix this simple logic issue. testRunDetached: this test never completed reading the output, because the write fd was kept open and reading never completed. Close the write fd before reading. testInputSequenceCustomExecutionBody, testInputAsyncSequenceCustomExecutionBody, testRedirectedOutputRedirectToSequence: these tests hit an implementation issue where EOF was not correctly detected, leading to a hang. Change the logic to return nil if an empty buffer is received. This patch also enables CI tests for Windows.
1 parent f848a4c commit e07ce99

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

.github/workflows/pull_request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
dnf install -y procps
2525
fi
2626
windows_swift_versions: '["6.1", "nightly-main"]'
27-
windows_build_command: 'swift build'
2827
enable_macos_checks: true
2928
macos_xcode_versions: '["16.3"]'
3029

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
var dep: [Package.Dependency] = [
77
.package(
88
url: "https://github.com/apple/swift-system",
9-
from: "1.4.2"
9+
from: "1.5.0"
1010
)
1111
]
1212
#if !os(Windows)

Sources/Subprocess/Platforms/Subprocess+Windows.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ extension FileDescriptor {
10141014
case .failure(let error):
10151015
continuation.resume(throwing: error)
10161016
case .success(let bytes):
1017-
continuation.resume(returning: bytes)
1017+
continuation.resume(returning: bytes.isEmpty ? nil : bytes)
10181018
}
10191019
}
10201020
}

Tests/SubprocessTests/SubprocessTests+Windows.swift

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,34 @@ extension SubprocessWindowsTests {
476476
platformOptions: platformOptions,
477477
output: .string
478478
)
479-
#expect(whoamiResult.terminationStatus.isSuccess)
480-
let result = try #require(
481-
whoamiResult.standardOutput
482-
).trimmingCharacters(in: .whitespacesAndNewlines)
483-
// whoami returns `computerName\userName`.
484-
let userInfo = result.split(separator: "\\")
485-
guard userInfo.count == 2 else {
486-
Issue.record("Fail to parse the result for whoami: \(result)")
487-
return
479+
480+
try await withKnownIssue {
481+
#expect(whoamiResult.terminationStatus.isSuccess)
482+
let result = try #require(
483+
whoamiResult.standardOutput
484+
).trimmingCharacters(in: .whitespacesAndNewlines)
485+
// whoami returns `computerName\userName`.
486+
let userInfo = result.split(separator: "\\")
487+
guard userInfo.count == 2 else {
488+
Issue.record("Fail to parse the result for whoami: \(result)")
489+
return
490+
}
491+
#expect(
492+
userInfo[1].lowercased() == username.lowercased()
493+
)
494+
} when: {
495+
func userName() -> String {
496+
var capacity = UNLEN + 1
497+
let pointer = UnsafeMutablePointer<UTF16.CodeUnit>.allocate(capacity: Int(capacity))
498+
defer { pointer.deallocate() }
499+
guard GetUserNameW(pointer, &capacity) else {
500+
return ""
501+
}
502+
return String(decodingCString: pointer, as: UTF16.self)
503+
}
504+
// CreateProcessWithLogonW doesn't appear to work when running in a container
505+
return whoamiResult.terminationStatus == .unhandledException(STATUS_DLL_INIT_FAILED) && userName() == "ContainerAdministrator"
488506
}
489-
#expect(
490-
userInfo[1].lowercased() == username.lowercased()
491-
)
492507
}
493508
}
494509

@@ -528,7 +543,7 @@ extension SubprocessWindowsTests {
528543
).trimmingCharacters(in: .whitespacesAndNewlines)
529544
// Make sure the child console is different from parent
530545
#expect(
531-
"\(intptr_t(bitPattern: parentConsole))" == differentConsoleValue
546+
"\(intptr_t(bitPattern: parentConsole))" != differentConsoleValue
532547
)
533548
}
534549

@@ -707,13 +722,13 @@ extension SubprocessWindowsTests {
707722
WaitForSingleObject(processHandle, INFINITE)
708723

709724
// Up to 10 characters because Windows process IDs are DWORDs (UInt32), whose max value is 10 digits.
725+
try writeFd.close()
710726
let data = try await readFd.readUntilEOF(upToLength: 10)
711727
let resultPID = try #require(
712728
String(data: data, encoding: .utf8)
713729
).trimmingCharacters(in: .whitespacesAndNewlines)
714730
#expect("\(pid.value)" == resultPID)
715731
try readFd.close()
716-
try writeFd.close()
717732
}
718733
}
719734

0 commit comments

Comments
 (0)