use assert_cmd::Command; use predicates::prelude::predicate; use std::io::{self, Write}; use tempfile::NamedTempFile; #[test] fn file_doesnt_exit() -> Result<(), Box> { let mut cmd = Command::cargo_bin("grrs")?; cmd.arg("foobar").arg("test/file/that/doesnt/exist"); cmd.assert() .failure() .stderr(predicate::str::contains("could not open file")); Ok(()) } #[test] fn find_content_in_a_file() -> Result<(), Box> { let mut file = NamedTempFile::new()?; writeln!(file, "A test\nActual content\nMore content\nAnother test")?; let mut cmd = Command::cargo_bin("grrs")?; cmd.arg("test").arg(file.path()); cmd.assert() .success() .stdout(predicate::str::contains("test\nAnother test")); Ok(()) }