trycmd icon indicating copy to clipboard operation
trycmd copied to clipboard

Testing interactive programs

Open dnaka91 opened this issue 3 years ago • 4 comments

Thanks for this awesome library, it looks really awesome.

I was wondering if there is some support or setting that'd allow testing a binary that expects inputs from the user on the terminal.

Currently, I tried setting that up by using the *.toml format and providing a *.stdin file.

That unfortunately doesn't seem to work, as I get the error Failed to initialize input reader from the library I use (inquire). So it seems it needs some kind of proper TTY/PTY to function properly.

All the other features look really great, as my project is a code generator for new projects, and I want to verify that the generation works, where the *.out features is extremely convenient for verification.

dnaka91 avatar Jun 09 '22 03:06 dnaka91

Sounds like there are two requests here, TTY support so it can work with inquire and pexpect support.

Could you split these out into separate issues?

epage avatar Jun 09 '22 13:06 epage

I split off the request about pexpect-ish support into #102 now 🙇‍♂️

dnaka91 avatar Jun 10 '22 14:06 dnaka91

To give some more details about the inquire crate: I use it with the crossterm crate as backend, and it uses its enable_raw_mode when prompting the user. If that one fails (as it does without a TTY), it'll not be able to run the prompt.

So some sort of TTY or PTY seems to be definitely required for this, and likely for other interactive CLI apps too, as it needs some way to access advanced terminal features, rather than just stdin/stdout.

dnaka91 avatar Jun 10 '22 14:06 dnaka91

https://docs.rs/portable-pty/0.7.0/portable_pty/ might be useful for this

epage avatar Jun 10 '22 14:06 epage