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
[SR-752] print does not print in some XCTest situations #405
Comments
Thanks for the report, @drewcrawford! I'm a little confused, though--why do you think Apple XCTest does define a class #import <XCTest/XCTestObserver.h>
/*!
* XCTestLog is deprecated.
*/
DEPRECATED_ATTRIBUTE
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@interface XCTestLog : XCTestObserver
#pragma clang diagnostic pop
@property (readonly, strong) NSFileHandle *logFileHandle;
- (void)testLogWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2);
- (void)testLogWithFormat:(NSString *)format arguments:(va_list)arguments NS_FORMAT_FUNCTION(1,0);
@end Note that In any case, could you explain what the bug is here? Sorry for not catching on! |
Sorry for writing a trainwreck of a bug report. Let me explain how I got here: 1. print didn't work inside an XCTest target, on x64 Linux. Is that a bug? Well, maybe not... I know XCTest does weird XPC stuff on Darwin, maybe stdout isn't connected on Linux by design. Knowing what I know now: 1. Maybe the real bug is that print doesn't work? ![](Screen Shot 2016-02-23 at 6.26.06 PM.png) I know that I still haven't given enough information to get any of these issues reproducible, but it would be a good start to find out which ones are expected and which are not. |
Aha, thanks for the detailed follow-up! 🙂
|
Ping @drewcrawford--did you see my comment above? Does this still happen for you? |
Sorry @modocache. I decided to reply by rewriting the bug description, since my original was so bad, and was a poor introduction to anyone who might stumble onto the issue. I thought it would notify you. It seems it did not. I am still affected by the issue. The rewritten bug description includes a full test case. Thanks for following up. |
The root cause of this may be https://bugs.swift.org/browse/SR-1127. Based on the comment by Dmitri there, we may want to close this as a "won't fix". |
@drewcrawford Could you follow-up on whether this is still affecting you, and whether you think that the `print()` buffering could be the source? Does the missing output appear if you explicitly flush before the `fatalError`? I'll point out that XCTest itself does explicitly flush after each of its `print` statements: https://github.com/apple/swift-corelibs-xctest/blob/master/Sources/XCTest/PrintObserver.swift#L69 |
I'm going to go ahead and close this due to:
Thanks for the report, though! |
Attachment: Download
Environment
Linux x64
swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a
Additional Detail from JIRA
md5: d46b18027b75685e1ff1ab234eddcb5f
Issue Description:
Okay, let me fix this trainwreck of a bug report. In the attached sample project, we have a function that prints:
We have a test that calls this function, and then crashes:
On OSX / Darwin XCTest, we see the print statement (expected behavior):
But on Linux (corelibs-xctest), we do not:
It is not as simple as "print isn't buffered on Linux", because a trivial example of print-then-fatalError prints as expected. So there is something to do with XCTest specifically involved here.
Implementation notes
SwiftPM does not support XCTest in the Feb 8th snapshot, so instead this sample project uses atbuild. Apologies in advance for foisting an unfamiliar build system on you. You can download it here. On OSX, to reproduce it is simply
atbuild
in the working directory. For Linux, I have replicated my entire environment in Docker, and you can just rundocker build .
on any system with Docker installed to see the Linux behavior.On Darwin,
atbuild
uses Darwin XCTest, builds.xctest
bundles, and runs tests withxcrun xctest /path/to/bundle.xctest
. On Linux, it builds executables linked with corelibs-xctest and runs them via thesystem
POSIX call.The text was updated successfully, but these errors were encountered: