Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Testing rexpect app

オープン
#79 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-cli/rexpect のほかの issue

rust-cli/rexpect の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。