mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
Flatten worktree tests module structure
This commit is contained in:
parent
c17dbab6f1
commit
5b6d1a27ff
1 changed files with 579 additions and 588 deletions
|
@ -1,10 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
worktree::{Event, WorktreeHandle},
|
worktree::{Event, Snapshot, WorktreeHandle},
|
||||||
EntryKind, PathChange, Worktree,
|
EntryKind, PathChange, Worktree,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use client::Client;
|
use client::Client;
|
||||||
use fs::{FakeFs, Fs, RealFs, RemoveOptions};
|
use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};
|
||||||
use git::GITIGNORE;
|
use git::GITIGNORE;
|
||||||
use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext};
|
use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
@ -728,9 +728,9 @@ fn randomly_mutate_worktree(
|
||||||
} else {
|
} else {
|
||||||
other_entry.path.parent().unwrap().into()
|
other_entry.path.parent().unwrap().into()
|
||||||
};
|
};
|
||||||
let mut new_path = new_parent_path.join(gen_name(rng));
|
let mut new_path = new_parent_path.join(random_filename(rng));
|
||||||
if new_path.starts_with(&entry.path) {
|
if new_path.starts_with(&entry.path) {
|
||||||
new_path = gen_name(rng).into();
|
new_path = random_filename(rng).into();
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
@ -747,7 +747,7 @@ fn randomly_mutate_worktree(
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let task = if entry.is_dir() {
|
let task = if entry.is_dir() {
|
||||||
let child_path = entry.path.join(gen_name(rng));
|
let child_path = entry.path.join(random_filename(rng));
|
||||||
let is_dir = rng.gen_bool(0.3);
|
let is_dir = rng.gen_bool(0.3);
|
||||||
log::info!(
|
log::info!(
|
||||||
"creating {} at {:?}",
|
"creating {} at {:?}",
|
||||||
|
@ -788,7 +788,7 @@ async fn randomly_mutate_fs(
|
||||||
|
|
||||||
if (files.is_empty() && dirs.len() == 1) || rng.gen_bool(insertion_probability) {
|
if (files.is_empty() && dirs.len() == 1) || rng.gen_bool(insertion_probability) {
|
||||||
let path = dirs.choose(rng).unwrap();
|
let path = dirs.choose(rng).unwrap();
|
||||||
let new_path = path.join(gen_name(rng));
|
let new_path = path.join(random_filename(rng));
|
||||||
|
|
||||||
if rng.gen() {
|
if rng.gen() {
|
||||||
log::info!(
|
log::info!(
|
||||||
|
@ -880,7 +880,7 @@ async fn randomly_mutate_fs(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
new_path_parent.to_path_buf()
|
new_path_parent.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
new_path_parent.join(gen_name(rng))
|
new_path_parent.join(random_filename(rng))
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
@ -927,23 +927,15 @@ async fn randomly_mutate_fs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_name(rng: &mut impl Rng) -> String {
|
fn random_filename(rng: &mut impl Rng) -> String {
|
||||||
(0..6)
|
(0..6)
|
||||||
.map(|_| rng.sample(rand::distributions::Alphanumeric))
|
.map(|_| rng.sample(rand::distributions::Alphanumeric))
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
mod git_tests {
|
#[gpui::test]
|
||||||
use crate::{worktree::WorktreeHandle, Snapshot};
|
async fn test_rename_work_directory(cx: &mut TestAppContext) {
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use collections::HashMap;
|
|
||||||
use fs::repository::GitFileStatus;
|
|
||||||
use pretty_assertions::assert_eq;
|
|
||||||
|
|
||||||
#[gpui::test]
|
|
||||||
async fn test_rename_work_directory(cx: &mut TestAppContext) {
|
|
||||||
let root = temp_tree(json!({
|
let root = temp_tree(json!({
|
||||||
"projects": {
|
"projects": {
|
||||||
"project1": {
|
"project1": {
|
||||||
|
@ -1012,10 +1004,10 @@ mod git_tests {
|
||||||
Some(GitFileStatus::Added)
|
Some(GitFileStatus::Added)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_git_repository_for_path(cx: &mut TestAppContext) {
|
async fn test_git_repository_for_path(cx: &mut TestAppContext) {
|
||||||
let root = temp_tree(json!({
|
let root = temp_tree(json!({
|
||||||
"c.txt": "",
|
"c.txt": "",
|
||||||
"dir1": {
|
"dir1": {
|
||||||
|
@ -1134,10 +1126,10 @@ mod git_tests {
|
||||||
.repository_for_path("dir1/src/b.txt".as_ref())
|
.repository_for_path("dir1/src/b.txt".as_ref())
|
||||||
.is_none());
|
.is_none());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_git_status(deterministic: Arc<Deterministic>, cx: &mut TestAppContext) {
|
async fn test_git_status(deterministic: Arc<Deterministic>, cx: &mut TestAppContext) {
|
||||||
const IGNORE_RULE: &'static str = "**/target";
|
const IGNORE_RULE: &'static str = "**/target";
|
||||||
|
|
||||||
let root = temp_tree(json!({
|
let root = temp_tree(json!({
|
||||||
|
@ -1324,10 +1316,10 @@ mod git_tests {
|
||||||
Some(GitFileStatus::Added)
|
Some(GitFileStatus::Added)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_propagate_git_statuses(cx: &mut TestAppContext) {
|
async fn test_propagate_git_statuses(cx: &mut TestAppContext) {
|
||||||
let fs = FakeFs::new(cx.background());
|
let fs = FakeFs::new(cx.background());
|
||||||
fs.insert_tree(
|
fs.insert_tree(
|
||||||
"/root",
|
"/root",
|
||||||
|
@ -1445,30 +1437,30 @@ mod git_tests {
|
||||||
expected_statuses
|
expected_statuses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_init(path: &Path) -> git2::Repository {
|
fn git_init(path: &Path) -> git2::Repository {
|
||||||
git2::Repository::init(path).expect("Failed to initialize git repository")
|
git2::Repository::init(path).expect("Failed to initialize git repository")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_add<P: AsRef<Path>>(path: P, repo: &git2::Repository) {
|
fn git_add<P: AsRef<Path>>(path: P, repo: &git2::Repository) {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let mut index = repo.index().expect("Failed to get index");
|
let mut index = repo.index().expect("Failed to get index");
|
||||||
index.add_path(path).expect("Failed to add a.txt");
|
index.add_path(path).expect("Failed to add a.txt");
|
||||||
index.write().expect("Failed to write index");
|
index.write().expect("Failed to write index");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_remove_index(path: &Path, repo: &git2::Repository) {
|
fn git_remove_index(path: &Path, repo: &git2::Repository) {
|
||||||
let mut index = repo.index().expect("Failed to get index");
|
let mut index = repo.index().expect("Failed to get index");
|
||||||
index.remove_path(path).expect("Failed to add a.txt");
|
index.remove_path(path).expect("Failed to add a.txt");
|
||||||
index.write().expect("Failed to write index");
|
index.write().expect("Failed to write index");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_commit(msg: &'static str, repo: &git2::Repository) {
|
fn git_commit(msg: &'static str, repo: &git2::Repository) {
|
||||||
use git2::Signature;
|
use git2::Signature;
|
||||||
|
|
||||||
let signature = Signature::now("test", "test@zed.dev").unwrap();
|
let signature = Signature::now("test", "test@zed.dev").unwrap();
|
||||||
|
@ -1492,19 +1484,19 @@ mod git_tests {
|
||||||
repo.commit(Some("HEAD"), &signature, &signature, msg, &tree, &[])
|
repo.commit(Some("HEAD"), &signature, &signature, msg, &tree, &[])
|
||||||
.expect("Failed to commit");
|
.expect("Failed to commit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_stash(repo: &mut git2::Repository) {
|
fn git_stash(repo: &mut git2::Repository) {
|
||||||
use git2::Signature;
|
use git2::Signature;
|
||||||
|
|
||||||
let signature = Signature::now("test", "test@zed.dev").unwrap();
|
let signature = Signature::now("test", "test@zed.dev").unwrap();
|
||||||
repo.stash_save(&signature, "N/A", None)
|
repo.stash_save(&signature, "N/A", None)
|
||||||
.expect("Failed to stash");
|
.expect("Failed to stash");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_reset(offset: usize, repo: &git2::Repository) {
|
fn git_reset(offset: usize, repo: &git2::Repository) {
|
||||||
let head = repo.head().expect("Couldn't get repo head");
|
let head = repo.head().expect("Couldn't get repo head");
|
||||||
let object = head.peel(git2::ObjectType::Commit).unwrap();
|
let object = head.peel(git2::ObjectType::Commit).unwrap();
|
||||||
let commit = object.as_commit().unwrap();
|
let commit = object.as_commit().unwrap();
|
||||||
|
@ -1518,15 +1510,14 @@ mod git_tests {
|
||||||
.expect("Not enough history");
|
.expect("Not enough history");
|
||||||
repo.reset(&new_head.as_object(), git2::ResetType::Soft, None)
|
repo.reset(&new_head.as_object(), git2::ResetType::Soft, None)
|
||||||
.expect("Could not reset");
|
.expect("Could not reset");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn git_status(repo: &git2::Repository) -> HashMap<String, git2::Status> {
|
fn git_status(repo: &git2::Repository) -> collections::HashMap<String, git2::Status> {
|
||||||
repo.statuses(None)
|
repo.statuses(None)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|status| (status.path().unwrap().to_string(), status.status()))
|
.map(|status| (status.path().unwrap().to_string(), status.status()))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue