diff options
author | Tim Oram <dev@mitmaro.ca> | 2024-02-19 10:00:34 -0330 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2024-02-19 10:20:42 -0330 |
commit | 2227eb36d6b278746392bb9f910385515e58bdbc (patch) | |
tree | c0c05d813389a5aac57affe45869daf19339efbc | |
parent | a2f99b7e0992a55c2b6ddd8b9854fb2015907da3 (diff) |
Reenable the unused lint, and cleanup unused
58 files changed, 222 insertions, 288 deletions
diff --git a/src/application.rs b/src/application.rs index 0a9fa56..60190a4 100644 --- a/src/application.rs +++ b/src/application.rs @@ -194,7 +194,7 @@ mod tests { use super::*; use crate::{ display::Size, - input::{Event, KeyCode, KeyEvent, KeyModifiers}, + input::{KeyCode, KeyEvent, KeyModifiers}, module::Modules, runtime::{Installer, RuntimeError}, test_helpers::{ diff --git a/src/components/choice/tests.rs b/src/components/choice/tests.rs index b2019e5..8f1dbd2 100644 --- a/src/components/choice/tests.rs +++ b/src/components/choice/tests.rs @@ -1,11 +1,7 @@ use rstest::rstest; use super::*; -use crate::{ - assert_rendered_output, - input::StandardEvent, - test_helpers::{assertions::assert_rendered_output::AssertRenderOptions, with_view_state}, -}; +use crate::{assert_rendered_output, input::StandardEvent, test_helpers::with_view_state}; #[derive(Clone, Debug, PartialEq)] enum TestAction { diff --git a/src/components/search_bar/tests.rs b/src/components/search_bar/tests.rs index 7d2e44c..1727f0d 100644 --- a/src/components/search_bar/tests.rs +++ b/src/components/search_bar/tests.rs @@ -1,7 +1,11 @@ use claims::{assert_none, assert_some_eq}; use super::*; -use crate::{assert_rendered_output, view::ViewData}; +use crate::{ + assert_rendered_output, + test_helpers::assertions::assert_rendered_output::AssertRenderOptions, + view::ViewData, +}; fn create_view_data(search_bar: &SearchBar) -> ViewData { let view_line = search_bar.build_view_line(); diff --git a/src/config/theme.rs b/src/config/theme.rs index 97da2f2..3310aa4 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -138,7 +138,7 @@ mod tests { use super::*; use crate::{ - config::{ConfigErrorCause, InvalidColorError}, + config::InvalidColorError, test_helpers::{invalid_utf, with_git_config}, }; diff --git a/src/display.rs b/src/display.rs index 658fe35..1a6bf49 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,3 +1,4 @@ +#![cfg_attr(test, allow(dead_code, unused_imports))] //! Git Interactive Rebase Tool - Display Module //! //! # Description diff --git a/src/git/errors.rs b/src/git/errors.rs index ae88772..df789a7 100644 --- a/src/git/errors.rs +++ b/src/git/errors.rs @@ -13,6 +13,7 @@ use thiserror::Error; pub(crate) enum RepositoryLoadKind { /// Repository was loaded from the path provided through an environment variable Environment, + #[cfg(test)] /// Repository was loaded from a direct path Path, } @@ -21,6 +22,7 @@ impl Display for RepositoryLoadKind { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match *self { Self::Environment => write!(f, "environment"), + #[cfg(test)] Self::Path => write!(f, "path"), } } @@ -29,6 +31,7 @@ impl Display for RepositoryLoadKind { /// Git errors #[derive(Error, Debug, PartialEq)] #[non_exhaustive] +#[allow(clippy::enum_variant_names)] pub(crate) enum GitError { /// The repository could not be loaded #[error("Could not open repository from {kind}")] @@ -47,6 +50,7 @@ pub(crate) enum GitError { cause: git2::Error, }, /// The configuration could not be loaded + #[cfg(test)] #[error("Could not load configuration")] ReferenceNotFound { /// The internal cause of the load error. diff --git a/src/git/repository.rs b/src/git/repository.rs index d415d82..0ed9ddc 100644 --- a/src/git/repository.rs +++ b/src/git/repository.rs @@ -1,22 +1,11 @@ use std::{ fmt::{Debug, Formatter}, - path::{Path, PathBuf}, sync::Arc, }; -use git2::{Oid, Signature}; use parking_lot::Mutex; -use crate::git::{ - Commit, - CommitDiff, - CommitDiffLoader, - CommitDiffLoaderOptions, - Config, - GitError, - Reference, - RepositoryLoadKind, -}; +use crate::git::{CommitDiff, CommitDiffLoader, CommitDiffLoaderOptions, Config, GitError, RepositoryLoadKind}; /// A light cloneable, simple wrapper around the `git2::Repository` struct #[derive(Clone)] @@ -43,22 +32,6 @@ impl Repository { }) } - /// Attempt to open an already-existing repository at `path`. - /// - /// # Errors - /// Will result in an error if the repository cannot be opened. - pub(crate) fn open_from_path(path: &Path) -> Result<Self, GitError> { - let repository = git2::Repository::open(path).map_err(|e| { - GitError::RepositoryLoad { - kind: RepositoryLoadKind::Path, - cause: e, - } - })?; - Ok(Self { - repository: Arc::new(Mutex::new(repository)), - }) - } - /// Load the git configuration for the repository. /// /// # Errors @@ -93,78 +66,6 @@ impl Repository { .map_err(|e| GitError::CommitLoad { cause: e })? .remove(0)) } - - /// Find a reference by the reference name. - /// - /// # Errors - /// Will result in an error if the reference cannot be found. - pub(crate) fn find_reference(&self, reference: &str) -> Result<Reference, GitError> { - let repo = self.repository.lock(); - let git2_reference = repo - .find_reference(reference) - .map_err(|e| GitError::ReferenceNotFound { cause: e })?; - Ok(Reference::from(&git2_reference)) - } - - /// Find a commit by a reference name. - /// - /// # Errors - /// Will result in an error if the reference cannot be found or is not a commit. - pub(crate) fn find_commit(&self, reference: &str) -> Result<Commit, GitError> { - let repo = self.repository.lock(); - let git2_reference = repo - .find_reference(reference) - .map_err(|e| GitError::ReferenceNotFound { cause: e })?; - Commit::try_from(&git2_reference) - } - - pub(crate) fn repo_path(&self) -> PathBuf { - self.repository.lock().path().to_path_buf() - } - - pub(crate) fn head_id(&self, head_name: &str) -> Result<Oid, git2::Error> { - let repo = self.repository.lock(); - let ref_name = format!("refs/heads/{head_name}"); - let revision = repo.revparse_single(ref_name.as_str())?; - Ok(revision.id()) - } - - pub(crate) fn commit_id_from_ref(&self, reference: &str) -> Result<Oid, git2::Error> { - let repo = self.repository.lock(); - let commit = repo.find_reference(reference)?.peel_to_commit()?; - Ok(commit.id()) - } - - pub(crate) fn add_path_to_index(&self, path: &Path) -> Result<(), git2::Error> { - let repo = self.repository.lock(); - let mut index = repo.index()?; - index.add_path(path) - } - - pub(crate) fn remove_path_from_index(&self, path: &Path) -> Result<(), git2::Error> { - let repo = self.repository.lock(); - let mut index = repo.index()?; - index.remove_path(path) - } - - pub(crate) fn create_commit_on_index( - &self, - reference: &str, - author: &Signature<'_>, - committer: &Signature<'_>, - message: &str, - ) -> Result<(), git2::Error> { - let repo = self.repository.lock(); - let tree = repo.find_tree(repo.index()?.write_tree()?)?; - let head = repo.find_reference(reference)?.peel_to_commit()?; - _ = repo.commit(Some("HEAD"), author, committer, message, &tree, &[&head])?; - Ok(()) - } - - #[cfg(test)] - pub(crate) fn repository(&self) -> Arc<Mutex<git2::Repository>> { - Arc::clone(&self.repository) - } } impl From<git2::Repository> for Repository { @@ -183,10 +84,112 @@ impl Debug for Repository { } } +#[cfg(test)] +mod tests { + use std::{ + path::{Path, PathBuf}, + sync::Arc, + }; + + use git2::{Oid, Signature}; + use parking_lot::Mutex; + + use crate::git::{Commit, GitError, Reference, Repository, RepositoryLoadKind}; + + impl Repository { + /// Attempt to open an already-existing repository at `path`. + /// + /// # Errors + /// Will result in an error if the repository cannot be opened. + pub(crate) fn open_from_path(path: &Path) -> Result<Self, GitError> { + let repository = git2::Repository::open(path).map_err(|e| { + GitError::RepositoryLoad { + kind: RepositoryLoadKind::Path, + cause: e, + } + })?; + Ok(Self { + repository: Arc::new(Mutex::new(repository)), + }) + } + + /// Find a reference by the reference name. + /// + /// # Errors + /// Will result in an error if the reference cannot be found. + pub(crate) fn find_reference(&self, reference: &str) -> Result<Reference, GitError> { + let repo = self.repository.lock(); + let git2_reference = repo + .find_reference(reference) + .map_err(|e| GitError::ReferenceNotFound { cause: e })?; + Ok(Reference::from(&git2_reference)) + } + + /// Find a commit by a reference name. + /// + /// # Errors + /// Will result in an error if the reference cannot be found or is not a commit. + pub(crate) fn find_commit(&self, reference: &str) -> Result<Commit, GitError> { + let repo = self.repository.lock(); + let git2_reference = repo + .find_reference(reference) + .map_err(|e| GitError::ReferenceNotFound { cause: e })?; + Commit::try_from(&git2_reference) + } + + pub(crate) fn repo_path(&self) -> PathBuf { + self.repository.lock().path().to_path_buf() + } + + pub(crate) fn head_id(&self, head_name: &str) -> Result<Oid, git2::Error> { + let repo = self.repository.lock(); + let ref_name = format!("refs/heads/{head_name}"); + let revision = repo.revparse_single(ref_name.as_str())?; + Ok(revision.id()) + } + + pub(crate) fn commit_id_from_ref(&self, reference: &str) -> Result<Oid, git2::Error> { + let repo = self.repository.lock(); + let commit = repo.find_reference(reference)?.peel_to_commit()?; + Ok(commit.id()) + } + + pub(crate) fn add_path_to_index(&self, path: &Path) -> Result<(), git2::Error> { + let repo = self.repository.lock(); + let mut index = repo.index()?; + index.add_path(path) + } + + pub(crate) fn remove_path_from_index(&self, path: &Path) -> Result<(), git2::Error> { + let repo = self.repository.lock(); + let mut index = repo.index()?; + index.remove_path(path) + } + + pub(crate) fn create_commit_on_index( + &self, + reference: &str, + author: &Signature<'_>, + committer: &Signature<'_>, + message: &str, + ) -> Result<(), git2::Error> { + let repo = self.repository.lock(); + let tree = repo.find_tree(repo.index()?.write_tree()?)?; + let head = repo.find_reference(reference)?.peel_to_commit()?; + _ = repo.commit(Some("HEAD"), author, committer, message, &tree, &[&head])?; + Ok(()) + } + + pub(crate) fn repository(&self) -> Arc<Mutex<git2::Repository>> { + Arc::clone(&self.repository) + } + } +} + // Paths in Windows makes these tests difficult, so disable #[cfg(all(unix, test))] -mod tests { - use std::env::set_var; +mod unix_tests { + use std::path::Path; use claims::{assert_err_eq, assert_ok}; use git2::{ErrorClass, ErrorCode}; diff --git a/src/input/event_provider.rs b/src/input/event_provider.rs index 5c7264b..e6743a7 100644 --- a/src/input/event_provider.rs +++ b/src/input/event_provider.rs @@ -74,7 +74,7 @@ mod read_event_mocks { mod tests { use std::{io, io::ErrorKind}; - use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseButton}; + use crossterm::event::{KeyCode, KeyModifiers, MouseButton}; use super::*; diff --git a/src/input/standard_event.rs b/src/input/standard_event.rs index 69283a5..59e659d 100644 --- a/src/input/standard_event.rs +++ b/src/input/standard_event.rs @@ -2,6 +2,7 @@ #[derive(Debug, PartialOrd, PartialEq, Eq, Clone, Copy)] #[non_exhaustive] pub(crate) enum StandardEvent { + #[allow(unused)] /// The exit meta event. Exit, /// The kill meta event. diff --git a/src/input/thread/state.rs b/src/input/thread/state.rs index 43fb478..57c0395 100644 --- a/src/input/thread/state.rs +++ b/src/input/thread/state.rs @@ -122,7 +122,6 @@ mod tests { }; use super::*; - use crate::input::Event; fn create_state() -> State { State::new() diff --git a/src/main.rs b/src/main.rs index 03a6b57..962bbcd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,11 +4,13 @@ #![cfg_attr( test, allow( - let_underscore_drop, clippy::cast_possible_truncation, clippy::cognitive_complexity, clippy::let_underscore_must_use, clippy::let_underscore_untyped, + clippy::missing_const_for_fn, + clippy::missing_errors_doc, + clippy::multiple_inherent_impl, clippy::needless_pass_by_value, clippy::panic, clippy::shadow_reuse, @@ -16,12 +18,14 @@ clippy::struct_field_names, clippy::undocumented_unsafe_blocks, clippy::unimplemented, - clippy::unreachable + clippy::unreachable, + clippy::unused_self, + let_underscore_drop, + missing_docs ) )] // allowable upcoming nightly lints #![cfg_attr(include_nightly_lints, allow(clippy::arc_with_non_send_sync))] -#![allow(unused)] mod application; mod arguments; diff --git a/src/modules/confirm_rebase.rs b/src/modules/confirm_rebase.rs index e63efdd..b145a02 100644 --- a/src/modules/confirm_rebase.rs +++ b/src/modules/confirm_rebase.rs @@ -54,7 +54,7 @@ mod tests { assert_results, input::{KeyCode, StandardEvent}, process::Artifact, - test_helpers::testers, + test_helpers::{assertions::assert_rendered_output::AssertRenderOptions, testers}, }; fn create_confirm_rebase() -> ConfirmRebase { diff --git a/src/modules/external_editor/argument_tokenizer.rs b/src/modules/external_editor/argument_tokenizer.rs index c30ad49..75267d7 100644 --- a/src/modules/external_editor/argument_tokenizer.rs +++ b/src/modules/external_editor/argument_tokenizer.rs @@ -1,5 +1,3 @@ -use std::iter::Iterator; - #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum State { Normal, diff --git a/src/modules/external_editor/tests.rs b/src/modules/external_editor/tests.rs index 9c886f1..c519686 100644 --- a/src/modules/external_editor/tests.rs +++ b/src/modules/external_editor/tests.rs @@ -1,14 +1,7 @@ use std::{fs, fs::File}; use super::*; -use crate::{ - assert_rendered_output, - assert_results, - input::{Event, KeyCode}, - module::ExitStatus, - process::Artifact, - test_helpers::testers, -}; +use crate::{assert_rendered_output, assert_results, input::KeyCode, process::Artifact, test_helpers::testers}; fn assert_external_editor_state_eq(actual: &ExternalEditorState, expected: &ExternalEditorState) { let actual_state = match *actual { diff --git a/src/modules/insert/tests.rs b/src/modules/insert/tests.rs index 271fbff..1a11f68 100644 --- a/src/modules/insert/tests.rs +++ b/src/modules/insert/tests.rs @@ -1,11 +1,5 @@ use super::*; -use crate::{ - assert_rendered_output, - assert_results, - input::{Event, KeyCode}, - process::Artifact, - test_helpers::testers, -}; +use crate::{assert_rendered_output, assert_results, input::KeyCode, process::Artifact, test_helpers::testers}; fn create_insert(todo_file: TodoFile) -> Insert { Insert::new(Arc::new(Mutex::new(todo_file))) diff --git a/src/modules/list/search.rs b/src/modules/list/search.rs index fd0e793..3a362ac 100644 --- a/src/modules/list/search.rs +++ b/src/modules/list/search.rs @@ -258,7 +258,7 @@ mod tests { fn search_empty_rebase_file() { with_todo_file(&[], |context| { let (_todo_file_path, todo_file) = context.to_owned(); - let mut search = create_and_run_search(todo_file, "foo", SearchResult::Complete); + let search = create_and_run_search(todo_file, "foo", SearchResult::Complete); assert_eq!(search.total_results(), 0); }); } diff --git a/src/modules/list/tests/abort_and_rebase.rs b/src/modules/list/tests/abort_and_rebase.rs index e064105..8746347 100644 --- a/src/modules/list/tests/abort_and_rebase.rs +++ b/src/modules/list/tests/abort_and_rebase.rs @@ -1,5 +1,5 @@ use super::*; -use crate::{assert_results, process::Artifact, test_helpers::testers}; +use crate::{assert_results, process::Artifact}; #[test] fn normal_mode_abort() { diff --git a/src/modules/list/tests/activate.rs b/src/modules/list/tests/activate.rs index 24dd42e..10b5c49 100644 --- a/src/modules/list/tests/activate.rs +++ b/src/modules/list/tests/activate.rs @@ -4,8 +4,7 @@ use super::*; use crate::{ assert_results, process::Artifact, - search::{Interrupter, SearchResult, Searchable}, - test_helpers::{create_config, testers}, + search::{Interrupter, SearchResult}, }; #[derive(Clone)] @@ -14,7 +13,7 @@ struct MockedSearchable; impl Searchable for MockedSearchable { fn reset(&mut self) {} - fn search(&mut self, _: Interrupter, term: &str) -> SearchResult { + fn search(&mut self, _: Interrupter, _: &str) -> SearchResult { SearchResult::None } } diff --git a/src/modules/list/tests/change_action.rs b/src/modules/list/tests/change_action.rs index 215fd10..b7200be 100644 --- a/src/modules/list/tests/change_action.rs +++ b/src/modules/list/tests/change_action.rs @@ -1,5 +1,5 @@ use super::*; -use crate::{action_line, assert_rendered_output, test_helpers::testers}; +use crate::{action_line, assert_rendered_output}; #[test] fn normal_mode_action_change_to_drop() { diff --git a/src/modules/list/tests/edit_mode.rs b/src/modules/list/tests/edit_mode.rs index 4736a83..579f0aa 100644 --- a/src/modules/list/tests/edit_mode.rs +++ b/src/modules/list/tests/edit_mode.rs @@ -1,5 +1,5 @@ use super::*; -use crate::{assert_rendered_output, assert_results, input::KeyCode, process::Artifact, test_helpers::testers}; +use crate::{assert_rendered_output, assert_results, input::KeyCode, process::Artifact}; #[test] fn edit_with_edit_content() { diff --git a/src/modules/list/tests/external_editor.rs b/src/modules/list/tests/external_editor.rs index 8b0e58c..2 |