-
Notifications
You must be signed in to change notification settings - Fork 35
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
Unable to test TTY behavior #138
Comments
Just a thought: maybe |
Just tried it, seems to be leading to the same behavior as without it, just slightly different verbose output. I think there needs to be a switch somewhere that toggles on "this should run exactly as when the user runs it in their terminal". The current default behavior is correct, since in theory, tests do run not directly in the terminal, but in their own environment (cargo, in this case). I just need to test things and let cargo know to make the program think it's inside of a TTY when it comes to STDOUT. |
We always capture stdout/stderr so we can run assertions on them. We'd need to add support for something like portable_ptr to do this. Overall, I'd recommend providing a flag / env variable to give users control over this behavior. At that point, its only a question of whether the auto-detection works or not. |
You're probably right on the money about the software being tested that must be responsible for being able to behave a certain way, not the testing framework. I will look at wget, curl, and other popular tools to see what format they use for ENV variables (naming is important for things like that sometimes, wouldn't want to make it too weird). Meanwhile, could you please hint at how to provide ENV variables to my CLI tool via assert_cmd, is it just |
According to the NO_COLOR FAQ, "user-level configuration files [...] should override $NO_COLOR." https://no-color.org/ Unfortunately this makes it harder to test the $NO_COLOR behavior since the test environment isn't attached to a tty. We could allocate a pty or LD_PRELOAD shim to intercept isatty(), but I feel it would be too much to do. assert-rs/assert_cmd#138
Substitute prompt_password for removed prompt_password. Note that prompt_password prints the prompt string to /dev/tty, while prompt_password_stdout printed the prompt to stdout. Remove test that prints password prompt. Since the prompt goes to tty rather than stdout, the test framework is not able to handle it. This is a know limitation of the framework, see: assert-rs/assert_cmd#138 Signed-off-by: mulhern <amulhern@redhat.com>
Substitute prompt_password for removed prompt_password. Note that prompt_password prints the prompt string to /dev/tty, while prompt_password_stdout printed the prompt to stdout. Remove test that prints password prompt. Since the prompt goes to tty rather than stdout, the test framework is not able to handle it. This is a know limitation of the framework, see: assert-rs/assert_cmd#138 Signed-off-by: mulhern <amulhern@redhat.com>
Substitute prompt_password for removed prompt_password. Note that prompt_password prints the prompt string to /dev/tty, while prompt_password_stdout printed the prompt to stdout. Remove test that prints password prompt. Since the prompt goes to tty rather than stdout, the test framework is not able to handle it. This is a know limitation of the framework, see: assert-rs/assert_cmd#138 Signed-off-by: mulhern <amulhern@redhat.com>
Using crate
atty
:When I run tests,
stdout_is_a_tty
is always false, hence I can't test the textual "to-terminal" output of my program, which I really need to test somehow. Ideally there should be some switch in assert_cmd... I really don't want to use env variables to force that behavior, it'd be very hacky.Thank you for creating and maintaining this crate, really helps me test my software even the way it is right now!
The text was updated successfully, but these errors were encountered: