Testing rexpect app
@ekarlsn がすでに取り組んでいます。
2022年10月14日 から。
評価
この issue はまだ評価されていません。
説明
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?
- 主要言語
- Rust
- スター
- 391
- フォーク
- 69
- 平均マージ
- 1日 34分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-cli/rexpect のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
-
Configurable sleeps オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
rust-cli/rexpect の issue をすべて見る
似ている issue
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
n0-computer/iroh#4550 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
paritytech/zombienet-sdk#591 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
farion1231/cc-switch#7638 · コメント 1 件 ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100