tests.rs

 1use gpui::{Entity, TestAppContext, WindowHandle};
 2use project::Project;
 3use settings::SettingsStore;
 4use terminal_view::terminal_panel::TerminalPanel;
 5use workspace::Workspace;
 6
 7use crate::{debugger_panel::DebugPanel, session::DebugSession};
 8
 9mod attach_modal;
10mod console;
11mod debugger_panel;
12mod module_list;
13mod stack_frame_list;
14mod variable_list;
15
16pub fn init_test(cx: &mut gpui::TestAppContext) {
17    if std::env::var("RUST_LOG").is_ok() {
18        env_logger::try_init().ok();
19    }
20
21    cx.update(|cx| {
22        let settings = SettingsStore::test(cx);
23        cx.set_global(settings);
24        terminal_view::init(cx);
25        theme::init(theme::LoadThemes::JustBase, cx);
26        command_palette_hooks::init(cx);
27        language::init(cx);
28        workspace::init_settings(cx);
29        Project::init_settings(cx);
30        editor::init(cx);
31        crate::init(cx);
32    });
33}
34
35pub async fn init_test_workspace(
36    project: &Entity<Project>,
37    cx: &mut TestAppContext,
38) -> WindowHandle<Workspace> {
39    let workspace_handle =
40        cx.add_window(|window, cx| Workspace::test_new(project.clone(), window, cx));
41
42    let debugger_panel = workspace_handle
43        .update(cx, |_, window, cx| {
44            cx.spawn_in(window, async move |this, cx| {
45                DebugPanel::load(this, cx.clone()).await
46            })
47        })
48        .unwrap()
49        .await
50        .expect("Failed to load debug panel");
51
52    let terminal_panel = workspace_handle
53        .update(cx, |_, window, cx| {
54            cx.spawn_in(window, async |this, cx| {
55                TerminalPanel::load(this, cx.clone()).await
56            })
57        })
58        .unwrap()
59        .await
60        .expect("Failed to load terminal panel");
61
62    workspace_handle
63        .update(cx, |workspace, window, cx| {
64            workspace.add_panel(debugger_panel, window, cx);
65            workspace.add_panel(terminal_panel, window, cx);
66        })
67        .unwrap();
68    workspace_handle
69}
70
71#[track_caller]
72pub fn active_debug_session_panel(
73    workspace: WindowHandle<Workspace>,
74    cx: &mut TestAppContext,
75) -> Entity<DebugSession> {
76    workspace
77        .update(cx, |workspace, _window, cx| {
78            let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
79            debug_panel
80                .update(cx, |this, _| this.active_session())
81                .unwrap()
82        })
83        .unwrap()
84}