mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-04-29 13:19:44 +08:00
将test的util函数移动到test宏下,去除unused警告
This commit is contained in:
@@ -126,10 +126,10 @@ pub fn branch(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::{commands, utils::util};
|
||||
use crate::{commands, utils::util::test_util};
|
||||
#[test]
|
||||
fn test_create_branch() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_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() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_with_clean_mit();
|
||||
|
||||
// no commit: invalid object
|
||||
let result = delete_branch("test_branch".to_string());
|
||||
|
||||
@@ -38,24 +38,27 @@ pub fn commit(message: String, allow_empty: bool) {
|
||||
mod test {
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{commands as cmd, utils::head, models, utils::util};
|
||||
use crate::{
|
||||
commands as cmd, models,
|
||||
utils::{head, util::test_util},
|
||||
};
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_commit_empty() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_with_clean_mit();
|
||||
|
||||
super::commit("".to_string(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_commit() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_with_clean_mit();
|
||||
let test_file = "a.txt";
|
||||
let head_one = head::current_head_commit();
|
||||
assert!(head_one.is_empty());
|
||||
|
||||
util::ensure_test_file(&Path::new(test_file), "test content".into());
|
||||
test_util::ensure_test_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();
|
||||
|
||||
@@ -70,10 +70,10 @@ fn __log(all: bool, number: Option<usize>) -> usize {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::super::super::commands;
|
||||
use crate::utils::util;
|
||||
use crate::utils::util::test_util;
|
||||
#[test]
|
||||
fn test_log() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_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);
|
||||
|
||||
@@ -82,12 +82,14 @@ pub fn merge(branch: String) {
|
||||
mod test {
|
||||
use std::fs;
|
||||
|
||||
use crate::commands::{commit, switch::switch};
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
commands::{commit, switch::switch},
|
||||
utils::util::test_util,
|
||||
};
|
||||
#[test]
|
||||
fn test_check_ff() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_with_clean_mit();
|
||||
util::list_workdir_files().iter().for_each(|x| fs::remove_file(x).unwrap());
|
||||
|
||||
commit::commit("init".to_string(), true);
|
||||
|
||||
@@ -217,14 +217,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::util};
|
||||
use crate::{commands as cmd, commands::status, models::Index, utils::util::test_util};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn test_restore_stage() {
|
||||
util::setup_test_with_empty_workdir();
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
let path = PathBuf::from("a.txt");
|
||||
util::ensure_no_file(&path);
|
||||
test_util::ensure_no_file(&path);
|
||||
cmd::add(vec![], true, false); //add -A
|
||||
cmd::restore(vec![".".to_string()], Some("HEAD".to_string()), false, true);
|
||||
assert!(Index::get_instance().is_empty());
|
||||
@@ -232,9 +232,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_restore_worktree() {
|
||||
util::setup_test_with_empty_workdir();
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
let files = vec!["a.txt", "b.txt", "c.txt", "test/in.txt"];
|
||||
util::ensure_test_files(&files);
|
||||
test_util::ensure_test_files(&files);
|
||||
|
||||
cmd::add(vec![], true, false);
|
||||
assert_eq!(status::changes_to_be_committed().new.iter().count(), 4);
|
||||
|
||||
@@ -196,14 +196,14 @@ pub fn status() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{commands as cmd, utils::util};
|
||||
use crate::{commands as cmd, utils::util::test_util};
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn test_changes_to_be_committed() {
|
||||
util::setup_test_with_clean_mit();
|
||||
test_util::setup_test_with_clean_mit();
|
||||
let test_file = "a.txt";
|
||||
util::ensure_test_file(Path::new(test_file), None);
|
||||
test_util::ensure_test_file(Path::new(test_file), None);
|
||||
|
||||
cmd::commit("test commit".to_string(), true);
|
||||
cmd::add(vec![test_file.to_string()], false, false);
|
||||
@@ -215,7 +215,7 @@ mod tests {
|
||||
println!("{:?}", change.to_absolute());
|
||||
|
||||
cmd::commit("test commit".to_string(), true);
|
||||
util::ensure_test_file(Path::new(test_file), Some("new content"));
|
||||
test_util::ensure_test_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,10 +1,8 @@
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::{
|
||||
utils::head,
|
||||
models::{Commit, Hash},
|
||||
utils::store,
|
||||
utils::util,
|
||||
utils::{head, store, util},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -86,11 +84,14 @@ pub fn switch(target_branch: Option<String>, create: Option<String>, detach: boo
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::commands::{self as cmd};
|
||||
use crate::{
|
||||
commands::{self as cmd},
|
||||
utils::util::test_util,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
#[test]
|
||||
fn test_switch() {
|
||||
util::setup_test_with_empty_workdir();
|
||||
test_util::setup_test_with_empty_workdir();
|
||||
|
||||
cmd::commit("init".to_string(), true);
|
||||
let test_branch_1 = "test_branch_1".to_string();
|
||||
@@ -98,7 +99,7 @@ mod test {
|
||||
|
||||
/* test 1: NoClean */
|
||||
let test_file_1 = PathBuf::from("test_file_1");
|
||||
util::ensure_test_file(&test_file_1, None);
|
||||
test_util::ensure_test_file(&test_file_1, None);
|
||||
let result = switch_to(test_branch_1.clone(), false);
|
||||
assert!(result.is_err());
|
||||
assert!(matches!(result.unwrap_err(), SwitchErr::NoClean));
|
||||
@@ -119,12 +120,12 @@ mod test {
|
||||
assert!(matches!(result.unwrap_err(), SwitchErr::InvalidObject));
|
||||
|
||||
let tees_file_2 = PathBuf::from("test_file_2");
|
||||
util::ensure_test_file(&tees_file_2, None);
|
||||
test_util::ensure_test_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
|
||||
|
||||
util::ensure_no_file(&test_file_1);
|
||||
test_util::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);
|
||||
|
||||
Reference in New Issue
Block a user