mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
unittest for commiting
This commit is contained in:
parent
77719df650
commit
0657da58db
1 changed files with 40 additions and 0 deletions
|
|
@ -82,3 +82,43 @@ pub fn stage_add(repo_path: &str, path: &Path) -> bool {
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::sync::{
|
||||||
|
stage_add,
|
||||||
|
status::{get_status, StatusType},
|
||||||
|
tests::repo_init,
|
||||||
|
};
|
||||||
|
use std::{fs::File, io::Write, path::Path};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_commit() {
|
||||||
|
let file_path = Path::new("foo");
|
||||||
|
let (_td, repo) = repo_init();
|
||||||
|
let root = repo.path().parent().unwrap();
|
||||||
|
let repo_path = root.as_os_str().to_str().unwrap();
|
||||||
|
|
||||||
|
let status_count = |s: StatusType| -> usize {
|
||||||
|
get_status(repo_path, s).len()
|
||||||
|
};
|
||||||
|
|
||||||
|
File::create(&root.join(file_path))
|
||||||
|
.unwrap()
|
||||||
|
.write_all(b"test\nfoo")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(status_count(StatusType::WorkingDir), 1);
|
||||||
|
|
||||||
|
assert_eq!(stage_add(repo_path, file_path), true);
|
||||||
|
|
||||||
|
assert_eq!(status_count(StatusType::WorkingDir), 0);
|
||||||
|
assert_eq!(status_count(StatusType::Stage), 1);
|
||||||
|
|
||||||
|
commit(repo_path, "commit msg");
|
||||||
|
|
||||||
|
assert_eq!(status_count(StatusType::Stage), 0);
|
||||||
|
assert_eq!(status_count(StatusType::WorkingDir), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue