Skip to content

Commit

Permalink
test explicit stdout/stderr printing
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 6, 2018
1 parent 03e4ef9 commit d1caa23
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/stdio.jl
@@ -1,13 +1,16 @@
using Compat.Test
using IJulia
using Compat: occursin

mktemp() do path, io
redirect_stdout(IJulia.IJuliaStdio(io, "stdout")) do
stdout = isdefined(Base, :devnull) ? Base.stdout : Base.STDOUT
println(stdout, "stdout")
println("print")
end
flush(io)
seek(io, 0)
@test read(io, String) == "print\n"
@test read(io, String) == "stdout\nprint\n"
@test_throws ArgumentError redirect_stdout(IJulia.IJuliaStdio(io, "stderr"))
@test_throws ArgumentError redirect_stdout(IJulia.IJuliaStdio(io, "stdin"))
@test_throws ArgumentError redirect_stderr(IJulia.IJuliaStdio(io, "stdout"))
Expand All @@ -16,25 +19,20 @@ mktemp() do path, io
@test_throws ArgumentError redirect_stdin(IJulia.IJuliaStdio(io, "stderr"))
end

# Helper function to strip out color codes from strings to make it easier to
# compare output within tests that has been colorized
function strip_colorization(s)
return replace(s, r"(\e\[\d+m)"m => "")
end

mktemp() do path, io
redirect_stderr(IJulia.IJuliaStdio(io, "stderr")) do
warn("warn")
stderr = isdefined(Base, :devnull) ? Base.stderr : Base.STDERR
println(stderr, "stderr")
end
flush(io)
seek(io, 0)
@test strip_colorization(read(io, String)) == "WARNING: warn\n"
@test read(io, String) == "stderr\n"
end

mktemp() do path, io
redirect_stdin(IJulia.IJuliaStdio(io, "stdin")) do
# We can't actually do anything here because `IJuliaexecute_msg` has not
# yet been initialized, so we just make sure that redirect_stdin does
# yet been initialized, so we just make sure that redirect_stdin does
# not error.
end
end
Expand Down

0 comments on commit d1caa23

Please sign in to comment.