use std::fs;
use std::process::Command;
use tempfile::TempDir;
#[test]
fn test_extract_command_with_input_file() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let source_file_path = temp_dir.path().join("test_source.rs");
let source_content = r#"
fn main() {
println!("Hello, world!");
}
"#;
fs::write(&source_file_path, source_content).unwrap();
let input_file_path = temp_dir.path().join("input.txt");
fs::write(
&input_file_path,
source_file_path.to_string_lossy().as_bytes(),
)
.unwrap();
let project_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let help_output = Command::new("cargo")
.args([
"run",
"--manifest-path",
project_dir.join("Cargo.toml").to_string_lossy().as_ref(),
"--",
"extract",
"--help",
])
.output()
.expect("Failed to execute help command");
let help_text = String::from_utf8_lossy(&help_output.stdout);
assert!(
help_text.contains("-F, --input-file"),
"Help text should include the new --input-file option"
);
}
#[test]
fn test_extract_command_with_nonexistent_input_file() {
let project_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let output = Command::new("cargo")
.args([
"run",
"--manifest-path",
project_dir.join("Cargo.toml").to_string_lossy().as_ref(),
"--",
"extract",
"--input-file",
"nonexistent_file.txt",
])
.output()
.expect("Failed to execute command");
assert!(
!output.status.success(),
"Command should fail with nonexistent file"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("nonexistent_file.txt"),
"Error should mention the nonexistent file"
);
}