use std::process::Command; use assert_cmd::prelude::*; use predicates::prelude::*; #[test] fn file_doesnt_exist() -> Result<(), Box> { let mut cmd = Command::main_binary()?; cmd.arg("foobar") .arg("plop/plip/ploup"); cmd.assert() .failure() .stderr(predicate::str::contains("No such file or directory")); Ok(()) } use tempfile::NamedTempFile; use std::io::{self, Write}; #[test] fn find_content_in_file() -> Result<(), Box> { let mut file = NamedTempFile::new()?; writeln!(file, "A test\nActual content\nMore content\nAnother test")?; let mut cmd = Command::main_binary()?; cmd.arg("test") .arg(file.path()); cmd.assert() .success() .stdout(predicate::str::contains("test\nAnother test")); Ok(()) } #[test] fn passing_empty_string() -> Result<(), Box> { let mut file =NamedTempFile::new()?; writeln!(file, "Who care what in\nwe just want to check\nerrors")?; let mut cmd = Command::main_binary()?; cmd.arg("") .arg(file.path()); cmd.assert() .failure() .stderr(predicate::str::contains("No pattern given")); Ok(()) }