From ec39c9d3354848936f6c8cf0dc134bf010030848 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 16 Dec 2021 12:28:54 +0100 Subject: [PATCH] Allow specifying `MAX_EXCERPTS` via an env variable in random tests --- crates/diagnostics/src/diagnostics.rs | 2 +- crates/editor/src/display_map.rs | 2 +- crates/editor/src/display_map/block_map.rs | 2 +- crates/editor/src/display_map/fold_map.rs | 2 +- crates/editor/src/display_map/tab_map.rs | 2 +- crates/editor/src/display_map/wrap_map.rs | 2 +- crates/editor/src/multi_buffer.rs | 7 ++++++- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index a7f9c0e5c1..3181f3b3dd 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -3,7 +3,7 @@ use std::{cmp, sync::Arc}; use editor::{ diagnostic_block_renderer, diagnostic_style, display_map::{BlockDisposition, BlockProperties}, - Anchor, Editor, ExcerptProperties, MultiBuffer, + Editor, ExcerptProperties, MultiBuffer, }; use gpui::{ action, elements::*, keymap::Binding, AppContext, Entity, ModelHandle, MutableAppContext, diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 220614ffd6..9454455214 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -532,7 +532,7 @@ mod tests { let text = RandomCharIter::new(&mut rng).take(len).collect::(); MultiBuffer::build_simple(&text, cx) } else { - MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx) + MultiBuffer::build_random(&mut rng, cx) } }); diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index d0a9103af3..fc1232ea64 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -1123,7 +1123,7 @@ mod tests { log::info!("initial buffer text: {:?}", text); MultiBuffer::build_simple(&text, cx) } else { - MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx) + MultiBuffer::build_random(&mut rng, cx) }; let mut buffer_snapshot = buffer.read(cx).snapshot(cx); diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 74d2b3851f..4f7837a2eb 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -1252,7 +1252,7 @@ mod tests { let buffer = if rng.gen() { MultiBuffer::build_simple(&text, cx) } else { - MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx) + MultiBuffer::build_random(&mut rng, cx) }; let mut buffer_snapshot = buffer.read(cx).snapshot(cx); let mut map = FoldMap::new(buffer_snapshot.clone()).0; diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index 14e54c9523..9b33a10b14 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -458,7 +458,7 @@ mod tests { let text = RandomCharIter::new(&mut rng).take(len).collect::(); MultiBuffer::build_simple(&text, cx) } else { - MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx) + MultiBuffer::build_random(&mut rng, cx) }; let buffer_snapshot = buffer.read(cx).snapshot(cx); log::info!("Buffer text: {:?}", buffer_snapshot.text()); diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index 0dd91b7404..0620290e0d 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -1021,7 +1021,7 @@ mod tests { let buffer = cx.update(|cx| { if rng.gen() { - MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx) + MultiBuffer::build_random(&mut rng, cx) } else { let len = rng.gen_range(0..10); let text = RandomCharIter::new(&mut rng).take(len).collect::(); diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 3176bb3ea3..b4ad63292b 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -178,13 +178,18 @@ impl MultiBuffer { #[cfg(any(test, feature = "test-support"))] pub fn build_random( - excerpts: usize, mut rng: &mut impl rand::Rng, cx: &mut gpui::MutableAppContext, ) -> ModelHandle { use rand::prelude::*; + use std::env; use text::RandomCharIter; + let max_excerpts = env::var("MAX_EXCERPTS") + .map(|i| i.parse().expect("invalid `MAX_EXCERPTS` variable")) + .unwrap_or(5); + let excerpts = rng.gen_range(1..=max_excerpts); + cx.add_model(|cx| { let mut multibuffer = MultiBuffer::new(0); let mut buffers = Vec::new();