-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Allow faking a terminal for testing #8
Comments
Actually, I'm not entirely certain this is so useful. I was able to relatively cleanly add testing to my own project, so I don't have a strong use case for it. Other projects that use atty might be structured differently and thus benefit from the ability to mock atty, but not mine. |
Nice. I'll leave this open in case you need it. Also neat project! |
Hmm, it's been a while since I wrote the tests. I think that I had an option to force color, regardless of if we were printing to a terminal, so if I wanted to test formatting I could set that option to be true. |
We have something like: fn permission_prompt(message: String) -> DenoResult<()> {
if !atty::is(atty::Stream::Stdin) || !atty::is(atty::Stream::Stderr) { return Err(permission_denied()) };
eprint!("{} Grant? yN", message);
... // more stuff What maybe you'd want to do is refactor to use dependency injection instead? https://stackoverflow.com/a/28370712/1240268 but then you not able to get an |
Okay, here's one way to fake TTYs in stdin, stdout and stderr: |
Thanks for this! I'm using it a command runner[0] to figure out when to produce colored error messages and it works great.
It would be great if I could somehow fool atty into thinking that a stream is a terminal for testing, so that I can make sure that error messages are being formatted correctly when a terminal is attached.
[0] https://github.com/casey/just
The text was updated successfully, but these errors were encountered: