use super::{GitRunner, RealGit};
use std::io;
use std::path::PathBuf;
use tempfile::TempDir;
#[test]
fn realgit_default_matches_new() {
let _ = RealGit::default();
}
#[test]
fn realgit_succeeds_on_valid_command() {
let holder = TempDir::new().unwrap();
RealGit::new()
.run(holder.path(), &["init", "-b", "main"])
.unwrap();
assert!(holder.path().join(".git").is_dir());
}
#[test]
fn realgit_returns_error_on_nonzero_exit() {
let holder = TempDir::new().unwrap();
let err = RealGit::new()
.run(holder.path(), &["status", "--porcelain"])
.unwrap_err();
let msg = err.to_string();
assert!(msg.contains("exited with"), "unexpected: {msg}");
}
#[test]
fn realgit_returns_error_when_binary_missing() {
let holder = TempDir::new().unwrap();
let git = RealGit {
bin: PathBuf::from("/no/such/lernie-test-git"),
};
let err = git.run(holder.path(), &["init"]).unwrap_err();
assert_eq!(err.kind(), io::ErrorKind::NotFound);
}
#[test]
fn realgit_run_capture_returns_stdout() {
let holder = TempDir::new().unwrap();
let out = RealGit::new()
.run_capture(holder.path(), &["--version"])
.unwrap();
assert!(out.starts_with("git "), "unexpected: {out:?}");
}