You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if we could provide an easy way to test rexpect apps. Maybe something like this?
fnmain() -> Result<(),Error>{letmut p = rexpect::spawn("cat",Some(300))?;use_cat(&mut p)?;Ok(())}fnuse_cat(p:&mutPtySession) -> Result<(),Error>{
p.send_line("I'm a cat")?;
p.exp_string("I'm a cat\r\n")?;Ok(())}mod test {usesuper::*;#[test]fnoption1() -> Result<(),Error>{use_cat(
rexpect::testing::FakePtySession().recv("I'm a cat").send("I'm a cat"),)?;Ok(())}fnoption2() -> Result<(),Error>{letmut p = rexpect::testing::FakePtySession();
std::thread::spawn(|| use_cat(p));
p.recv("I'm a cat");
p.send("I'm a cat");Ok(())}}
Or any suggestions for a better interface? I think option2 looks nicer in the test case, but I think option1 is overall better, since it doesn't require spinning up a new thread, and needing to sync between the two.
I'm not sure how we could get nice error messages with either approach, but I'm working on option1 at the moment and will see how it turns out.
I haven't seen any crates providing special testing-utilities, is it normally not done? Should we have it behind a feature-flag?
Implementation wise, it looks like we would have to store Box<impl PtyProcess> in PtySession and Box<impl Write> in StreamSession. So that we can keep PtySession without template arguments. This would break the API, but I don't think it should be a problem?
The text was updated successfully, but these errors were encountered:
It would be nice if we could provide an easy way to test rexpect apps. Maybe something like this?
Or any suggestions for a better interface? I think option2 looks nicer in the test case, but I think option1 is overall better, since it doesn't require spinning up a new thread, and needing to sync between the two.
I'm not sure how we could get nice error messages with either approach, but I'm working on option1 at the moment and will see how it turns out.
I haven't seen any crates providing special testing-utilities, is it normally not done? Should we have it behind a feature-flag?
Implementation wise, it looks like we would have to store
Box<impl PtyProcess>
in PtySession andBox<impl Write>
in StreamSession. So that we can keep PtySession without template arguments. This would break the API, but I don't think it should be a problem?The text was updated successfully, but these errors were encountered: