Add a test-support feature flag that enables compilation of zed::test module
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
a57cb2b189
commit
efc8bc3124
+13
-8
@@ -13,6 +13,9 @@ path = "src/lib.rs"
|
||||
name = "Zed"
|
||||
path = "src/main.rs"
|
||||
|
||||
[features]
|
||||
test-support = ["tempdir", "serde_json"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.38"
|
||||
arrayvec = "0.5.2"
|
||||
@@ -20,9 +23,9 @@ crossbeam-channel = "0.5.0"
|
||||
ctor = "0.1.20"
|
||||
dirs = "3.0"
|
||||
easy-parallel = "3.1.0"
|
||||
fsevent = { path="../fsevent" }
|
||||
fsevent = {path = "../fsevent"}
|
||||
futures = "0.3"
|
||||
gpui = { path="../gpui" }
|
||||
gpui = {path = "../gpui"}
|
||||
http-auth-basic = "0.1.3"
|
||||
ignore = "0.4"
|
||||
lazy_static = "1.4.0"
|
||||
@@ -30,29 +33,31 @@ libc = "0.2"
|
||||
log = "0.4"
|
||||
num_cpus = "1.13.0"
|
||||
parking_lot = "0.11.1"
|
||||
postage = { version="0.4.1", features=["futures-traits"] }
|
||||
postage = {version = "0.4.1", features = ["futures-traits"]}
|
||||
rand = "0.8.3"
|
||||
rsa = "0.4"
|
||||
rust-embed = "5.9.0"
|
||||
seahash = "4.1"
|
||||
serde = { version="1", features=["derive"] }
|
||||
serde = {version = "1", features = ["derive"]}
|
||||
serde_json = {version = "1.0.64", features = ["preserve_order"], optional = true}
|
||||
similar = "1.3"
|
||||
simplelog = "0.9"
|
||||
smallvec = { version="1.6", features=["union"] }
|
||||
smallvec = {version = "1.6", features = ["union"]}
|
||||
smol = "1.2.5"
|
||||
surf = "2.2"
|
||||
tempdir = {version = "0.3.7", optional = true}
|
||||
tiny_http = "0.8"
|
||||
toml = "0.5"
|
||||
tree-sitter = "0.19.5"
|
||||
tree-sitter-rust = "0.19.0"
|
||||
url = "2.2"
|
||||
zed-rpc = { path="../zed-rpc" }
|
||||
zed-rpc = {path = "../zed-rpc"}
|
||||
|
||||
[dev-dependencies]
|
||||
cargo-bundle = "0.5.0"
|
||||
env_logger = "0.8"
|
||||
serde_json = { version="1.0.64", features=["preserve_order"] }
|
||||
tempdir = "0.3.7"
|
||||
serde_json = {version = "1.0.64", features = ["preserve_order"]}
|
||||
tempdir = {version = "0.3.7"}
|
||||
unindent = "0.1.7"
|
||||
|
||||
[package.metadata.bundle]
|
||||
|
||||
+3
-3
@@ -7,12 +7,12 @@ mod operation_queue;
|
||||
pub mod rpc;
|
||||
pub mod settings;
|
||||
mod sum_tree;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub mod test;
|
||||
mod time;
|
||||
mod util;
|
||||
pub mod workspace;
|
||||
mod worktree;
|
||||
pub mod worktree;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
|
||||
+8
-14
@@ -1,15 +1,13 @@
|
||||
use crate::{language::LanguageRegistry, rpc, settings, time::ReplicaId, AppState};
|
||||
use ctor::ctor;
|
||||
use gpui::AppContext;
|
||||
use rand::Rng;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use tempdir::TempDir;
|
||||
|
||||
#[ctor]
|
||||
#[cfg(test)]
|
||||
#[ctor::ctor]
|
||||
fn init_logger() {
|
||||
env_logger::init();
|
||||
}
|
||||
@@ -20,15 +18,17 @@ struct Envelope<T: Clone> {
|
||||
sender: ReplicaId,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) struct Network<T: Clone> {
|
||||
inboxes: BTreeMap<ReplicaId, Vec<Envelope<T>>>,
|
||||
inboxes: std::collections::BTreeMap<ReplicaId, Vec<Envelope<T>>>,
|
||||
all_messages: Vec<T>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<T: Clone> Network<T> {
|
||||
pub fn new() -> Self {
|
||||
Network {
|
||||
inboxes: BTreeMap::new(),
|
||||
inboxes: Default::default(),
|
||||
all_messages: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,7 @@ impl<T: Clone> Network<T> {
|
||||
self.inboxes.values().all(|i| i.is_empty())
|
||||
}
|
||||
|
||||
pub fn broadcast<R>(&mut self, sender: ReplicaId, messages: Vec<T>, rng: &mut R)
|
||||
where
|
||||
R: Rng,
|
||||
{
|
||||
pub fn broadcast<R: rand::Rng>(&mut self, sender: ReplicaId, messages: Vec<T>, rng: &mut R) {
|
||||
for (replica, inbox) in self.inboxes.iter_mut() {
|
||||
if *replica != sender {
|
||||
for message in &messages {
|
||||
@@ -83,10 +80,7 @@ impl<T: Clone> Network<T> {
|
||||
!self.inboxes[&receiver].is_empty()
|
||||
}
|
||||
|
||||
pub fn receive<R>(&mut self, receiver: ReplicaId, rng: &mut R) -> Vec<T>
|
||||
where
|
||||
R: Rng,
|
||||
{
|
||||
pub fn receive<R: rand::Rng>(&mut self, receiver: ReplicaId, rng: &mut R) -> Vec<T> {
|
||||
let inbox = self.inboxes.get_mut(&receiver).unwrap();
|
||||
let count = rng.gen_range(0..inbox.len() + 1);
|
||||
inbox
|
||||
|
||||
Reference in New Issue
Block a user