File: lib.rs

package info (click to toggle)
rust-inquire 0.9.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,956 kB
  • sloc: makefile: 2; sh: 1
file content (42 lines) | stat: -rw-r--r-- 1,104 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#[cfg(test)]
#[cfg(not(any(target_os = "windows")))]
mod tests {
    use std::process::Command;

    use assert_cmd::assert::OutputAssertExt;
    use rexpect::{session::PtySession, spawn};

    #[test]
    fn test() -> anyhow::Result<()> {
        Command::new("cargo")
            .args(["build"])
            .assert()
            .success()
            .code(0);

        run_example("password_simple", |mut process| {
            process.exp_string("RSA Encryption Key")?;
            process.send_line("secret")?;
            process.exp_string("Confirmation:")?;
            process.send_line("secret")?;
            process.exp_string("This doesn't look like a key.")?;
            process.exp_eof()?;
            Ok(())
        })?;

        Ok(())
    }

    fn run_example<T>(example_name: &str, test_case: T) -> anyhow::Result<()>
    where
        T: FnOnce(PtySession) -> anyhow::Result<()>,
    {
        let process = spawn(
            format!("../target/debug/examples/{example_name}").as_str(),
            Some(30_000),
        )?;
        test_case(process)?;

        Ok(())
    }
}