Skip to content

Commit 9c0f3cd

Browse files
committed
Fix Windows test errors
1 parent 664238c commit 9c0f3cd

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Sources/Subprocess/IO/AsyncIO.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ extension AsyncIO {
330330
var count: Int { get }
331331

332332
func withUnsafeBytes<ResultType>(
333-
_ body: (UnsafeRawBufferPointer
334-
) throws -> ResultType) rethrows -> ResultType
333+
_ body: (UnsafeRawBufferPointer) throws -> ResultType
334+
) rethrows -> ResultType
335335
}
336336

337337
func read(
@@ -739,7 +739,12 @@ final class AsyncIO: Sendable {
739739
)
740740
continuation.resume(throwing: windowsError)
741741
} else {
742-
continuation.resume(returning: values)
742+
// If we didn't read anything, return nil
743+
if values.isEmpty {
744+
continuation.resume(returning: nil)
745+
} else {
746+
continuation.resume(returning: values)
747+
}
743748
}
744749
}
745750
}

Tests/SubprocessTests/SubprocessTests+Windows.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import TestResources
2727

2828
@Suite(.serialized)
2929
struct SubprocessWindowsTests {
30-
private let cmdExe: Subprocess.Executable = .path("C:\\Windows\\System32\\cmd.exe")
30+
private let cmdExe: Subprocess.Executable = .name("cmd.exe")
3131
}
3232

3333
// MARK: - Executable Tests
@@ -87,7 +87,7 @@ extension SubprocessWindowsTests {
8787
Issue.record("Expected to throw POSIXError")
8888
} catch {
8989
guard let subprocessError = error as? SubprocessError,
90-
let underlying = subprocessError.underlyingError
90+
let underlying = subprocessError.underlyingError
9191
else {
9292
Issue.record("Expected CocoaError, got \(error)")
9393
return
@@ -128,7 +128,6 @@ extension SubprocessWindowsTests {
128128
environment: .inherit,
129129
output: .string
130130
)
131-
#expect(result.terminationStatus.isSuccess)
132131
// As a sanity check, make sure there's
133132
// `C:\Windows\system32` in PATH
134133
// since we inherited the environment variables
@@ -249,7 +248,6 @@ extension SubprocessWindowsTests {
249248
output: .data(limit: 2048 * 1024)
250249
)
251250

252-
#expect(catResult.terminationStatus.isSuccess)
253251
// Make sure we read all bytes
254252
#expect(
255253
catResult.standardOutput == expected
@@ -304,7 +302,6 @@ extension SubprocessWindowsTests {
304302
input: .sequence(stream),
305303
output: .data(limit: 2048 * 1024)
306304
)
307-
#expect(catResult.terminationStatus.isSuccess)
308305
#expect(
309306
catResult.standardOutput == expected
310307
)
@@ -510,7 +507,7 @@ extension SubprocessWindowsTests {
510507
@Test func testPlatformOptionsCreateNewConsole() async throws {
511508
let parentConsole = GetConsoleWindow()
512509
let sameConsoleResult = try await Subprocess.run(
513-
.path("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
510+
.name("powershell.exe"),
514511
arguments: [
515512
"-File", windowsTester.string,
516513
"-mode", "get-console-window",
@@ -529,7 +526,7 @@ extension SubprocessWindowsTests {
529526
var platformOptions: Subprocess.PlatformOptions = .init()
530527
platformOptions.consoleBehavior = .createNew
531528
let differentConsoleResult = try await Subprocess.run(
532-
.path("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
529+
.name("powershell.exe"),
533530
arguments: [
534531
"-File", windowsTester.string,
535532
"-mode", "get-console-window",
@@ -700,12 +697,13 @@ extension SubprocessWindowsTests {
700697
0
701698
)
702699
let pid = try Subprocess.runDetached(
703-
.path("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
700+
.name("powershell.exe"),
704701
arguments: [
705702
"-Command", "Write-Host $PID",
706703
],
707704
output: writeFd
708705
)
706+
try writeFd.close()
709707
// Wait for process to finish
710708
guard
711709
let processHandle = OpenProcess(

0 commit comments

Comments
 (0)