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

Conversation

DilumAluthge
Copy link
Member

@DilumAluthge DilumAluthge commented Jul 16, 2022

This should help a little bit when trying to diagnose failures in the deprecation_exec test set (e.g. the failures seen in #46039).

@DilumAluthge DilumAluthge added the test This change adds or pertains to unit tests label Jul 16, 2022
test/misc.jl Outdated Show resolved Hide resolved
flags = Cmd(filter(a->!occursin("depwarn", a), collect(test_exeflags)))
cmd = `$test_exename $flags --depwarn=yes deprecation_exec.jl`
io = IOBuffer()
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
Sponsor 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
Sponsor 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

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants