Skip to content

Fix remaining Windows test issues #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
dnf install -y procps
fi
windows_swift_versions: '["6.1", "nightly-main"]'
windows_build_command: 'swift build'
enable_macos_checks: true
macos_xcode_versions: '["16.3"]'

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
var dep: [Package.Dependency] = [
.package(
url: "https://github.com/apple/swift-system",
from: "1.4.2"
from: "1.5.0"
)
]
#if !os(Windows)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Subprocess/Platforms/Subprocess+Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ extension FileDescriptor {
case .failure(let error):
continuation.resume(throwing: error)
case .success(let bytes):
continuation.resume(returning: bytes)
continuation.resume(returning: bytes.isEmpty ? nil : bytes)
}
}
}
Expand Down
43 changes: 29 additions & 14 deletions Tests/SubprocessTests/SubprocessTests+Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -476,19 +476,34 @@ extension SubprocessWindowsTests {
platformOptions: platformOptions,
output: .string
)
#expect(whoamiResult.terminationStatus.isSuccess)
let result = try #require(
whoamiResult.standardOutput
).trimmingCharacters(in: .whitespacesAndNewlines)
// whoami returns `computerName\userName`.
let userInfo = result.split(separator: "\\")
guard userInfo.count == 2 else {
Issue.record("Fail to parse the result for whoami: \(result)")
return

try await withKnownIssue {
#expect(whoamiResult.terminationStatus.isSuccess)
let result = try #require(
whoamiResult.standardOutput
).trimmingCharacters(in: .whitespacesAndNewlines)
// whoami returns `computerName\userName`.
let userInfo = result.split(separator: "\\")
guard userInfo.count == 2 else {
Issue.record("Fail to parse the result for whoami: \(result)")
return
}
#expect(
userInfo[1].lowercased() == username.lowercased()
)
} when: {
func userName() -> String {
var capacity = UNLEN + 1
let pointer = UnsafeMutablePointer<UTF16.CodeUnit>.allocate(capacity: Int(capacity))
defer { pointer.deallocate() }
guard GetUserNameW(pointer, &capacity) else {
return ""
}
return String(decodingCString: pointer, as: UTF16.self)
}
// CreateProcessWithLogonW doesn't appear to work when running in a container
return whoamiResult.terminationStatus == .unhandledException(STATUS_DLL_INIT_FAILED) && userName() == "ContainerAdministrator"
}
#expect(
userInfo[1].lowercased() == username.lowercased()
)
}
}

Expand Down Expand Up @@ -528,7 +543,7 @@ extension SubprocessWindowsTests {
).trimmingCharacters(in: .whitespacesAndNewlines)
// Make sure the child console is different from parent
#expect(
"\(intptr_t(bitPattern: parentConsole))" == differentConsoleValue
"\(intptr_t(bitPattern: parentConsole))" != differentConsoleValue
)
}

Expand Down Expand Up @@ -707,13 +722,13 @@ extension SubprocessWindowsTests {
WaitForSingleObject(processHandle, INFINITE)

// Up to 10 characters because Windows process IDs are DWORDs (UInt32), whose max value is 10 digits.
try writeFd.close()
let data = try await readFd.readUntilEOF(upToLength: 10)
let resultPID = try #require(
String(data: data, encoding: .utf8)
).trimmingCharacters(in: .whitespacesAndNewlines)
#expect("\(pid.value)" == resultPID)
try readFd.close()
try writeFd.close()
}
}

Expand Down