Testing Long-Running CLI app Part II

Started my journey here, and made some progress, in terms of designing the app to be testable:

But now I'm on the back end and am still struggling to figure out the best way to test my app. I'm using assert_cmd which is great, but am challenged with how to start the app, then do something externally, catching stdout and stderr after that, then doing the assert on the output.

Here's what I have - that doesn't work...the assert never catches.

let mut cmd = Command::cargo_bin("cli_app")?;
    cmd.arg("spy");
    cmd.arg("-b");
    cmd.arg("master");
    cmd.arg("-d");
    cmd.arg("10");
    cmd.arg("-x");
    cmd.arg(format!("file://{}", arg_path));
    cmd.spawn()?;
    
    let ten_millis = std::time::Duration::from_millis(1000);
    std::thread::sleep(ten_millis);

    cli_app_file.write_all(b", world!\"")?;

    match add_and_commit(&repo, Path::new(".cli_app"), "test2"){
        Ok(oid) => println!("OID: {}", oid),
        Err(e) => eprintln!("error: {}", e),
    }

    //cmd.wait()?;
    cmd.assert()
        .stderr(predicates::str::contains("goa"));

Is this even possible?

TIA.
Kit

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.