use assert_cmd::prelude::*; use std::process::Command;
#[test]
fn test_init_with_no_args() {
let mut cmd = Command::cargo_bin("r_git").expect("Failed to build binary");
cmd.arg("init").assert().success();
assert!(std::path::Path::new(".rgit").exists());
assert!(std::path::Path::new(".rgit/objects").exists());
assert!(std::path::Path::new(".rgit/refs/heads").exists());
assert!(std::path::Path::new(".rgit/HEAD").exists());
let head_content = std::fs::read_to_string(".rgit/HEAD").expect("Failed to read HEAD file");
assert_eq!(head_content, "ref: refs/heads/master\n");
std::fs::remove_dir_all(".rgit").expect("Failed to remove .rgit directory");
}
#[test]
fn test_init_with_args() {
let mut cmd = Command::cargo_bin("r_git").expect("Failed to build binary");
cmd.arg("init").arg("sub_path").assert().success();
assert!(std::path::Path::new("sub_path/.rgit").exists());
assert!(std::path::Path::new("sub_path/.rgit/objects").exists());
assert!(std::path::Path::new("sub_path/.rgit/refs/heads").exists());
assert!(std::path::Path::new("sub_path/.rgit/HEAD").exists());
let head_content =
std::fs::read_to_string("sub_path/.rgit/HEAD").expect("Failed to read HEAD file");
assert_eq!(head_content, "ref: refs/heads/master\n");
std::fs::remove_dir_all("sub_path/").expect("Failed to remove .rgit directory");
}