Skip to content
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

Test suite: If the deprecation_exec test fails, print the subcommand's stdout and stderr to the log #46059

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -967,12 +967,20 @@ end

include("testenv.jl")


let flags = Cmd(filter(a->!occursin("depwarn", a), collect(test_exeflags)))
local cmd = `$test_exename $flags --depwarn=yes deprecation_exec.jl`

if !success(pipeline(cmd; stdout=stdout, stderr=stderr))
error("Deprecation test failed, cmd : $cmd")
@testset "deprecation_exec" begin
flags = Cmd(filter(a->!occursin("depwarn", a), collect(test_exeflags)))
cmd = `$test_exename $flags --depwarn=yes deprecation_exec.jl`
cmd = ignorestatus(cmd)
io = Base.BufferStream()
pipln = pipeline(cmd; stdout=io, stderr=io)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm away from computer and can't check myself: can you have stdout and stderr writing to the same buffer? It's nice if that just works, I guess it'd be similar to &> redirection in shell.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick test, it seems to work fine.

julia> println(read("foo.jl", String))
println(stdout, "out1")
println(stderr, "err1")


println(stdout, "out2")
println(stderr, "err2")


println(stdout, "out3")
println(stderr, "err3")


julia> cmd = `julia foo.jl`;

julia> io = IOBuffer();

julia> run(pipeline(cmd; stdout=io, stderr=io));

julia> println(String(take!(io)))
out1
err1
out2
err2
out3
err3


julia>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not allowed to use an IOBuffer as output, as such types are not stream-oriented, so they lack the required EOF capabilities. Use a BufferStream instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've switched this PR to use Base.BufferStream().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vtjnash Is it legal for me to send both stdout and stderr to the same BufferStream? E.g.

io = Base.BufferStream()

run(pipeline(cmd; stdout=io, stderr=io))

close(io)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. It will result in the program getting 2 different streams, while you probably wanted it to get only one file description

Copy link
Member Author

@DilumAluthge DilumAluthge Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. What's the correct way to capture the stdout and stderr from a command into a single string?

proc = run(pipln)
close(io)
proc_output = String(read(io))
if !success(proc)
# If the test failed, we print the stdout and stderr to the log.
println(proc_output)
@error "Deprecation test failed" cmd proc.exitcode proc.termsignal
@test false
end
end

Expand Down