Skip to content

Commit

Permalink
Clean up redirect_* APIs after Pipe -> PipeEndpoint rename
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Aug 26, 2016
1 parent c8d6a78 commit f06840e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -959,17 +961,17 @@ 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

"""
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)

Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f06840e

Please sign in to comment.