From f06840ee80f70b6823464a35a4b9b9f78254cb8b Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 26 Aug 2016 16:11:21 -0400 Subject: [PATCH] Clean up redirect_* APIs after Pipe -> PipeEndpoint rename These probably should have been cleaned up along side that in #12739. Certainly the documentation was out of date, since it referred to `Pipe`, but meant what is now called `PipeEndpoint`. Clean all of this up, by allowing an unitinalized `Pipe` to be passed to these functions, and also by replacing the tuple of `PipeEndpoint`s, by `Pipe`, since the purpose of `Pipe` is precisely to hold two endpoints. --- base/stream.jl | 22 ++++++++++++---------- test/test.jl | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/base/stream.jl b/base/stream.jl index f42af7b82c2ec..965f1a350a050 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -946,11 +946,13 @@ for (x, writable, unix_fd, c_symbol) in handle.handle) handle end + function ($f)(handle::Pipe) + link_pipe(handle, julia_only_read = $(writable), julia_only_write = $(!writable)) + $(f)($(writable) ? handle.in : handle.out) + handle + end function ($f)() - read,write = (PipeEndpoint(), PipeEndpoint()) - link_pipe(read,$(writable),write,$(!writable)) - ($f)($(writable? :write : :read)) - (read,write) + $(f)(Pipe()) end end end @@ -959,9 +961,9 @@ end redirect_stdout() Create a pipe to which all C and Julia level `STDOUT` output will be redirected. Returns a -tuple `(rd,wr)` representing the pipe ends. Data written to `STDOUT` may now be read from -the rd end of the pipe. The wr end is given for convenience in case the old `STDOUT` object -was cached by the user and needs to be replaced elsewhere. +Pipe object representing the pipe ends. Data written to `STDOUT` may now be read from +the pipe. Note that `STDOUT` will be set to `pipe.in` (which is a `PipeEndpoint`), not the +pipe itself. """ redirect_stdout @@ -969,7 +971,7 @@ redirect_stdout redirect_stdout(stream) Replace `STDOUT` by stream for all C and Julia level output to `STDOUT`. Note that `stream` -must be a TTY, a `Pipe` or a `TCPSocket`. +must be a TTY, a `Pipe`, a `PipeEndpoint` or a `TCPSocket`. """ redirect_stdout(stream) @@ -983,8 +985,8 @@ redirect_stderr """ redirect_stdin([stream]) -Like redirect_stdout, but for STDIN. Note that the order of the return tuple is still -(rd,wr), i.e. data to be read from STDIN, may be written to wr. +Like redirect_stdout, but for STDIN. Note however, that in this case, STDIN will be `pipe.out` +(such that data written to `pipe` will be available to read from `STDIN`). """ redirect_stdin diff --git a/test/test.jl b/test/test.jl index 7e2e8b70823af..bfca896e0c6c8 100644 --- a/test/test.jl +++ b/test/test.jl @@ -76,7 +76,8 @@ tse_str = sprint(show, Test.TestSetException(1,2,3,4)) OLD_STDOUT = STDOUT catch_out = IOStream("") -rd, wr = redirect_stdout() +# Capture a reference to make sure the read end doesn't get closed +pipe = redirect_stdout() # Check that the fallback test set throws immediately @test_throws ErrorException (@test 1 == 2)