Skip to content

Commit c38fd36

Browse files
committed
Move runtime testutils to test_helpers
1 parent a9b5538 commit c38fd36

File tree

10 files changed

+44
-34
lines changed

10 files changed

+44
-34
lines changed

src/input/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ mod tests {
9696
use super::*;
9797
use crate::{
9898
input::KeyEvent,
99-
runtime::{testutils::ThreadableTester, Status},
100-
test_helpers::create_event_reader,
99+
runtime::Status,
100+
test_helpers::{create_event_reader, ThreadableTester},
101101
};
102102

103103
#[test]

src/process/tests.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use crate::{
77
assert_results,
88
input::{InputOptions, KeyBindings},
99
module::{Module, DEFAULT_INPUT_OPTIONS, DEFAULT_VIEW_DATA},
10-
runtime::{testutils::MockNotifier, Status},
10+
runtime::Status,
1111
search::{Interrupter, SearchResult},
12+
test_helpers::mocks::Notifier,
1213
testutil::{
1314
create_default_test_module_handler,
1415
create_test_module_handler,
@@ -409,7 +410,7 @@ fn handle_external_command_success() {
409410
create_test_module_handler(module),
410411
|ProcessTestContext { process, .. }| {
411412
_ = process.input_state.read_event(); // clear existing event
412-
let mut notifier = MockNotifier::new(&process.thread_statuses);
413+
let mut notifier = Notifier::new(&process.thread_statuses);
413414
notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting);
414415
notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting);
415416
assert_results!(process.handle_external_command(&(String::from("true"), vec![])));
@@ -428,7 +429,7 @@ fn handle_external_command_failure() {
428429
create_test_module_handler(module),
429430
|ProcessTestContext { process, .. }| {
430431
_ = process.input_state.read_event(); // clear existing event
431-
let mut notifier = MockNotifier::new(&process.thread_statuses);
432+
let mut notifier = Notifier::new(&process.thread_statuses);
432433
notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting);
433434
notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting);
434435
assert_results!(process.handle_external_command(&(String::from("false"), vec![])));
@@ -455,7 +456,7 @@ fn handle_external_command_not_executable() {
455456
create_test_module_handler(module),
456457
|ProcessTestContext { process, .. }| {
457458
_ = process.input_state.read_event(); // clear existing event
458-
let mut notifier = MockNotifier::new(&process.thread_statuses);
459+
let mut notifier = Notifier::new(&process.thread_statuses);
459460
notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting);
460461
notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting);
461462
assert_results!(
@@ -484,7 +485,7 @@ fn handle_external_command_not_found() {
484485
create_test_module_handler(module),
485486
|ProcessTestContext { process, .. }| {
486487
_ = process.input_state.read_event(); // clear existing event
487-
let mut notifier = MockNotifier::new(&process.thread_statuses);
488+
let mut notifier = Notifier::new(&process.thread_statuses);
488489
notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting);
489490
notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting);
490491
assert_results!(
@@ -574,7 +575,7 @@ fn handle_results_external_command_success() {
574575
create_test_module_handler(module),
575576
|ProcessTestContext { process, .. }| {
576577
_ = process.input_state.read_event(); // clear existing event
577-
let mut notifier = MockNotifier::new(&process.thread_statuses);
578+
let mut notifier = Notifier::new(&process.thread_statuses);
578579
notifier.register_thread(REFRESH_THREAD_NAME, Status::Waiting);
579580
notifier.register_thread(crate::input::THREAD_NAME, Status::Waiting);
580581
let mut results = Results::new();

src/process/thread.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ mod tests {
7878
use crate::{
7979
input::{Event, StandardEvent},
8080
module::Module,
81-
runtime::{testutils::ThreadableTester, Status},
81+
runtime::Status,
82+
test_helpers::ThreadableTester,
8283
testutil::{create_default_test_module_handler, create_test_module_handler, process_test, ProcessTestContext},
8384
};
8485

src/runtime.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ mod notifier;
1414
#[allow(clippy::module_inception)]
1515
mod runtime;
1616
mod status;
17-
#[cfg(test)]
18-
pub(crate) mod testutils;
17+
1918
mod thread_statuses;
2019
mod threadable;
2120

src/search/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ mod tests {
130130
use parking_lot::Mutex;
131131

132132
use super::*;
133-
use crate::runtime::{testutils::ThreadableTester, Status};
133+
use crate::{runtime::Status, test_helpers::ThreadableTester};
134134

135135
#[derive(Clone)]
136136
struct MockedSearchable {

src/test_helpers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod create_invalid_utf;
55
mod create_test_keybindings;
66
pub(crate) mod mocks;
77
mod shared;
8+
mod threadable_tester;
89
mod with_event_handler;
910
mod with_git_config;
1011
mod with_temp_bare_repository;
@@ -17,6 +18,7 @@ pub(crate) use self::{
1718
create_event_reader::create_event_reader,
1819
create_invalid_utf::invalid_utf,
1920
create_test_keybindings::create_test_keybindings,
21+
threadable_tester::ThreadableTester,
2022
with_event_handler::{with_event_handler, EventHandlerTestContext},
2123
with_git_config::with_git_config,
2224
with_temp_bare_repository::with_temp_bare_repository,

src/test_helpers/mocks.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
pub(crate) mod crossterm;
2+
mod notifier;
3+
4+
pub(crate) use self::notifier::Notifier;

src/test_helpers/mocks/notifier.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::runtime::{Status, ThreadStatuses};
2+
3+
/// A mocked version of the `Notifier`, that will interact directly with a `ThreadStatuses` without the use of a thread
4+
/// or the `Runtime`.
5+
#[derive(Debug)]
6+
pub(crate) struct Notifier<'notifier> {
7+
threadable_statuses: &'notifier ThreadStatuses,
8+
}
9+
10+
impl<'notifier> Notifier<'notifier> {
11+
/// Create a new instance of a `MockNotifier`.
12+
#[must_use]
13+
pub(crate) const fn new(threadable_statuses: &'notifier ThreadStatuses) -> Self {
14+
Self { threadable_statuses }
15+
}
16+
17+
/// Register a thread by name and status. This does not create a thread.
18+
pub(crate) fn register_thread(&mut self, thread_name: &str, status: Status) {
19+
self.threadable_statuses.register_thread(thread_name, status);
20+
}
21+
}

src/runtime/testutils.rs renamed to src/test_helpers/threadable_tester.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,6 @@ use crate::runtime::{Installer, Status, ThreadStatuses};
1717

1818
const WAIT_TIME: Duration = Duration::from_millis(100);
1919

20-
/// A mocked version of the `Notifier`, that will interact directly with a `ThreadStatuses` without the use of a thread
21-
/// or the `Runtime`.
22-
#[derive(Debug)]
23-
pub(crate) struct MockNotifier<'notifier> {
24-
threadable_statuses: &'notifier ThreadStatuses,
25-
}
26-
27-
impl<'notifier> MockNotifier<'notifier> {
28-
/// Create a new instance of a `MockNotifier`.
29-
#[must_use]
30-
pub(crate) const fn new(threadable_statuses: &'notifier ThreadStatuses) -> Self {
31-
Self { threadable_statuses }
32-
}
33-
34-
/// Register a thread by name and status. This does not create a thread.
35-
pub(crate) fn register_thread(&mut self, thread_name: &str, status: Status) {
36-
self.threadable_statuses.register_thread(thread_name, status);
37-
}
38-
}
39-
4020
/// A tester utility for `Threadable`.
4121
#[derive(Clone, Debug)]
4222
pub(crate) struct ThreadableTester {

src/view/thread.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ mod tests {
163163
use crate::{
164164
config::Theme,
165165
display::{Display, DisplayError},
166-
runtime::{testutils::ThreadableTester, Status},
167-
test_helpers::mocks::crossterm::{CrossTerm, MockableTui},
166+
runtime::Status,
167+
test_helpers::{
168+
mocks::crossterm::{CrossTerm, MockableTui},
169+
ThreadableTester,
170+
},
168171
view::ViewData,
169172
};
170173

0 commit comments

Comments
 (0)