diff options
author | Tim Oram <dev@mitmaro.ca> | 2024-02-12 19:38:29 -0330 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2024-02-15 20:27:06 -0330 |
commit | c38fd360f8abcfc8607c2822944c1dccb6855f14 (patch) | |
tree | 1e7f35d26c897bf7630ba772dffff4f7f6f1166c | |
parent | a9b55386d5f74c80b182b7fc13fabf29f98aaef2 (diff) |
Move runtime testutils to test_helpers
-rw-r--r-- | src/input/thread.rs | 4 | ||||
-rw-r--r-- | src/process/tests.rs | 13 | ||||
-rw-r--r-- | src/process/thread.rs | 3 | ||||
-rw-r--r-- | src/runtime.rs | 3 | ||||
-rw-r--r-- | src/search/thread.rs | 2 | ||||
-rw-r--r-- | src/test_helpers.rs | 2 | ||||
-rw-r--r-- | src/test_helpers/mocks.rs | 3 | ||||
-rw-r--r-- | src/test_helpers/mocks/notifier.rs | 21 | ||||
-rw-r--r-- | src/test_helpers/threadable_tester.rs (renamed from src/runtime/testutils.rs) | 20 | ||||
-rw-r--r-- | src/view/thread.rs | 7 |
10 files changed, 44 insertions, 34 deletions
diff --git a/src/input/thread.rs b/src/input/thread.rs index 7a91413..a2467ac 100644 --- a/src/input/thread.rs +++ b/src/input/thread.rs @@ -96,8 +96,8 @@ mod tests { use super::*; use crate::{ input::KeyEvent, - runtime::{testutils::ThreadableTester, Status}, - test_helpers::create_event_reader, + runtime::Status, + test_helpers::{create_event_reader, ThreadableTester}, }; #[test] diff --git a/src/process/tests.rs b/src/process/tests.rs index 6af1239..ff58bab 100644 --- a/src/process/tests.rs +++ b/src/process/tests.rs @@ -7,8 +7,9 @@ use crate::{ assert_results, input::{InputOptions, KeyBindings}, module::{Module, DEFAULT_INPUT_OPTIONS, DEFAULT_VIEW_DATA}, - runtime::{testutils::MockNotifier, Status}, + runtime::Status, search::{Interrupter, SearchResult}, + test_helpers::mocks::Notifier, testutil::{ create_default_test_module_handler, create_test_module_handler, @@ -409,7 +410,7 @@ fn handle_external_command_success() { create_test_module_handler(module), |ProcessTestContext { process, .. }| { _ = process.input_state.read_event(); // clear existing event - let mut notifier = MockNotifier::new(&process.thread_statuses); + let mut notifier = Notifier::new(&process.thread_statuses); notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting); notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting); assert_results!(process.handle_external_command(&(String::from("true"), vec![]))); @@ -428,7 +429,7 @@ fn handle_external_command_failure() { create_test_module_handler(module), |ProcessTestContext { process, .. }| { _ = process.input_state.read_event(); // clear existing event - let mut notifier = MockNotifier::new(&process.thread_statuses); + let mut notifier = Notifier::new(&process.thread_statuses); notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting); notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting); assert_results!(process.handle_external_command(&(String::from("false"), vec![]))); @@ -455,7 +456,7 @@ fn handle_external_command_not_executable() { create_test_module_handler(module), |ProcessTestContext { process, .. }| { _ = process.input_state.read_event(); // clear existing event - let mut notifier = MockNotifier::new(&process.thread_statuses); + let mut notifier = Notifier::new(&process.thread_statuses); notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting); notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting); assert_results!( @@ -484,7 +485,7 @@ fn handle_external_command_not_found() { create_test_module_handler(module), |ProcessTestContext { process, .. }| { _ = process.input_state.read_event(); // clear existing event - let mut notifier = MockNotifier::new(&process.thread_statuses); + let mut notifier = Notifier::new(&process.thread_statuses); notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting); notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting); assert_results!( @@ -574,7 +575,7 @@ fn handle_results_external_command_success() { create_test_module_handler(module), |ProcessTestContext { process, .. }| { _ = process.input_state.read_event(); // clear existing event - let mut notifier = MockNotifier::new(&process.thread_statuses); + let mut notifier = Notifier::new(&process.thread_statuses); notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting); notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting); let mut results = Results::new(); diff --git a/src/process/thread.rs b/src/process/thread.rs index b1e904e..f293119 100644 --- a/src/process/thread.rs +++ b/src/process/thread.rs @@ -78,7 +78,8 @@ mod tests { use crate::{ input::{Event, StandardEvent}, module::Module, - runtime::{testutils::ThreadableTester, Status}, + runtime::Status, + test_helpers::ThreadableTester, testutil::{create_default_test_module_handler, create_test_module_handler, process_test, ProcessTestContext}, }; diff --git a/src/runtime.rs b/src/runtime.rs index 69c10b4..732dd9e 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -14,8 +14,7 @@ mod notifier; #[allow(clippy::module_inception)] mod runtime; mod status; -#[cfg(test)] -pub(crate) mod testutils; + mod thread_statuses; mod threadable; diff --git a/src/search/thread.rs b/src/search/thread.rs index f81335a..a2f149f 100644 --- a/src/search/thread.rs +++ b/src/search/thread.rs @@ -130,7 +130,7 @@ mod tests { use parking_lot::Mutex; use super::*; - use crate::runtime::{testutils::ThreadableTester, Status}; + use crate::{runtime::Status, test_helpers::ThreadableTester}; #[derive(Clone)] struct MockedSearchable { diff --git a/src/test_helpers.rs b/src/test_helpers.rs index 23f7f89..c9d5930 100644 --- a/src/test_helpers.rs +++ b/src/test_helpers.rs @@ -5,6 +5,7 @@ mod create_invalid_utf; mod create_test_keybindings; pub(crate) mod mocks; mod shared; +mod threadable_tester; mod with_event_handler; mod with_git_config; mod with_temp_bare_repository; @@ -17,6 +18,7 @@ pub(crate) use self::{ create_event_reader::create_event_reader, create_invalid_utf::invalid_utf, create_test_keybindings::create_test_keybindings, + threadable_tester::ThreadableTester, with_event_handler::{with_event_handler, EventHandlerTestContext}, with_git_config::with_git_config, with_temp_bare_repository::with_temp_bare_repository, diff --git a/src/test_helpers/mocks.rs b/src/test_helpers/mocks.rs index 5d17e48..8f873df 100644 --- a/src/test_helpers/mocks.rs +++ b/src/test_helpers/mocks.rs @@ -1 +1,4 @@ pub(crate) mod crossterm; +mod notifier; + +pub(crate) use self::notifier::Notifier; diff --git a/src/test_helpers/mocks/notifier.rs b/src/test_helpers/mocks/notifier.rs new file mode 100644 index 0000000..9508808 --- /dev/null +++ b/src/test_helpers/mocks/notifier.rs @@ -0,0 +1,21 @@ +use crate::runtime::{Status, ThreadStatuses}; + +/// A mocked version of the `Notifier`, that will interact directly with a `ThreadStatuses` without the use of a thread +/// or the `Runtime`. +#[derive(Debug)] +pub(crate) struct Notifier<'notifier> { + threadable_statuses: &'notifier ThreadStatuses, +} + +impl<'notifier> Notifier<'notifier> { + /// Create a new instance of a `MockNotifier`. + #[must_use] + pub(crate) const fn new(threadable_statuses: &'notifier ThreadStatuses) -> Self { + Self { threadable_statuses } + } + + /// Register a thread by name and status. This does not create a thread. + pub(crate) fn register_thread(&mut self, thread_name: &str, status: Status) { + self.threadable_statuses.register_thread(thread_name, status); + } +} diff --git a/src/runtime/testutils.rs b/src/test_helpers/threadable_tester.rs index d38c683..53866c0 100644 --- a/src/runtime/testutils.rs +++ b/src/test_helpers/threadable_tester.rs @@ -17,26 +17,6 @@ use crate::runtime::{Installer, Status, ThreadStatuses}; const WAIT_TIME: Duration = Duration::from_millis(100); -/// A mocked version of the `Notifier`, that will interact directly with a `ThreadStatuses` without the use of a thread -/// or the `Runtime`. -#[derive(Debug)] -pub(crate) struct MockNotifier<'notifier> { - threadable_statuses: &'notifier ThreadStatuses, -} - -impl<'notifier> MockNotifier<'notifier> { - /// Create a new instance of a `MockNotifier`. - #[must_use] - pub(crate) const fn new(threadable_statuses: &'notifier ThreadStatuses) -> Self { - Self { threadable_statuses } - } - - /// Register a thread by name and status. This does not create a thread. - pub(crate) fn register_thread(&mut self, thread_name: &str, status: Status) { - self.threadable_statuses.register_thread(thread_name, status); - } -} - /// A tester utility for `Threadable`. #[derive(Clone, Debug)] pub(crate) struct ThreadableTester { diff --git a/src/view/thread.rs b/src/view/thread.rs index 33f373d..8611b6b 100644 --- a/src/view/thread.rs +++ b/src/view/thread.rs @@ -163,8 +163,11 @@ mod tests { use crate::{ config::Theme, display::{Display, DisplayError}, - runtime::{testutils::ThreadableTester, Status}, - test_helpers::mocks::crossterm::{CrossTerm, MockableTui}, + runtime::Status, + test_helpers::{ + mocks::crossterm::{CrossTerm, MockableTui}, + ThreadableTester, + }, view::ViewData, }; |