Testing rexpect app
@ekarlsn ci sta già lavorando.
Dal 14/10/2022.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
It would be nice if we could provide an easy way to test rexpect apps. Maybe something like this?
fn main() -> Result<(), Error> {
let mut p = rexpect::spawn("cat", Some(300))?;
use_cat(&mut p)?;
Ok(())
}
fn use_cat(p: &mut PtySession) -> Result<(), Error> {
p.send_line("I'm a cat")?;
p.exp_string("I'm a cat\r\n")?;
Ok(())
}
mod test {
use super::*;
#[test]
fn option1() -> Result<(), Error> {
use_cat(
rexpect::testing::FakePtySession()
.recv("I'm a cat")
.send("I'm a cat"),
)?;
Ok(())
}
fn option2() -> Result<(), Error> {
let mut 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?
- Lingua principale
- Rust
- Stelle
- 391
- Fork
- 69
- Merge medio
- 1g 34m
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-cli/rexpect
-
Strict output expectations Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
-
Configurable sleeps Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
Tutte le issue di rust-cli/rexpect
Issue simili
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
n0-computer/iroh#4550 ·
-
impl detach for native Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
paritytech/zombienet-sdk#591 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
farion1231/cc-switch#7638 · 1 commento ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100