diff --git a/src/client/mod.rs b/src/client/mod.rs index 819fddf0c..c1458b1a6 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -72,6 +72,7 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C std::env::set_var(&"ZELLIJ", "0"); + #[cfg(not(test))] spawn_server(&*ZELLIJ_IPC_PIPE).unwrap(); let mut command_is_executing = CommandIsExecuting::new(); diff --git a/src/main.rs b/src/main.rs index d08deb4af..5acd6df53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,10 +14,10 @@ use structopt::StructOpt; use crate::cli::CliArgs; use crate::command_is_executing::CommandIsExecuting; -use crate::common::input::{config::Config, options::Options}; -use crate::os_input_output::{get_client_os_input, get_server_os_input, ClientOsApi, ServerOsApi}; +use crate::common::input::config::Config; +use crate::os_input_output::{get_client_os_input, get_server_os_input}; use crate::utils::{ - consts::{ZELLIJ_IPC_PIPE, ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, + consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, logging::*, }; use std::convert::TryFrom; @@ -48,14 +48,3 @@ pub fn main() { } } } -pub fn start( - client_os_input: Box, - opts: CliArgs, - server_os_input: Box, - config: Config, - config_options: Options, -) { - start_server(server_os_input, ZELLIJ_IPC_PIPE.clone()); - start_client(client_os_input, opts, config); - //drop(ipc_thread.join()); -} diff --git a/src/server/mod.rs b/src/server/mod.rs index 96c0a3ce9..4d52e7799 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,7 +1,5 @@ pub mod route; -use daemonize::Daemonize; -use interprocess::local_socket::LocalSocketListener; use std::sync::{Arc, RwLock}; use std::thread; use std::{path::PathBuf, sync::mpsc}; @@ -13,7 +11,7 @@ use crate::common::thread_bus::{Bus, ThreadSenders}; use crate::common::{ errors::ContextType, ipc::{ClientToServerMsg, ServerToClientMsg}, - os_input_output::{set_permissions, ServerOsApi}, + os_input_output::ServerOsApi, pty::{pty_thread_main, Pty, PtyInstruction}, screen::{screen_thread_main, ScreenInstruction}, setup::install::populate_data_dir, @@ -65,7 +63,8 @@ impl Drop for SessionMetaData { } pub fn start_server(os_input: Box, socket_path: PathBuf) { - Daemonize::new() + #[cfg(not(test))] + daemonize::Daemonize::new() .working_directory(std::env::var("HOME").unwrap()) .umask(0o077) .start() @@ -105,6 +104,9 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { let _ = thread::Builder::new() .name("server_listener".to_string()) .spawn({ + use crate::common::os_input_output::set_permissions; + use interprocess::local_socket::LocalSocketListener; + let os_input = os_input.clone(); let sessions = sessions.clone(); let to_server = to_server.clone(); @@ -180,6 +182,7 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { } } } + #[cfg(not(test))] drop(std::fs::remove_file(&socket_path)); } diff --git a/src/tests/integration/basic.rs b/src/tests/integration/basic.rs index 1ebcb9225..83cae2054 100644 --- a/src/tests/integration/basic.rs +++ b/src/tests/integration/basic.rs @@ -3,6 +3,7 @@ use ::insta::assert_snapshot; use crate::common::input::{config::Config, options::Options}; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::commands::{ BRACKETED_PASTE_END, BRACKETED_PASTE_START, PANE_MODE, QUIT, SCROLL_DOWN_IN_SCROLL_MODE, SCROLL_MODE, SCROLL_PAGE_DOWN_IN_SCROLL_MODE, SCROLL_PAGE_UP_IN_SCROLL_MODE, @@ -10,7 +11,7 @@ use crate::tests::utils::commands::{ SPLIT_RIGHT_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, }; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) diff --git a/src/tests/integration/close_pane.rs b/src/tests/integration/close_pane.rs index d151f63d3..c492591f5 100644 --- a/src/tests/integration/close_pane.rs +++ b/src/tests/integration/close_pane.rs @@ -2,8 +2,9 @@ use crate::panes::PositionAndSize; use ::insta::assert_snapshot; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/compatibility.rs b/src/tests/integration/compatibility.rs index b986b1ded..40c2b9bf5 100644 --- a/src/tests/integration/compatibility.rs +++ b/src/tests/integration/compatibility.rs @@ -4,8 +4,9 @@ use ::std::collections::HashMap; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; use crate::tests::possible_tty_inputs::Bytes; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::QUIT; diff --git a/src/tests/integration/layouts.rs b/src/tests/integration/layouts.rs index bd7ceb3fc..42a5b66f1 100644 --- a/src/tests/integration/layouts.rs +++ b/src/tests/integration/layouts.rs @@ -4,9 +4,10 @@ use std::path::PathBuf; use crate::common::input::{config::Config, options::Options}; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::commands::QUIT; use crate::tests::utils::get_output_frame_snapshots; -use crate::{start, CliArgs}; +use crate::CliArgs; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) diff --git a/src/tests/integration/move_focus_down.rs b/src/tests/integration/move_focus_down.rs index e182acf9b..d81219941 100644 --- a/src/tests/integration/move_focus_down.rs +++ b/src/tests/integration/move_focus_down.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/move_focus_left.rs b/src/tests/integration/move_focus_left.rs index c991d1e8f..9533184a8 100644 --- a/src/tests/integration/move_focus_left.rs +++ b/src/tests/integration/move_focus_left.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/move_focus_right.rs b/src/tests/integration/move_focus_right.rs index ffc8cacfe..03177bca9 100644 --- a/src/tests/integration/move_focus_right.rs +++ b/src/tests/integration/move_focus_right.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/move_focus_up.rs b/src/tests/integration/move_focus_up.rs index 54bfef5e3..e6e7c3019 100644 --- a/src/tests/integration/move_focus_up.rs +++ b/src/tests/integration/move_focus_up.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/resize_down.rs b/src/tests/integration/resize_down.rs index 0e710b4e5..47293951c 100644 --- a/src/tests/integration/resize_down.rs +++ b/src/tests/integration/resize_down.rs @@ -2,8 +2,9 @@ use insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/resize_left.rs b/src/tests/integration/resize_left.rs index 5d498e964..d0581c52d 100644 --- a/src/tests/integration/resize_left.rs +++ b/src/tests/integration/resize_left.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/resize_right.rs b/src/tests/integration/resize_right.rs index 8be15315f..562161b79 100644 --- a/src/tests/integration/resize_right.rs +++ b/src/tests/integration/resize_right.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/resize_up.rs b/src/tests/integration/resize_up.rs index ba810a9f3..ed4d5f1fa 100644 --- a/src/tests/integration/resize_up.rs +++ b/src/tests/integration/resize_up.rs @@ -2,8 +2,9 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/tabs.rs b/src/tests/integration/tabs.rs index 1d8a2c9d3..f81c1cc61 100644 --- a/src/tests/integration/tabs.rs +++ b/src/tests/integration/tabs.rs @@ -1,9 +1,10 @@ use insta::assert_snapshot; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; +use crate::CliArgs; use crate::{panes::PositionAndSize, tests::utils::commands::CLOSE_PANE_IN_PANE_MODE}; -use crate::{start, CliArgs}; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/integration/terminal_window_resize.rs b/src/tests/integration/terminal_window_resize.rs index 7c06609af..4bb7240bd 100644 --- a/src/tests/integration/terminal_window_resize.rs +++ b/src/tests/integration/terminal_window_resize.rs @@ -3,9 +3,10 @@ use ::insta::assert_snapshot; use crate::common::input::{config::Config, options::Options}; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::commands::QUIT; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) diff --git a/src/tests/integration/toggle_fullscreen.rs b/src/tests/integration/toggle_fullscreen.rs index 8a63bbeaa..8707afffa 100644 --- a/src/tests/integration/toggle_fullscreen.rs +++ b/src/tests/integration/toggle_fullscreen.rs @@ -2,8 +2,9 @@ use insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; use crate::common::input::{config::Config, options::Options}; use crate::tests::utils::commands::{ diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 6e07c96d3..7aaad79fa 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -3,3 +3,26 @@ pub mod integration; pub mod possible_tty_inputs; pub mod tty_inputs; pub mod utils; + +use crate::cli::CliArgs; +use crate::client::start_client; +use crate::common::input::config::Config; +use crate::os_input_output::{ClientOsApi, ServerOsApi}; +use crate::server::start_server; +use std::path::PathBuf; + +pub fn start( + client_os_input: Box, + opts: CliArgs, + server_os_input: Box, + config: Config, +) { + let server_thread = std::thread::Builder::new() + .name("server_thread".into()) + .spawn(move || { + start_server(server_os_input, PathBuf::from("")); + }) + .unwrap(); + start_client(client_os_input, opts, config); + let _ = server_thread.join(); +}