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::{
worktree::{Event, WorktreeHandle},
worktree::{Event, Snapshot, WorktreeHandle},
EntryKind, PathChange, Worktree,
};
use anyhow::Result;
use client::Client;
use fs::{FakeFs, Fs, RealFs, RemoveOptions};
use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};
use git::GITIGNORE;
use gpui::{executor::Deterministic, ModelContext, Task, TestAppContext};
use parking_lot::Mutex;
@ -728,9 +728,9 @@ fn randomly_mutate_worktree(
} else {
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) {
new_path = gen_name(rng).into();
new_path = random_filename(rng).into();
}
log::info!(
@ -747,7 +747,7 @@ fn randomly_mutate_worktree(
}
_ => {
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);
log::info!(
"creating {} at {:?}",
@ -788,7 +788,7 @@ async fn randomly_mutate_fs(
if (files.is_empty() && dirs.len() == 1) || rng.gen_bool(insertion_probability) {
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() {
log::info!(
@ -880,7 +880,7 @@ async fn randomly_mutate_fs(
.unwrap();
new_path_parent.to_path_buf()
} else {
new_path_parent.join(gen_name(rng))
new_path_parent.join(random_filename(rng))
};
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)
.map(|_| rng.sample(rand::distributions::Alphanumeric))
.map(char::from)
.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]
async fn test_rename_work_directory(cx: &mut TestAppContext) {
let root = temp_tree(json!({
@ -1522,11 +1514,10 @@ mod git_tests {
#[allow(dead_code)]
#[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)
.unwrap()
.iter()
.map(|status| (status.path().unwrap().to_string(), status.status()))
.collect()
}
}