mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 11:42:56 +03:00
unittest for commiting
This commit is contained in:
parent
77719df650
commit
0657da58db
@ -82,3 +82,43 @@ pub fn stage_add(repo_path: &str, path: &Path) -> bool {
|
||||
|
||||
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 New Issue
Block a user