Skip to content

Commit c90e17e

Browse files
authored
Move the stdout line-buffering call. (#576)
Move the `stdout` line-buffering call so it affects both overloads of `__swiftPMEntryPoint()`. This has no effect on SwiftPM because it currently uses the overload that returns `Never`. Two overloads are provided to allow SwiftPM some flexibility, but we're not actively taking advantage of that in Swift 6. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 41330ae commit c90e17e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Sources/Testing/ABI/EntryPoints/SwiftPMEntryPoint.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ var EXIT_NO_TESTS_FOUND: CInt {
5050
/// - Warning: This function is used by Swift Package Manager. Do not call it
5151
/// directly.
5252
public func __swiftPMEntryPoint(passing args: __CommandLineArguments_v0? = nil) async -> CInt {
53-
await entryPoint(passing: args, eventHandler: nil)
53+
#if !SWT_NO_FILE_IO
54+
// Ensure that stdout is line- rather than block-buffered. Swift Package
55+
// Manager reroutes standard I/O through pipes, so we tend to end up with
56+
// block-buffered streams.
57+
FileHandle.stdout.withUnsafeCFILEHandle { stdout in
58+
_ = setvbuf(stdout, nil, _IOLBF, Int(BUFSIZ))
59+
}
60+
#endif
61+
62+
return await entryPoint(passing: args, eventHandler: nil)
5463
}
5564

5665
/// The entry point to the testing library used by Swift Package Manager.
@@ -69,15 +78,6 @@ public func __swiftPMEntryPoint(passing args: __CommandLineArguments_v0? = nil)
6978
/// - Warning: This function is used by Swift Package Manager. Do not call it
7079
/// directly.
7180
public func __swiftPMEntryPoint(passing args: __CommandLineArguments_v0? = nil) async -> Never {
72-
#if !SWT_NO_FILE_IO
73-
// Ensure that stdout is line- rather than block-buffered. Swift Package
74-
// Manager reroutes standard I/O through pipes, so we tend to end up with
75-
// block-buffered streams.
76-
FileHandle.stdout.withUnsafeCFILEHandle { stdout in
77-
_ = setvbuf(stdout, nil, _IOLBF, Int(BUFSIZ))
78-
}
79-
#endif
80-
8181
let exitCode: CInt = await __swiftPMEntryPoint(passing: args)
8282
exit(exitCode)
8383
}

0 commit comments

Comments
 (0)