Enable linux tests (#12493)

Note:
- We have disabled all tests that rely on Postgres in the Linux CI. We
only really need to test these once, and as macOS is our team's primary
platform, we'll only enable them on macOS for local reproduction.
- We have disabled all tests that rely on the font metrics. We
standardized on Zed Mono in many fonts, but our CoreText Text System and
Cosmic Text System proved to be very different in effect. We should
revisit if we decide to standardize our text system across platforms
(e.g. using Harfbuzz everywhere)
- Extended the condition timeout significantly. Our CI machines are slow
enough that this is causing spurious errors in random tests.

Release Notes:

- N/A

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Mikayla Maki 2024-06-13 16:38:53 -07:00 committed by GitHub
parent 066cdc2297
commit 10d3ad4e33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 107 additions and 52 deletions

View file

@ -101,7 +101,6 @@ jobs:
- name: Build other binaries and features - name: Build other binaries and features
run: cargo build --workspace --bins --all-features; cargo check -p gpui --features "macos-blade" run: cargo build --workspace --bins --all-features; cargo check -p gpui --features "macos-blade"
# todo(linux): Actually run the tests
linux_tests: linux_tests:
timeout-minutes: 60 timeout-minutes: 60
name: (Linux) Run Clippy and tests name: (Linux) Run Clippy and tests
@ -120,6 +119,9 @@ jobs:
- name: cargo clippy - name: cargo clippy
run: cargo xtask clippy run: cargo xtask clippy
- name: Run tests
uses: ./.github/actions/run_tests
- name: Build Zed - name: Build Zed
run: cargo build -p zed run: cargo build -p zed

View file

@ -277,7 +277,7 @@ mod test {
#[gpui::test] #[gpui::test]
async fn test_verify_access_token(cx: &mut gpui::TestAppContext) { async fn test_verify_access_token(cx: &mut gpui::TestAppContext) {
let test_db = crate::db::TestDb::postgres(cx.executor().clone()); let test_db = crate::db::TestDb::sqlite(cx.executor().clone());
let db = test_db.db(); let db = test_db.db();
let user = db let user = db

View file

@ -2,6 +2,8 @@ mod buffer_tests;
mod channel_tests; mod channel_tests;
mod contributor_tests; mod contributor_tests;
mod db_tests; mod db_tests;
// we only run postgres tests on macos right now
#[cfg(target_os = "macos")]
mod embedding_tests; mod embedding_tests;
mod extension_tests; mod extension_tests;
mod feature_flag_tests; mod feature_flag_tests;
@ -108,6 +110,7 @@ impl TestDb {
#[macro_export] #[macro_export]
macro_rules! test_both_dbs { macro_rules! test_both_dbs {
($test_name:ident, $postgres_test_name:ident, $sqlite_test_name:ident) => { ($test_name:ident, $postgres_test_name:ident, $sqlite_test_name:ident) => {
#[cfg(target_os = "macos")]
#[gpui::test] #[gpui::test]
async fn $postgres_test_name(cx: &mut gpui::TestAppContext) { async fn $postgres_test_name(cx: &mut gpui::TestAppContext) {
let test_db = $crate::db::TestDb::postgres(cx.executor().clone()); let test_db = $crate::db::TestDb::postgres(cx.executor().clone());

View file

@ -1,9 +1,7 @@
use super::*; use super::*;
use crate::test_both_dbs; use crate::test_both_dbs;
use gpui::TestAppContext;
use pretty_assertions::{assert_eq, assert_ne}; use pretty_assertions::{assert_eq, assert_ne};
use std::sync::Arc; use std::sync::Arc;
use tests::TestDb;
test_both_dbs!( test_both_dbs!(
test_get_users, test_get_users,
@ -564,9 +562,10 @@ fn test_fuzzy_like_string() {
assert_eq!(Database::fuzzy_like_string(" z "), "%z%"); assert_eq!(Database::fuzzy_like_string(" z "), "%z%");
} }
#[cfg(target = "macos")]
#[gpui::test] #[gpui::test]
async fn test_fuzzy_search_users(cx: &mut TestAppContext) { async fn test_fuzzy_search_users(cx: &mut gpui::TestAppContext) {
let test_db = TestDb::postgres(cx.executor()); let test_db = tests::TestDb::postgres(cx.executor());
let db = test_db.db(); let db = test_db.db();
for (i, github_login) in [ for (i, github_login) in [
"California", "California",

View file

@ -575,7 +575,8 @@ async fn test_save_as_remote(cx1: &mut gpui::TestAppContext, cx2: &mut gpui::Tes
let title = remote_workspace let title = remote_workspace
.update(&mut cx, |ws, cx| { .update(&mut cx, |ws, cx| {
ws.active_item(cx).unwrap().tab_description(0, &cx).unwrap() let active_item = ws.active_item(cx).unwrap();
active_item.tab_description(0, &cx).unwrap()
}) })
.unwrap(); .unwrap();

View file

@ -277,11 +277,7 @@ impl TestServer {
node_runtime: FakeNodeRuntime::new(), node_runtime: FakeNodeRuntime::new(),
}); });
let os_keymap = if cfg!(target_os = "linux") { let os_keymap = "keymaps/default-macos.json";
"keymaps/default-linux.json"
} else {
"keymaps/default-macos.json"
};
cx.update(|cx| { cx.update(|cx| {
theme::init(theme::LoadThemes::JustBase, cx); theme::init(theme::LoadThemes::JustBase, cx);

View file

@ -1111,14 +1111,11 @@ impl ToDisplayPoint for Anchor {
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use super::*; use super::*;
use crate::{ use crate::{movement, test::marked_display_snapshot};
movement,
test::{editor_test_context::EditorTestContext, marked_display_snapshot},
};
use gpui::{div, font, observe, px, AppContext, BorrowAppContext, Context, Element, Hsla}; use gpui::{div, font, observe, px, AppContext, BorrowAppContext, Context, Element, Hsla};
use language::{ use language::{
language_settings::{AllLanguageSettings, AllLanguageSettingsContent}, language_settings::{AllLanguageSettings, AllLanguageSettingsContent},
Buffer, Language, LanguageConfig, LanguageMatcher, SelectionGoal, Buffer, Language, LanguageConfig, LanguageMatcher,
}; };
use project::Project; use project::Project;
use rand::{prelude::*, Rng}; use rand::{prelude::*, Rng};
@ -1393,6 +1390,7 @@ pub mod tests {
} }
} }
#[cfg(target_os = "macos")]
#[gpui::test(retries = 5)] #[gpui::test(retries = 5)]
async fn test_soft_wraps(cx: &mut gpui::TestAppContext) { async fn test_soft_wraps(cx: &mut gpui::TestAppContext) {
cx.background_executor cx.background_executor
@ -1401,7 +1399,7 @@ pub mod tests {
init_test(cx, |_| {}); init_test(cx, |_| {});
}); });
let mut cx = EditorTestContext::new(cx).await; let mut cx = crate::test::editor_test_context::EditorTestContext::new(cx).await;
let editor = cx.editor.clone(); let editor = cx.editor.clone();
let window = cx.window; let window = cx.window;
@ -1457,39 +1455,39 @@ pub mod tests {
movement::up( movement::up(
&snapshot, &snapshot,
DisplayPoint::new(DisplayRow(1), 10), DisplayPoint::new(DisplayRow(1), 10),
SelectionGoal::None, language::SelectionGoal::None,
false, false,
&text_layout_details, &text_layout_details,
), ),
( (
DisplayPoint::new(DisplayRow(0), 7), DisplayPoint::new(DisplayRow(0), 7),
SelectionGoal::HorizontalPosition(x.0) language::SelectionGoal::HorizontalPosition(x.0)
) )
); );
assert_eq!( assert_eq!(
movement::down( movement::down(
&snapshot, &snapshot,
DisplayPoint::new(DisplayRow(0), 7), DisplayPoint::new(DisplayRow(0), 7),
SelectionGoal::HorizontalPosition(x.0), language::SelectionGoal::HorizontalPosition(x.0),
false, false,
&text_layout_details &text_layout_details
), ),
( (
DisplayPoint::new(DisplayRow(1), 10), DisplayPoint::new(DisplayRow(1), 10),
SelectionGoal::HorizontalPosition(x.0) language::SelectionGoal::HorizontalPosition(x.0)
) )
); );
assert_eq!( assert_eq!(
movement::down( movement::down(
&snapshot, &snapshot,
DisplayPoint::new(DisplayRow(1), 10), DisplayPoint::new(DisplayRow(1), 10),
SelectionGoal::HorizontalPosition(x.0), language::SelectionGoal::HorizontalPosition(x.0),
false, false,
&text_layout_details &text_layout_details
), ),
( (
DisplayPoint::new(DisplayRow(2), 4), DisplayPoint::new(DisplayRow(2), 4),
SelectionGoal::HorizontalPosition(x.0) language::SelectionGoal::HorizontalPosition(x.0)
) )
); );
@ -1679,6 +1677,8 @@ pub mod tests {
); );
} }
// todo(linux) fails due to pixel differences in text rendering
#[cfg(target_os = "macos")]
#[gpui::test] #[gpui::test]
async fn test_chunks_with_soft_wrapping(cx: &mut gpui::TestAppContext) { async fn test_chunks_with_soft_wrapping(cx: &mut gpui::TestAppContext) {
use unindent::Unindent as _; use unindent::Unindent as _;

View file

@ -1157,7 +1157,7 @@ mod tests {
use super::*; use super::*;
use crate::display_map::inlay_map::InlayMap; use crate::display_map::inlay_map::InlayMap;
use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap}; use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap};
use gpui::{div, font, px, Element}; use gpui::{div, font, px, AssetSource, Element};
use multi_buffer::MultiBuffer; use multi_buffer::MultiBuffer;
use rand::prelude::*; use rand::prelude::*;
use settings::SettingsStore; use settings::SettingsStore;
@ -1452,6 +1452,7 @@ mod tests {
} }
} }
#[cfg(target_os = "macos")]
#[gpui::test] #[gpui::test]
fn test_blocks_on_wrapped_lines(cx: &mut gpui::TestAppContext) { fn test_blocks_on_wrapped_lines(cx: &mut gpui::TestAppContext) {
cx.update(|cx| init_test(cx)); cx.update(|cx| init_test(cx));
@ -1940,6 +1941,12 @@ mod tests {
let settings = SettingsStore::test(cx); let settings = SettingsStore::test(cx);
cx.set_global(settings); cx.set_global(settings);
theme::init(theme::LoadThemes::JustBase, cx); theme::init(theme::LoadThemes::JustBase, cx);
cx.text_system()
.add_fonts(vec![assets::Assets
.load("fonts/zed-mono/zed-mono-extended.ttf")
.unwrap()
.unwrap()])
.unwrap();
} }
impl TransformBlock { impl TransformBlock {

View file

@ -2746,7 +2746,9 @@ impl Editor {
Some(Selection { start, end, .. }) => start != end, Some(Selection { start, end, .. }) => start != end,
None => false, None => false,
}; };
pending_nonempty_selection || self.columnar_selection_tail.is_some()
pending_nonempty_selection
|| (self.columnar_selection_tail.is_some() && self.selections.disjoint.len() > 1)
} }
pub fn has_pending_selection(&self) -> bool { pub fn has_pending_selection(&self) -> bool {

View file

@ -936,6 +936,8 @@ fn test_move_cursor(cx: &mut TestAppContext) {
}); });
} }
// TODO: Re-enable this test
#[cfg(target_os = "macos")]
#[gpui::test] #[gpui::test]
fn test_move_cursor_multibyte(cx: &mut TestAppContext) { fn test_move_cursor_multibyte(cx: &mut TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});

View file

@ -586,7 +586,7 @@ impl EditorElement {
editor.handle_click_hovered_link(point, event.modifiers, cx); editor.handle_click_hovered_link(point, event.modifiers, cx);
cx.stop_propagation(); cx.stop_propagation();
} else if end_selection { } else if end_selection && pending_nonempty_selections {
cx.stop_propagation(); cx.stop_propagation();
} else if cfg!(target_os = "linux") && event.button == MouseButton::Middle { } else if cfg!(target_os = "linux") && event.button == MouseButton::Middle {
if !text_hitbox.is_hovered(cx) || editor.read_only(cx) { if !text_hitbox.is_hovered(cx) || editor.read_only(cx) {
@ -594,7 +594,7 @@ impl EditorElement {
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
if let Some(item) = cx.read_from_clipboard() { if let Some(item) = cx.read_from_primary() {
let point_for_position = let point_for_position =
position_map.point_for_position(text_hitbox.bounds, event.position); position_map.point_for_position(text_hitbox.bounds, event.position);
let position = point_for_position.previous_valid; let position = point_for_position.previous_valid;

View file

@ -748,9 +748,13 @@ mod tests {
]))) ])))
}); });
cx.cx let modifiers = if cfg!(target_os = "macos") {
.cx Modifiers::command_shift()
.simulate_mouse_move(screen_coord.unwrap(), None, Modifiers::command_shift()); } else {
Modifiers::control_shift()
};
cx.simulate_mouse_move(screen_coord.unwrap(), None, modifiers);
requests.next().await; requests.next().await;
cx.run_until_parked(); cx.run_until_parked();
@ -767,9 +771,7 @@ mod tests {
let variable = A; let variable = A;
"}); "});
cx.cx cx.simulate_click(screen_coord.unwrap(), modifiers);
.cx
.simulate_click(screen_coord.unwrap(), Modifiers::command_shift());
cx.assert_editor_state(indoc! {" cx.assert_editor_state(indoc! {"
struct «»; struct «»;

View file

@ -25,7 +25,7 @@ pub fn marked_display_snapshot(
let (unmarked_text, markers) = marked_text_offsets(text); let (unmarked_text, markers) = marked_text_offsets(text);
let font = Font { let font = Font {
family: "Courier".into(), family: "Zed Mono".into(),
features: FontFeatures::default(), features: FontFeatures::default(),
weight: FontWeight::default(), weight: FontWeight::default(),
style: FontStyle::default(), style: FontStyle::default(),

View file

@ -510,6 +510,14 @@ async fn test_extension_store_with_gleam_extension(cx: &mut TestAppContext) {
{ {
"name": format!("gleam-{version}-aarch64-apple-darwin.tar.gz"), "name": format!("gleam-{version}-aarch64-apple-darwin.tar.gz"),
"browser_download_url": asset_download_uri "browser_download_url": asset_download_uri
},
{
"name": format!("gleam-{version}-x86_64-unknown-linux-musl.tar.gz"),
"browser_download_url": asset_download_uri
},
{
"name": format!("gleam-{version}-aarch64-unknown-linux-musl.tar.gz"),
"browser_download_url": asset_download_uri
} }
] ]
} }

View file

@ -571,7 +571,11 @@ impl<V> View<V> {
use postage::prelude::{Sink as _, Stream as _}; use postage::prelude::{Sink as _, Stream as _};
let (tx, mut rx) = postage::mpsc::channel(1024); let (tx, mut rx) = postage::mpsc::channel(1024);
let timeout_duration = Duration::from_millis(100); let timeout_duration = if cfg!(target_os = "macos") {
Duration::from_millis(100)
} else {
Duration::from_secs(1)
};
let mut cx = cx.app.borrow_mut(); let mut cx = cx.app.borrow_mut();
let subscriptions = ( let subscriptions = (

View file

@ -296,6 +296,15 @@ impl Modifiers {
} }
} }
/// helper method for Modifiers with command + shift
pub fn control_shift() -> Modifiers {
Modifiers {
shift: true,
control: true,
..Default::default()
}
}
/// Checks if this Modifiers is a subset of another Modifiers /// Checks if this Modifiers is a subset of another Modifiers
pub fn is_subset_of(&self, other: &Modifiers) -> bool { pub fn is_subset_of(&self, other: &Modifiers) -> bool {
(other.control || !self.control) (other.control || !self.control)

View file

@ -27,6 +27,7 @@ pub(crate) struct TestPlatform {
current_primary_item: Mutex<Option<ClipboardItem>>, current_primary_item: Mutex<Option<ClipboardItem>>,
pub(crate) prompts: RefCell<TestPrompts>, pub(crate) prompts: RefCell<TestPrompts>,
pub opened_url: RefCell<Option<String>>, pub opened_url: RefCell<Option<String>>,
pub text_system: Arc<dyn PlatformTextSystem>,
weak: Weak<Self>, weak: Weak<Self>,
} }
@ -44,6 +45,15 @@ impl TestPlatform {
.expect("unable to initialize Windows OLE"); .expect("unable to initialize Windows OLE");
} }
#[cfg(target_os = "macos")]
let text_system = Arc::new(crate::platform::mac::MacTextSystem::new());
#[cfg(target_os = "linux")]
let text_system = Arc::new(crate::platform::cosmic_text::CosmicTextSystem::new());
#[cfg(target_os = "windows")]
let text_system = Arc::new(crate::platform::windows::DirectWriteTextSystem::new().unwrap());
Rc::new_cyclic(|weak| TestPlatform { Rc::new_cyclic(|weak| TestPlatform {
background_executor: executor, background_executor: executor,
foreground_executor, foreground_executor,
@ -56,6 +66,7 @@ impl TestPlatform {
current_primary_item: Mutex::new(None), current_primary_item: Mutex::new(None),
weak: weak.clone(), weak: weak.clone(),
opened_url: Default::default(), opened_url: Default::default(),
text_system,
}) })
} }
@ -132,14 +143,7 @@ impl Platform for TestPlatform {
} }
fn text_system(&self) -> Arc<dyn PlatformTextSystem> { fn text_system(&self) -> Arc<dyn PlatformTextSystem> {
#[cfg(target_os = "macos")] self.text_system.clone()
return Arc::new(crate::platform::mac::MacTextSystem::new());
#[cfg(target_os = "linux")]
return Arc::new(crate::platform::cosmic_text::CosmicTextSystem::new());
#[cfg(target_os = "windows")]
return Arc::new(crate::platform::windows::DirectWriteTextSystem::new().unwrap());
} }
fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) { fn run(&self, _on_finish_launching: Box<dyn FnOnce()>) {

View file

@ -69,6 +69,7 @@ impl TextSystem {
font("Cantarell"), // Gnome font("Cantarell"), // Gnome
font("Ubuntu"), // Gnome (Ubuntu) font("Ubuntu"), // Gnome (Ubuntu)
font("Noto Sans"), // KDE font("Noto Sans"), // KDE
font("DejaVu Sans")
], ],
} }
} }

View file

@ -143,21 +143,28 @@ impl Boundary {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{font, TestAppContext, TestDispatcher, TextRun, WindowTextSystem, WrapBoundary}; use crate::{font, TestAppContext, TestDispatcher};
#[cfg(target_os = "macos")]
use crate::{TextRun, WindowTextSystem, WrapBoundary};
use rand::prelude::*; use rand::prelude::*;
#[test] #[test]
fn test_wrap_line() { fn test_wrap_line() {
let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(0)); let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(0));
let cx = TestAppContext::new(dispatcher, None); let cx = TestAppContext::new(dispatcher, None);
cx.text_system()
.add_fonts(vec![std::fs::read(
"../../assets/fonts/zed-mono/zed-mono-extended.ttf",
)
.unwrap()
.into()])
.unwrap();
let id = cx.text_system().font_id(&font("Zed Mono")).unwrap();
cx.update(|cx| { cx.update(|cx| {
let text_system = cx.text_system().clone(); let text_system = cx.text_system().clone();
let mut wrapper = LineWrapper::new( let mut wrapper =
text_system.font_id(&font("Courier")).unwrap(), LineWrapper::new(id, px(16.), text_system.platform_text_system.clone());
px(16.),
text_system.platform_text_system.clone(),
);
assert_eq!( assert_eq!(
wrapper wrapper
.wrap_line("aa bbb cccc ddddd eeee", px(72.)) .wrap_line("aa bbb cccc ddddd eeee", px(72.))
@ -213,8 +220,11 @@ mod tests {
} }
// For compatibility with the test macro // For compatibility with the test macro
#[cfg(target_os = "macos")]
use crate as gpui; use crate as gpui;
// These seem to vary wildly based on the the text system.
#[cfg(target_os = "macos")]
#[crate::test] #[crate::test]
fn test_wrap_shaped_line(cx: &mut TestAppContext) { fn test_wrap_shaped_line(cx: &mut TestAppContext) {
cx.update(|cx| { cx.update(|cx| {

View file

@ -24,7 +24,7 @@ async fn test_block_via_channel(cx: &mut gpui::TestAppContext) {
let (tx, mut rx) = futures::channel::mpsc::unbounded(); let (tx, mut rx) = futures::channel::mpsc::unbounded();
let _thread = std::thread::spawn(move || { let _thread = std::thread::spawn(move || {
std::fs::metadata("/Users").unwrap(); std::fs::metadata("/tmp").unwrap();
std::thread::sleep(Duration::from_millis(1000)); std::thread::sleep(Duration::from_millis(1000));
tx.unbounded_send(1).unwrap(); tx.unbounded_send(1).unwrap();
}); });

View file

@ -1,7 +1,10 @@
fn main() { fn main() {
// Find WebRTC.framework as a sibling of the executable when running outside of an application bundle. // Find WebRTC.framework as a sibling of the executable when running outside of an application bundle.
// TODO: We shouldn't depend on WebRTC in editor // TODO: We shouldn't depend on WebRTC in editor
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path"); #[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path");
}
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {

View file

@ -400,6 +400,7 @@ async fn test_join_lines(cx: &mut gpui::TestAppContext) {
"}); "});
} }
#[cfg(target_os = "macos")]
#[gpui::test] #[gpui::test]
async fn test_wrapped_lines(cx: &mut gpui::TestAppContext) { async fn test_wrapped_lines(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;
@ -706,6 +707,7 @@ async fn test_selection_goal(cx: &mut gpui::TestAppContext) {
Lorem Ipsum"}); Lorem Ipsum"});
} }
#[cfg(target_os = "macos")]
#[gpui::test] #[gpui::test]
async fn test_wrapped_motions(cx: &mut gpui::TestAppContext) { async fn test_wrapped_motions(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await; let mut cx = NeovimBackedTestContext::new(cx).await;