Flatten worktree tests module structure

This commit is contained in:
Max Brunsfeld 2023-06-13 10:31:29 -07:00
parent c17dbab6f1
commit 5b6d1a27ff

View file

@ -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,21 +927,13 @@ 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 {
use crate::{worktree::WorktreeHandle, Snapshot};
use super::*;
use collections::HashMap;
use fs::repository::GitFileStatus;
use pretty_assertions::assert_eq;
#[gpui::test] #[gpui::test]
async fn test_rename_work_directory(cx: &mut TestAppContext) { async fn test_rename_work_directory(cx: &mut TestAppContext) {
let root = temp_tree(json!({ let root = temp_tree(json!({
@ -1522,11 +1514,10 @@ mod git_tests {
#[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()
} }
}