diff --git a/src/main.rs b/src/main.rs index 40fa446..23ff801 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::fs::{File, metadata}; use std::path::Path; use std::process::Command; -/// tail a file or execite the fallback command +/// tail a file or execute the fallback command /// /// Attempts to tail a file. If the file doesn't exist or can't be read, /// runs the specified fallback command instead passing the specified file. @@ -14,7 +14,7 @@ use std::process::Command; /// Examples: /// tailor file.txt touch # tail file.txt, or touch file.txt /// tailor file.txt chmod 755 # tail file.txt, or chmod 755 file.txt -/// tailor config.json cp config.template.json # tail file.txt, or cp config.template.json config.json +/// tailor config.json cp config.template.json # tail config.json, or cp config.template.json config.json #[derive(Parser, Debug)] #[command(version, about, long_about, verbatim_doc_comment)] struct Args { @@ -110,7 +110,10 @@ mod tests { #[test] fn test_can_tail_file_with_nonexistent_file() { - let result = can_tail_file("/tmp/nonexistent_file_12345").unwrap(); + let temp_file = NamedTempFile::new().unwrap(); + let file_path = temp_file.path().to_str().unwrap(); + std::fs::remove_file(file_path).unwrap(); + let result = can_tail_file(file_path).unwrap(); assert!(!result, "Should not be able to tail a nonexistent file"); } @@ -212,8 +215,11 @@ mod tests { #[test] fn test_main_fails_without_fallback_command() { + let temp_file = NamedTempFile::new().unwrap(); + let file_path = temp_file.path().to_str().unwrap(); + std::fs::remove_file(file_path).unwrap(); let mut cmd = Command::cargo_bin("tailor").unwrap(); - cmd.arg("/tmp/nonexistent_file_12345") + cmd.arg(file_path) .assert() .failure() .stderr(contains("no fallback command"));