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 分钟
- 30 天内合并 PR
- 2
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-cli/rexpect 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 48/100
-
难度 3/5 1-2 天 新手友好度 25/100
相似的 Issue
-
bug github_actions
难度 2/5 1-3 小时 新手友好度 75/100
registrystack/registry-stack#1393 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
难度 2/5 1-3 小时 新手友好度 65/100
rocky-data/rocky#2181 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
oasisprotocol/oasis-sdk#2523 ·
-
bot:ai-assisted component:indexer QA-roadmap status:untriaged
难度 2/5 1-3 小时 新手友好度 75/100
midnightntwrk/midnight-indexer#1557 ·