Skip to content

Override Console.out and Console.err the REPL #3940

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

Merged
merged 1 commit into from
Jan 29, 2018

Conversation

allanrenucci
Copy link
Contributor

This make it possible to test command such as println in the REPL
scripted tests.

This make it possible to test command such as `println` in the REPL
scripted tests.
@allanrenucci
Copy link
Contributor Author

I am not 100% this is the right solution. I guess hijacking Console.in and Console.out when the JVM is shared can lead to surprising behaviors (like when running inside sbt).

Copy link
Contributor

@felixmulder felixmulder left a comment

Choose a reason for hiding this comment

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

Very good to see some progress on this!

I agree that it's tricky. Since System.out and System.in are final MUTABLE in Java - maybe that influences this implementation?

I reckon Console.in is bound to System.in somewhere along the chain.

It looks good to me in that it solves the issue - but how resilient would it be if there is logging to stdout for instance? Eg logback and friends.

Maybe that's hard to test. Right now I don't have bandwidth to do a bug bash, but I've raised my concerns and I'm happy to see this go in since it improves the state of things! :)

@allanrenucci
Copy link
Contributor Author

Console.out is initialised to System.out. Then if System.out is later on mutated, it will not impact Console.out. However Console.out is effectively mutated by Console.withOut(out) { ... }. The old value is restored while returning but the mutation can be seen by another thread.

It looks good to me in that it solves the issue - but how resilient would it be if there is logging to stdout for instance? Eg logback and friends.

This implementation is not mutating System.out, so anything that you run within the REPL that uses the Java API will output to System.out. We could also set System.out and System.err in withRedirectedOutput, but unless there is a use case, I would be conservative and not play with 🔥

@felixmulder
Copy link
Contributor

Sounds reasonable, we did something similar in Vulpix FYI.

But yeah, LGTM :)

@allanrenucci allanrenucci merged commit 6d06cce into scala:master Jan 29, 2018
@allanrenucci allanrenucci deleted the fix-repl-scripted branch January 29, 2018 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants