mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-02-03 10:14:13 +08:00
简化test util用法与名称,将head移入models
This commit is contained in:
@@ -2,7 +2,7 @@ use colored::Colorize;
|
||||
|
||||
use crate::{
|
||||
models::*,
|
||||
utils::{head, store, util},
|
||||
utils::{store, util},
|
||||
};
|
||||
|
||||
// branch error
|
||||
@@ -126,10 +126,10 @@ pub fn branch(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{commands, utils::test_util};
|
||||
use crate::{commands, utils::test};
|
||||
#[test]
|
||||
fn test_create_branch() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
|
||||
// no commit: invalid object
|
||||
let result = create_branch("test_branch".to_string(), head::current_head_commit());
|
||||
@@ -170,7 +170,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_delete_branch() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
|
||||
// no commit: invalid object
|
||||
let result = delete_branch("test_branch".to_string());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::*, utils::head};
|
||||
use crate::models::*;
|
||||
|
||||
use super::status;
|
||||
|
||||
@@ -38,33 +38,31 @@ pub fn commit(message: String, allow_empty: bool) {
|
||||
mod test {
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
commands as cmd, models,
|
||||
utils::{head, test_util},
|
||||
};
|
||||
use crate::models::head;
|
||||
use crate::{commands as cmd, models, utils::test};
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_commit_empty() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
super::commit("".to_string(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_commit() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let test_file = "a.txt";
|
||||
let head_one = head::current_head_commit();
|
||||
assert!(head_one.is_empty());
|
||||
|
||||
test_util::ensure_test_file(&Path::new(test_file), "test content".into());
|
||||
test::ensure_file(&Path::new(test_file), "test content".into());
|
||||
cmd::add(vec![], true, false);
|
||||
cmd::commit("test commit 1".to_string(), true);
|
||||
let head_two = head::current_head_commit();
|
||||
assert!(head_two.len() > 0);
|
||||
|
||||
let commit = models::commit::Commit::load(&head_two);
|
||||
assert!(commit.get_parent_hash().len() == 0);
|
||||
assert!(commit.get_message() == "test commit 1");
|
||||
assert_eq!(commit.get_parent_hash().len(), 0);
|
||||
assert_eq!(commit.get_message(), "test commit 1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::Commit, utils::head};
|
||||
use crate::models::{head, Commit};
|
||||
use colored::Colorize;
|
||||
|
||||
const DEFAULT_LOG_NUMBER: usize = 10;
|
||||
@@ -70,10 +70,10 @@ fn __log(all: bool, number: Option<usize>) -> usize {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::super::super::commands;
|
||||
use crate::utils::test_util;
|
||||
use crate::utils::test;
|
||||
#[test]
|
||||
fn test_log() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
assert_eq!(super::__log(false, None), 0);
|
||||
commands::commit::commit("test commit 2".into(), true);
|
||||
assert_eq!(super::__log(false, Some(1)), 1);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
commands::{self, status::*},
|
||||
models::{Commit, Hash},
|
||||
utils::{head, store, util},
|
||||
models::{head, Commit, Hash},
|
||||
utils::{store, util},
|
||||
};
|
||||
|
||||
enum MergeErr {
|
||||
@@ -83,12 +83,12 @@ mod test {
|
||||
use super::*;
|
||||
use crate::{
|
||||
commands::{commit, switch::switch},
|
||||
utils::test_util,
|
||||
utils::test,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_check_ff() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
commit::commit("init".to_string(), true);
|
||||
let commit1 = head::current_head_commit();
|
||||
let origin_branch = match head::current_head() {
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
models::*,
|
||||
utils::{head, store, util},
|
||||
utils::{store, util},
|
||||
};
|
||||
|
||||
fn restore_to_file(hash: &Hash, path: &PathBuf) {
|
||||
@@ -221,14 +221,14 @@ pub fn restore(paths: Vec<String>, source: Option<String>, worktree: bool, stage
|
||||
mod test {
|
||||
use std::fs;
|
||||
//TODO 写测试!
|
||||
use crate::{commands as cmd, commands::status, models::Index, utils::test_util};
|
||||
use crate::{commands as cmd, commands::status, models::Index, utils::test};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn test_restore_stage() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
let path = PathBuf::from("a.txt");
|
||||
test_util::ensure_no_file(&path);
|
||||
test::ensure_no_file(&path);
|
||||
cmd::add(vec![], true, false); //add -A
|
||||
cmd::restore(vec![".".to_string()], Some("HEAD".to_string()), false, true);
|
||||
let index = Index::get_instance();
|
||||
@@ -237,9 +237,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_restore_worktree() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
let files = vec!["a.txt", "b.txt", "c.txt", "test/in.txt"];
|
||||
test_util::ensure_test_files(&files);
|
||||
test::ensure_files(&files);
|
||||
|
||||
cmd::add(vec![], true, false);
|
||||
assert_eq!(status::changes_to_be_committed().new.iter().count(), 4);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::models::head;
|
||||
use crate::{
|
||||
models::{Blob, Commit, Index},
|
||||
utils::{head, util},
|
||||
utils::util,
|
||||
};
|
||||
use colored::Colorize;
|
||||
use std::path::PathBuf;
|
||||
@@ -202,14 +203,14 @@ pub fn status() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{commands as cmd, utils::test_util};
|
||||
use crate::{commands as cmd, utils::test};
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn test_changes_to_be_committed() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
let test_file = "a.txt";
|
||||
test_util::ensure_test_file(Path::new(test_file), None);
|
||||
test::ensure_file(Path::new(test_file), None);
|
||||
|
||||
cmd::commit("test commit".to_string(), true);
|
||||
cmd::add(vec![test_file.to_string()], false, false);
|
||||
@@ -221,7 +222,7 @@ mod tests {
|
||||
println!("{:?}", change.to_absolute());
|
||||
|
||||
cmd::commit("test commit".to_string(), true);
|
||||
test_util::ensure_test_file(Path::new(test_file), Some("new content"));
|
||||
test::ensure_file(Path::new(test_file), Some("new content"));
|
||||
cmd::add(vec![test_file.to_string()], false, false);
|
||||
let change = changes_to_be_committed();
|
||||
assert_eq!(change.new.len(), 0);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::{
|
||||
models::{Commit, Hash},
|
||||
utils::{head, store, util},
|
||||
models::{head, Commit, Hash},
|
||||
utils::{store, util},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -89,12 +89,12 @@ mod test {
|
||||
use super::*;
|
||||
use crate::{
|
||||
commands::{self as cmd},
|
||||
utils::test_util,
|
||||
utils::test,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
#[test]
|
||||
fn test_switch() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
|
||||
cmd::commit("init".to_string(), true);
|
||||
let test_branch_1 = "test_branch_1".to_string();
|
||||
@@ -102,7 +102,7 @@ mod test {
|
||||
|
||||
/* test 1: NoClean */
|
||||
let test_file_1 = PathBuf::from("test_file_1");
|
||||
test_util::ensure_test_file(&test_file_1, None);
|
||||
test::ensure_file(&test_file_1, None);
|
||||
cmd::add(vec![], true, false); // add all
|
||||
let result = switch_to(test_branch_1.clone(), false);
|
||||
assert!(result.is_err());
|
||||
@@ -123,12 +123,12 @@ mod test {
|
||||
assert!(matches!(result.unwrap_err(), SwitchErr::InvalidObject));
|
||||
|
||||
let tees_file_2 = PathBuf::from("test_file_2");
|
||||
test_util::ensure_test_file(&tees_file_2, None);
|
||||
test::ensure_file(&tees_file_2, None);
|
||||
cmd::add(vec![], true, false); // add all
|
||||
cmd::commit("add file 2".to_string(), false);
|
||||
let history_commit = head::current_head_commit(); // commit: test_file_1 exists, test_file_2 exists
|
||||
|
||||
test_util::ensure_no_file(&test_file_1);
|
||||
test::ensure_no_file(&test_file_1);
|
||||
cmd::add(vec![], true, false); // add all
|
||||
assert!(!test_file_1.exists());
|
||||
cmd::commit("delete file 1".to_string(), false);
|
||||
|
||||
@@ -70,11 +70,11 @@ impl Blob {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::utils::test_util;
|
||||
use crate::utils::test;
|
||||
|
||||
#[test]
|
||||
fn test_save_and_load() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let test_data = "hello world";
|
||||
let blob = super::Blob::new(test_data.into());
|
||||
|
||||
|
||||
@@ -83,11 +83,11 @@ impl Commit {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::utils::test_util;
|
||||
use crate::utils::test;
|
||||
|
||||
#[test]
|
||||
fn test_commit() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
|
||||
let index = super::Index::get_instance();
|
||||
let mut commit = super::Commit::new(&index, vec!["123".to_string(), "456".to_string()], "test".to_string());
|
||||
|
||||
@@ -113,12 +113,12 @@ pub fn change_head_to_commit(commit_hash: &String) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::utils::test_util;
|
||||
use crate::utils::head;
|
||||
use crate::models::head;
|
||||
use crate::utils::test;
|
||||
|
||||
#[test]
|
||||
fn test_edit_branch() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let branch_name = "test_branch".to_string() + &rand::random::<u32>().to_string();
|
||||
let branch_head = super::get_branch_head(&branch_name);
|
||||
assert!(branch_head.is_empty());
|
||||
@@ -132,7 +132,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_list_local_branches() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let branch_one = "test_branch".to_string() + &rand::random::<u32>().to_string();
|
||||
let branch_two = "test_branch".to_string() + &rand::random::<u32>().to_string();
|
||||
head::update_branch(&branch_one, &"1234567890".to_string());
|
||||
@@ -145,7 +145,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_change_head_to_branch() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let branch_name = "test_branch".to_string() + &rand::random::<u32>().to_string();
|
||||
head::update_branch(&branch_name, &"1234567890".to_string());
|
||||
super::change_head_to_branch(&branch_name);
|
||||
@@ -160,7 +160,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_change_head_to_commit() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let commit_hash = "1234567890".to_string();
|
||||
super::change_head_to_commit(&commit_hash);
|
||||
assert!(
|
||||
@@ -174,7 +174,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_update_branch_head() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let branch_name = "test_branch".to_string() + &rand::random::<u32>().to_string();
|
||||
let commit_hash = "1234567890".to_string();
|
||||
super::update_branch(&branch_name, &commit_hash);
|
||||
@@ -211,12 +211,12 @@ impl Index {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::utils::test_util;
|
||||
use crate::utils::test;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn test_meta_get() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let metadata = fs::metadata(".mit/HEAD").unwrap();
|
||||
println!("{:?}", util::format_time(&metadata.created().unwrap()));
|
||||
println!("{:?}", util::format_time(&metadata.modified().unwrap()));
|
||||
@@ -225,20 +225,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let index = Index::get_instance();
|
||||
println!("{:?}", index);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_save() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let index = Index::get_instance();
|
||||
let path = PathBuf::from("../mit_test_storage/.mit/HEAD"); //测试../相对路径的处理
|
||||
index.add(path.clone(), FileMetaData::new(&Blob::new(util::read_workfile(&path)), &path));
|
||||
|
||||
let 中文路径 = "中文路径.txt";
|
||||
test_util::ensure_test_file(Path::new(中文路径), None);
|
||||
test::ensure_file(Path::new(中文路径), None);
|
||||
let path = PathBuf::from(中文路径);
|
||||
index.add(path.clone(), FileMetaData::new(&Blob::new(util::read_workfile(&path)), &path));
|
||||
index.save();
|
||||
@@ -247,7 +247,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_save_load() {
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
test::setup_with_empty_workdir();
|
||||
let index = Index::get_instance();
|
||||
let path = PathBuf::from(".mit/HEAD");
|
||||
index.add(path.clone(), FileMetaData::new(&Blob::new(util::read_workfile(&path)), &path));
|
||||
|
||||
@@ -7,5 +7,7 @@ pub use index::FileMetaData;
|
||||
pub use index::Index;
|
||||
pub mod object;
|
||||
pub use object::Hash;
|
||||
pub mod head;
|
||||
pub mod tree;
|
||||
|
||||
pub use tree::Tree;
|
||||
|
||||
@@ -137,16 +137,16 @@ mod test {
|
||||
|
||||
use crate::{
|
||||
models::*,
|
||||
utils::{test_util, util},
|
||||
utils::{test, util},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let index = Index::get_instance();
|
||||
for test_file in vec!["b.txt", "mit_src/a.txt", "test/test.txt"] {
|
||||
let test_file = PathBuf::from(test_file);
|
||||
test_util::ensure_test_file(&test_file, None);
|
||||
test::ensure_file(&test_file, None);
|
||||
index.add(test_file.clone(), FileMetaData::new(&Blob::new(util::read_workfile(&test_file)), &test_file));
|
||||
}
|
||||
|
||||
@@ -157,12 +157,12 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_load() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let index = Index::get_instance();
|
||||
let test_files = vec!["b.txt", "mit_src/a.txt"];
|
||||
for test_file in test_files.clone() {
|
||||
let test_file = PathBuf::from(test_file);
|
||||
test_util::ensure_test_file(&test_file, None);
|
||||
test::ensure_file(&test_file, None);
|
||||
index.add(test_file.clone(), FileMetaData::new(&Blob::new(util::read_workfile(&test_file)), &test_file));
|
||||
}
|
||||
|
||||
@@ -177,13 +177,13 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_get_recursive_blobs() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let index = Index::get_instance();
|
||||
let test_files = vec!["b.txt", "mit_src/a.txt"];
|
||||
let mut test_blobs = vec![];
|
||||
for test_file in test_files.clone() {
|
||||
let test_file = PathBuf::from(test_file);
|
||||
test_util::ensure_test_file(&test_file, None);
|
||||
test::ensure_file(&test_file, None);
|
||||
let blob = Blob::new(util::read_workfile(&test_file));
|
||||
test_blobs.push(blob.clone());
|
||||
index.add(test_file.clone(), FileMetaData::new(&Blob::new(util::read_workfile(&test_file)), &test_file));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod util;
|
||||
pub mod head;
|
||||
pub mod store;
|
||||
pub mod test_util;
|
||||
pub mod test;
|
||||
pub mod util;
|
||||
|
||||
@@ -93,24 +93,24 @@ mod tests {
|
||||
use std::fs;
|
||||
|
||||
use super::*;
|
||||
use crate::utils::test_util;
|
||||
use crate::utils::test;
|
||||
|
||||
#[test]
|
||||
fn test_new_success() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let _ = Store::new();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_new_fail() {
|
||||
test_util::setup_test_without_mit();
|
||||
test::setup_without_mit();
|
||||
let _ = Store::new();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_save_and_load() {
|
||||
let _ = test_util::setup_test_with_clean_mit();
|
||||
let _ = test::setup_with_clean_mit();
|
||||
let store = Store::new();
|
||||
let content = "hello world".to_string();
|
||||
let hash = store.save(&content);
|
||||
@@ -120,7 +120,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_search() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let hashs = vec!["1234567890".to_string(), "1235467891".to_string(), "4567892".to_string()];
|
||||
for hash in hashs.iter() {
|
||||
let mut path = util::get_storage_path().unwrap();
|
||||
|
||||
@@ -34,7 +34,7 @@ fn find_cargo_dir() -> PathBuf {
|
||||
}
|
||||
|
||||
/// 准备测试环境,切换到测试目录
|
||||
fn setup_test_env() {
|
||||
fn setup_env() {
|
||||
color_backtrace::install(); // colorize backtrace
|
||||
|
||||
let mut path = find_cargo_dir();
|
||||
@@ -51,14 +51,14 @@ pub fn init_mit() {
|
||||
}
|
||||
|
||||
/// with 初始化的干净的mit
|
||||
pub fn setup_test_with_clean_mit() {
|
||||
setup_test_without_mit();
|
||||
pub fn setup_with_clean_mit() {
|
||||
setup_without_mit();
|
||||
init_mit();
|
||||
}
|
||||
|
||||
pub fn setup_test_without_mit() {
|
||||
pub fn setup_without_mit() {
|
||||
// 将执行目录切换到测试目录,并清除测试目录下的.mit目录
|
||||
setup_test_env();
|
||||
setup_env();
|
||||
let mut path = util::cur_dir();
|
||||
path.push(util::ROOT_DIR);
|
||||
if path.exists() {
|
||||
@@ -66,9 +66,9 @@ pub fn setup_test_without_mit() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ensure_test_files<T: AsRef<str>>(paths: &Vec<T>) {
|
||||
pub fn ensure_files<T: AsRef<str>>(paths: &Vec<T>) {
|
||||
for path in paths {
|
||||
ensure_test_file(path.as_ref().as_ref(), None);
|
||||
ensure_file(path.as_ref().as_ref(), None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,13 +85,13 @@ pub fn ensure_empty_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn setup_test_with_empty_workdir() {
|
||||
pub fn setup_with_empty_workdir() {
|
||||
let test_dir = find_cargo_dir().join(TEST_DIR);
|
||||
ensure_empty_dir(&test_dir).unwrap();
|
||||
setup_test_with_clean_mit();
|
||||
setup_with_clean_mit();
|
||||
}
|
||||
|
||||
pub fn ensure_test_file(path: &Path, content: Option<&str>) {
|
||||
pub fn ensure_file(path: &Path, content: Option<&str>) {
|
||||
// 以测试目录为根目录,创建文件
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap(); // ensure父目录
|
||||
let mut file = fs::File::create(util::get_working_dir().unwrap().join(path))
|
||||
@@ -112,7 +112,7 @@ pub fn ensure_no_file(path: &Path) {
|
||||
}
|
||||
|
||||
/** 列出子文件夹 */
|
||||
pub fn list_subpath(path: &Path) -> io::Result<Vec<PathBuf>> {
|
||||
pub fn list_subdir(path: &Path) -> io::Result<Vec<PathBuf>> {
|
||||
let mut files = Vec::new();
|
||||
let path = util::get_absolute_path(path);
|
||||
if path.is_dir() {
|
||||
@@ -125,4 +125,4 @@ pub fn list_subpath(path: &Path) -> io::Result<Vec<PathBuf>> {
|
||||
}
|
||||
}
|
||||
Ok(files)
|
||||
}
|
||||
}
|
||||
@@ -392,7 +392,7 @@ mod tests {
|
||||
use crate::{
|
||||
models::{blob::Blob, index::Index},
|
||||
utils::{
|
||||
test_util,
|
||||
test,
|
||||
util::{self, *},
|
||||
},
|
||||
};
|
||||
@@ -437,7 +437,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_relative_path() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let path = Path::new("../../src\\main.rs");
|
||||
let rel_path = get_relative_path(&path, &cur_dir());
|
||||
println!("{:?}", rel_path);
|
||||
@@ -447,7 +447,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_to_workdir_absolute_path() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
let path = Path::new("./src/../main.rs");
|
||||
let abs_path = to_workdir_absolute_path(path);
|
||||
println!("{:?}", abs_path);
|
||||
@@ -467,10 +467,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_list_files() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test_util::ensure_test_file(Path::new("test/test.txt"), None);
|
||||
test_util::ensure_test_file(Path::new("a.txt"), None);
|
||||
test_util::ensure_test_file(Path::new("b.txt"), None);
|
||||
test::setup_with_clean_mit();
|
||||
test::ensure_file(Path::new("test/test.txt"), None);
|
||||
test::ensure_file(Path::new("a.txt"), None);
|
||||
test::ensure_file(Path::new("b.txt"), None);
|
||||
let files = list_files(Path::new("./"));
|
||||
match files {
|
||||
Ok(files) => {
|
||||
@@ -486,9 +486,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_check_object_type() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
assert_eq!(check_object_type("123".into()), ObjectType::Invalid);
|
||||
test_util::ensure_test_file(Path::new("test.txt"), Some("test"));
|
||||
test::ensure_file(Path::new("test.txt"), Some("test"));
|
||||
let content = util::read_workfile(get_working_dir().unwrap().join("test.txt").as_path());
|
||||
let hash = Blob::new(content).get_hash();
|
||||
assert_eq!(check_object_type(hash), ObjectType::Blob);
|
||||
@@ -500,11 +500,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_check_root_dir() {
|
||||
test_util::setup_test_with_clean_mit();
|
||||
test::setup_with_clean_mit();
|
||||
list_workdir_files().iter().for_each(|f| {
|
||||
fs::remove_file(f).unwrap();
|
||||
});
|
||||
test_util::list_subpath(Path::new("./")).unwrap().iter().for_each(|f| {
|
||||
test::list_subdir(Path::new("./")).unwrap().iter().for_each(|f| {
|
||||
if include_root_dir(f) {
|
||||
fs::remove_dir_all(f).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user