use rdd::Dd;
use std::fs;
use std::path::Path;
#[test]
fn dd_spawn_with_files() {
let input_file = "tests/input.txt";
let output_file = "tests/output.txt";
if !Path::new(input_file).exists() {
fs::write(input_file, b"Hello, dd testing!\n").expect("Failed to create input.txt");
}
if Path::new(output_file).exists() {
fs::remove_file(output_file).expect("Failed to remove output.txt");
}
let result = Dd::new("dd")
.input(input_file)
.output(output_file)
.bs("1M")
.count(1)
.status("none")
.spawn();
if result.is_err() {
eprintln!("{}", result.as_ref().unwrap_err());
}
assert!(result.is_ok(), "dd command failed");
assert!(
Path::new(output_file).exists(),
"Output file does not exist"
);
let output_content = fs::read_to_string(output_file).expect("Failed to read output.txt");
assert!(
output_content.contains("Hello, dd testing!"),
"Output does not contain the expected text"
);
}