Open ssfrr opened 6 years ago
hm, the 2nd method is more specific than the current redirect_stdout(f::Function, stream)
so it's getting called instead, so that signature would need to be tweaked to catch the OS-level file stream types more specifically.
The usability of the
redirect_stdout
etc. functions got a big boost with thedo
versions, but there are still some gotchas that make them often inconvenient, and I think they can be improved without any breaking changes:Sometimes you just want to throw away output
This could be written as:
This was proposed in #22879, and seems like it would need a cross-platform way to open a null file. It looks like on windows you can
open("nul", "w")
. So this could be implemented as something like:It's come up before that the
redirect_
functions don't support more genericIO
typesThis was mentioned in the above issue, and also in #12711. It would look like:
Capturing to a string is a multi-step process
It's common in testing to check that your code is outputting what you expect, so an easy way to capture to a string would be useful. This could be:
This implementation for both these last two could look very similar to the
@capture_out
macro from Suppressor.jl except that there's no need for it to be a macro (originally those were macros so that the macro didn't affect the expression's scope, but that got blown out of the water when we added thetry...finally
block).:TBH I'm not 100% sure what the
if ccall(:jl_generating_output, Cint, ()) == 0
checks are for, I think they came from some of @keno's codeThese methods are all currently errors, so it seems like they could be candidates for a 1.x release if they seem like OK ideas.