use assert_cmd::prelude::*; use assert_fs::prelude::*; use predicates::prelude::*; use std::process::Command; #[test] fn file_doesnt_exist() -> Result<(), Box> { let mut cmd = Command::cargo_bin("minigrep")?; cmd.arg("hello").arg("test/file/doesnt/exist"); cmd.assert() .failure() .stderr(predicate::str::contains("could not read file")); Ok(()) } #[test] fn find_content_in_file() -> Result<(), Box> { let file = assert_fs::NamedTempFile::new("sample.txt")?; let content = "A test\nActual content\nMore content\nAnother test"; file.write_str(content)?; Command::cargo_bin("minigrep")? .arg("test") .arg(file.path()) .assert() .success() .stdout(predicate::str::contains("test\nAnother test")); Command::cargo_bin("minigrep")? .arg("") .arg(file.path()) .assert() .success() .stdout(predicate::str::contains(content)); Ok(()) }