use std::{env, fs, process::Command};
use tempfile::TempDir;
#[test]
fn test_justfile_creation() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let original_dir = env::current_dir().expect("Failed to get current dir");
let output = Command::new("cargo")
.args([
"run",
"--bin",
"justrs",
"--manifest-path",
&format!("{}/Cargo.toml", original_dir.display()),
])
.current_dir(temp_dir.path())
.output()
.expect("Failed to run justrs");
assert!(
output.status.success(),
"Program should execute successfully. stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
let justfile_path = temp_dir.path().join("justfile");
assert!(justfile_path.exists(), "justfile should be created");
let content = fs::read_to_string(&justfile_path).expect("Failed to read justfile");
assert!(
content.contains("project_name :="),
"justfile should contain project_name variable"
);
assert!(
content.contains("# cargo run"),
"justfile should contain run recipe"
);
}
#[test]
fn test_justfile_template_validity() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let original_dir = env::current_dir().expect("Failed to get current dir");
let _ = Command::new("cargo")
.args([
"run",
"--bin",
"justrs",
"--manifest-path",
&format!("{}/Cargo.toml", original_dir.display()),
])
.current_dir(temp_dir.path())
.output()
.expect("Failed to run justrs");
let just_output = Command::new("just")
.args(["-l", "--unstable"])
.current_dir(temp_dir.path())
.output();
if let Ok(output) = just_output {
assert!(
output.status.success(),
"Generated justfile should be valid. stderr: {}",
String::from_utf8_lossy(&output.stderr)
);
}
}