-
Notifications
You must be signed in to change notification settings - Fork 264
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
XCTest: Stdio not output at correct point #422
Comments
|
This is a "bug" in xctest. The issue you're seeing here is that Therefore even if a As a workaround, you can place a func testPrint() {
for i in 1..<100 {
let string = (0..<i).map(\.description).joined()
print(string)
}
fflush(stdout) // <<---
}and everything will look okay. Arguably, XCTest should flush all the stdio buffers How can one debug this? For example with this dtrace. The meaning of this dtrace is:
the output is The relevant parts here are that XCTest's On the other hand, Swift's (see how the |
|
I pretty much came to the same conclusion while writing a response to your forum post |
|
Awesome! Also: XCTest does (sometimes?) print its status messages to This will also help with losing output in case of a crash/kill during a test when the stdio buffers can no longer be flushed and are lost. |
|
cc @stmontgomery @briancroom, should report be moved to XCTest repo and handled there? |
|
This symptom appears to be seen in the copy of XCTest included in Xcode, not in the "Corelibs" open source Swift version of XCTest contained in this repo. I have filed 102210347 to track the issue there. But we can keep this issue open to track fixing the same problem in this repo, even though I don't think that is where the bug was originally observed. |
|
Yes this is a macOS issue only. On macOS XCTest outputs all of its status updates to stderr, while the corelibs version outputs to stdout. This issue could be fixed by either
|
That alone won't be good enough. Unless XCTest starts going through stdio (i.e. My recommendation would be to flush everything right after the test has ended. That way we do as much as we can to make sure the printed data actually makes it into the output (terminal/pipe/file/...). |
|
I wonder if calling |
It would if we assume that the user never touches it. I still think it can be expected from a test framework that it flushes all sorts of output buffers at the end of a test. |
|
Agreed, that seems like a reasonable thing to do as well. |
|
We've transferred this issue to Radar as rdar://102210347 and will track it as an improvement to the XCTest framework. |
Describe the bug
Stdio output appears to be buffered and not outputting at correct time. The easiest way to reproduce this is create a test which outputs a lot of text. You'll find that the text output appears after the
TestSuite passedmessage. This only happens when running swift from the command line.Steps To Reproduce
Steps to reproduce the behavior:
swift testExpected behavior
Print out of numbers should appear before
TestSuite passedmessage.Environment (please fill out the following information)
Target: arm64-apple-macosx12.0
The text was updated successfully, but these errors were encountered: