use std::process::Command; use assert_cmd::prelude::*; use assert_fs::prelude::*; use predicates::prelude::*; #[test] fn file_doesnt_exist() -> Result<(), Box> { let mut cmd = Command::cargo_bin("fe-cli")?; cmd.arg("foobar").arg("test/file/doesn/exist"); cmd.assert() .failure() .stderr(predicate::str::contains("cannot find the path specified")); Ok(()) } #[test] fn find_content_in_file() -> Result<(), Box> { let file = assert_fs::NamedTempFile::new("sample.txt")?; file.write_str("A test\nActual content\nMore content\nAnother test")?; let mut cmd = Command::cargo_bin("fe-cli")?; cmd.arg("test").arg(file.path()); cmd.assert() .success() .stdout(predicate::str::contains("A test\nAnother test")); Ok(()) } #[test] fn accept_empty_pattern() -> Result<(), Box> { let file = assert_fs::NamedTempFile::new("sample.txt")?; let content = "Some content on Line-1\nSome other content on Line-2"; file.write_str(content)?; let mut cmd = Command::cargo_bin("fe-cli")?; cmd.arg("").arg(file.path()); cmd.assert() .success() .stdout(predicate::str::contains(content)); Ok(()) }