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
cabal test
outputs stdout and stderr out of order
#3024
Comments
Have you tried different Also, it's unclear whether (and where) ordering between stdout and stderr is well-defined, even on *x systems (let alone Windows), so it's unclear how the interface of In particular, it seems clearly hard to preserve order when performing filtering. (I am assuming that you're only printing complete lines to stdout, otherwise not even running the program standalone would preserve buffering). |
Perhaps it will help to talk about where I'm coming from: essentially, what I would like to have is a command to run all the test suites without doing any kind of buffering or filtering. The only problem (as far as I'm aware) with just running I realise that an ordering between stdout and stderr is probably not well-defined in general, but I'm really thinking about test suites which run sequentially and output text line-by-line, where it seems that it ought to be easier. I think that a lot of test suites are like this; possibly even most are. I hadn't tried different |
I'm not sure on the exact requirements, but I suspect in a perfect world it'd be overall easier to do fancy error reporting on test reports before stringifying them. I think that's also what happens on the JVM in most cases, by loading test classes at runtime; in Haskell, I'd rather exchange structured data (JSON? YAML?).
👍 I'd even go one step back to user requirements. |
Whoops, people are onto that already: #1601 (comment) |
This is PureScript. No test framework; just a bunch of tests and a call to The interleaving matters to me because one of the tests has two different sections; the first happens to output to stdout, and the second to stderr. The interleaving meant that it was annoying when the first passed and the second failed, because it looked like the second was not outputting anything before failing, when really, the second section's output was just a few lines back, mixed in with the first's. I suppose I could also fix this problem by a) flushing stdout and stderr between each section, or b) only outputting to one of those two streams, too. But it would be nice not to have to. |
Maybe the reason it doesn't work with |
I'd advise to try forcing line buffering in the launched test suite; line buffering is enabled by default when process run against terminals, but not when they run against pipes. That should be actually easy and, if you're right, should fix the problem. Maybe you want to have cabal tell the testsuite to do that if you don't always want that (but why?), but I'll leave that up to you. Otherwise, doing that just from inside While Haskell libraries appear not to use C buffering, the implementation appears to be similar enough; it might be instructive to look at the hacks used in Unix around this behavior (search for |
Then it seems reasonable for Cabal to present a pseudo-terminal to the subprocess when it intends to pass the information straight through to the user's terminal. (Well, someone has to implement it first though...) |
@ezyang The only reason I didn't do that in the first place is that Windows doesn't seem to have a notion analogous to pseudoterminals; I think the Cabal library should have the same features on all platforms. As discussed elsewhere, I think the correct way forward on this is to make the library "dumb" with respect to logging, i.e. only supporting |
👍 to On pseudoterminals: I said "sanest", but I did mean "still not sane, just less so". The TL;DR is "it's low-level UNIX APIs, so let's please run away from that complexity and maintenance hell". I implicitly assumed that pseudoterminals would be a pain to support, based on everything I hear about TTYs in general (not on having actually done it); it's low-level leaky UNIX APIs. Example puzzler: can you portably call Especially because the motivation is:
I expect it'd be better (in terms of overall effort) to put together the needed PureScript test framework (if missing) to use the But if some UNIX API expert contributes robust code to support that and guarantees long-term maintenance for it, even though I still expect that effort to be bigger, I might well turn out to be wrong. |
Just in case I wasn't clear: This is for the PureScript compiler, which is all written in Haskell. Looking at this discussion, I think it probably does make more sense just to make our test suite stop outputting to stderr, and send everything to stdout. It wouldn't be very much effort to do so. I'm not really sold on the |
With https://github.com/hdgarrood/cabal-test-stderr, if you run
cabal test
, you get this:But if you run the test executable directly, you get this:
That is,
lol
andoops, failed
appear the other way around.The source code is:
I expected
cabal test
to produce text output in the same order as running the executable directly, even if the test executable outputs text to both stderr and stdout.Possibly related: #1601. Being able to easily run the test suite directly would make this less of a problem.
The text was updated successfully, but these errors were encountered: