Testing rexpect app
@ekarlsn đang làm issue này rồi.
Từ ngày 14/10/2022.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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?
- Ngôn ngữ chính
- Rust
- Star
- 391
- Fork
- 69
- Merge trung bình
- 1 ngày 34 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-cli/rexpect
-
Strict output expectations Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Disabling bracketed paste mode Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
Configurable sleeps Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
Tất cả issue của rust-cli/rexpect
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
state:needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
zed-industries/zed#64680 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
RustPython/RustPython#8802 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
TheLarkInn/aipm#2390 ·