From a4ee3d311c7630be9cb9cd232a4ad09afd36fca6 Mon Sep 17 00:00:00 2001 From: Tim Oram Date: Thu, 15 Feb 2024 21:24:36 -0330 Subject: Move testutils crate into test_helpers --- Cargo.lock | 8 -- Cargo.toml | 6 -- src/config.rs | 3 +- src/config/color.rs | 3 +- src/config/git_config.rs | 3 +- src/config/theme.rs | 3 +- src/config/utils/get_bool.rs | 3 +- src/config/utils/get_diff_ignore_whitespace.rs | 3 +- src/config/utils/get_diff_rename.rs | 3 +- src/config/utils/get_diff_show_whitespace.rs | 3 +- src/config/utils/get_input.rs | 3 +- src/config/utils/get_string.rs | 3 +- src/config/utils/get_unsigned_integer.rs | 3 +- src/git/commit.rs | 3 +- src/git/file_status.rs | 3 +- src/git/repository.rs | 3 +- src/packages/testutils/Cargo.toml | 21 ---- src/packages/testutils/Makefile.toml | 2 - src/packages/testutils/README.md | 3 - src/packages/testutils/build.rs | 11 -- src/packages/testutils/src/assert_empty.rs | 71 ------------- src/packages/testutils/src/assert_err_eq.rs | 101 ------------------ src/packages/testutils/src/assert_not_empty.rs | 71 ------------- src/packages/testutils/src/lib.rs | 130 ------------------------ src/runtime/thread_statuses.rs | 3 +- src/test_helpers/assertions.rs | 2 + src/test_helpers/assertions/assert_empty.rs | 19 ++++ src/test_helpers/assertions/assert_not_empty.rs | 19 ++++ src/todo_file.rs | 2 +- src/todo_file/action.rs | 3 +- src/todo_file/history/tests.rs | 2 +- src/todo_file/line.rs | 3 +- src/todo_file/line_parser.rs | 2 +- 33 files changed, 60 insertions(+), 461 deletions(-) delete mode 100644 src/packages/testutils/Cargo.toml delete mode 100644 src/packages/testutils/Makefile.toml delete mode 100644 src/packages/testutils/README.md delete mode 100644 src/packages/testutils/build.rs delete mode 100644 src/packages/testutils/src/assert_empty.rs delete mode 100644 src/packages/testutils/src/assert_err_eq.rs delete mode 100644 src/packages/testutils/src/assert_not_empty.rs delete mode 100644 src/packages/testutils/src/lib.rs create mode 100644 src/test_helpers/assertions/assert_empty.rs create mode 100644 src/test_helpers/assertions/assert_not_empty.rs diff --git a/Cargo.lock b/Cargo.lock index da3c924..de47116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,13 +321,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "girt-testutils" -version = "2.3.0" -dependencies = [ - "rustc_version", -] - [[package]] name = "git-interactive-rebase-tool" version = "2.3.0" @@ -339,7 +332,6 @@ dependencies = [ "claims", "crossbeam-channel", "crossterm", - "girt-testutils", "git2", "if_chain", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 62de962..1724898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,11 +23,6 @@ edition = "2021" name = "interactive-rebase-tool" path = "src/main.rs" -[workspace] -members = [ - "src/packages/testutils", -] - [dependencies] anyhow = "1.0.72" bitflags = "2.4.2" @@ -59,7 +54,6 @@ regex = "1.8.3" rstest = "0.18.1" serial_test = "2.0.0" tempfile = "3.7.0" -girt-testutils = {version = "2.3.0", path = "src/packages/testutils"} [build-dependencies] chrono = "0.4.26" diff --git a/src/config.rs b/src/config.rs index 755458d..fd32bbd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -123,8 +123,7 @@ impl TryFrom<&crate::git::Config> for Config { mod tests { use std::fmt::Debug; - use ::testutils::assert_err_eq; - use claims::assert_ok; + use claims::{assert_err_eq, assert_ok}; use rstest::rstest; use super::*; diff --git a/src/config/color.rs b/src/config/color.rs index 546f631..e455149 100644 --- a/src/config/color.rs +++ b/src/config/color.rs @@ -123,9 +123,8 @@ impl TryFrom<&str> for Color { #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; diff --git a/src/config/git_config.rs b/src/config/git_config.rs index 60b4c45..61fa9da 100644 --- a/src/config/git_config.rs +++ b/src/config/git_config.rs @@ -81,9 +81,8 @@ impl TryFrom<&Config> for GitConfig { mod tests { use std::env::{remove_var, set_var}; - use claims::assert_ok; + use claims::{assert_err_eq, assert_ok}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; use crate::{ diff --git a/src/config/theme.rs b/src/config/theme.rs index 6997120..97da2f2 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -133,9 +133,8 @@ impl TryFrom<&Config> for Theme { #[cfg(test)] mod tests { - use claims::{assert_err, assert_ok}; + use claims::{assert_err, assert_err_eq, assert_ok}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; use crate::{ diff --git a/src/config/utils/get_bool.rs b/src/config/utils/get_bool.rs index 95080d3..c8fa96b 100644 --- a/src/config/utils/get_bool.rs +++ b/src/config/utils/get_bool.rs @@ -31,8 +31,7 @@ pub(crate) fn get_bool(config: Option<&Config>, name: &str, default: bool) -> Re #[cfg(test)] mod tests { - use claims::assert_ok_eq; - use testutils::assert_err_eq; + use claims::{assert_err_eq, assert_ok_eq}; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/config/utils/get_diff_ignore_whitespace.rs b/src/config/utils/get_diff_ignore_whitespace.rs index e572bda..4f5796f 100644 --- a/src/config/utils/get_diff_ignore_whitespace.rs +++ b/src/config/utils/get_diff_ignore_whitespace.rs @@ -23,9 +23,8 @@ pub(crate) fn get_diff_ignore_whitespace( #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/config/utils/get_diff_rename.rs b/src/config/utils/get_diff_rename.rs index c861858..e492502 100644 --- a/src/config/utils/get_diff_rename.rs +++ b/src/config/utils/get_diff_rename.rs @@ -14,9 +14,8 @@ pub(crate) fn git_diff_renames(git_config: Option<&Config>, name: &str) -> Resul #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/config/utils/get_diff_show_whitespace.rs b/src/config/utils/get_diff_show_whitespace.rs index 65934e6..95bea4d 100644 --- a/src/config/utils/get_diff_show_whitespace.rs +++ b/src/config/utils/get_diff_show_whitespace.rs @@ -18,9 +18,8 @@ pub(crate) fn get_diff_show_whitespace( #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/config/utils/get_input.rs b/src/config/utils/get_input.rs index ff68737..bc38e82 100644 --- a/src/config/utils/get_input.rs +++ b/src/config/utils/get_input.rs @@ -76,9 +76,8 @@ pub(crate) fn get_input(config: Option<&Config>, name: &str, default: &str) -> R #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/config/utils/get_string.rs b/src/config/utils/get_string.rs index f97176d..0aae1b0 100644 --- a/src/config/utils/get_string.rs +++ b/src/config/utils/get_string.rs @@ -30,8 +30,7 @@ pub(crate) fn get_string(config: Option<&Config>, name: &str, default: &str) -> #[cfg(test)] mod tests { - use claims::assert_ok_eq; - use testutils::assert_err_eq; + use claims::{assert_err_eq, assert_ok_eq}; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/config/utils/get_unsigned_integer.rs b/src/config/utils/get_unsigned_integer.rs index 5dff94b..2477894 100644 --- a/src/config/utils/get_unsigned_integer.rs +++ b/src/config/utils/get_unsigned_integer.rs @@ -39,8 +39,7 @@ pub(crate) fn get_unsigned_integer(config: Option<&Config>, name: &str, default: #[cfg(test)] mod tests { - use claims::assert_ok_eq; - use testutils::assert_err_eq; + use claims::{assert_err_eq, assert_ok_eq}; use super::*; use crate::test_helpers::{invalid_utf, with_git_config}; diff --git a/src/git/commit.rs b/src/git/commit.rs index 6a04ac2..f55874b 100644 --- a/src/git/commit.rs +++ b/src/git/commit.rs @@ -117,8 +117,7 @@ impl From<&git2::Commit<'_>> for Commit { #[cfg(test)] mod tests { - use claims::{assert_none, assert_some_eq}; - use testutils::assert_err_eq; + use claims::{assert_err_eq, assert_none, assert_some_eq}; use super::*; use crate::test_helpers::{ diff --git a/src/git/file_status.rs b/src/git/file_status.rs index 372b14f..1c59a24 100644 --- a/src/git/file_status.rs +++ b/src/git/file_status.rs @@ -123,9 +123,8 @@ impl FileStatus { #[cfg(test)] mod tests { - use testutils::assert_empty; - use super::*; + use crate::assert_empty; fn create_file_stat() -> FileStatus { FileStatus::new( diff --git a/src/git/repository.rs b/src/git/repository.rs index a8adab4..d415d82 100644 --- a/src/git/repository.rs +++ b/src/git/repository.rs @@ -188,9 +188,8 @@ impl Debug for Repository { mod tests { use std::env::set_var; - use claims::assert_ok; + use claims::{assert_err_eq, assert_ok}; use git2::{ErrorClass, ErrorCode}; - use testutils::assert_err_eq; use super::*; use crate::test_helpers::{create_commit, set_git_directory, with_temp_bare_repository, with_temp_repository}; diff --git a/src/packages/testutils/Cargo.toml b/src/packages/testutils/Cargo.toml deleted file mode 100644 index 20fe926..0000000 --- a/src/packages/testutils/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "girt-testutils" -version = "2.3.0" -authors = ["Tim Oram "] -license = "GPL-3.0-or-later" -description = "Test utils for git-interactive-rebase-tool" -homepage = "https://gitrebasetool.mitmaro.ca/" -repository = "https://github.com/MitMaro/git-interactive-rebase-tool" -edition = "2021" -keywords = ["git", "cli"] -categories = ["command-line-interface", "command-line-utilities", "text-editors"] -readme = "../../README.md" - -[lib] -name = "testutils" - -[dependencies] -[dev-dependencies] - -[build-dependencies] -rustc_version = "0.4.0" diff --git a/src/packages/testutils/Makefile.toml b/src/packages/testutils/Makefile.toml deleted file mode 100644 index c19ab5c..0000000 --- a/src/packages/testutils/Makefile.toml +++ /dev/null @@ -1,2 +0,0 @@ -extend = "../../Makefile.toml" - diff --git a/src/packages/testutils/README.md b/src/packages/testutils/README.md deleted file mode 100644 index 9f1e38f..0000000 --- a/src/packages/testutils/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# GIRT TestUtils Crate - -This crate is part of the larger [Git Interactive Rebase Tool](../../README.md). The version is pinned to the root project, and this crate does not follow SemVer. diff --git a/src/packages/testutils/build.rs b/src/packages/testutils/build.rs deleted file mode 100644 index 4cc52ff..0000000 --- a/src/packages/testutils/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -use rustc_version::{version_meta, Channel}; - -fn main() { - // allow unknown lints in nightly builds - if let Ok(meta) = version_meta() { - if meta.channel == Channel::Nightly { - println!("cargo:rustc-cfg=allow_unknown_lints"); - println!("cargo:rustc-cfg=include_nightly_lints"); - } - } -} diff --git a/src/packages/testutils/src/assert_empty.rs b/src/packages/testutils/src/assert_empty.rs deleted file mode 100644 index a86c32f..0000000 --- a/src/packages/testutils/src/assert_empty.rs +++ /dev/null @@ -1,71 +0,0 @@ -/// Asserts that expression is empty using `is_empty`. -/// -/// ## Uses -/// -/// Assertions are always checked in both debug and release builds, and cannot be disabled. -/// See [`debug_assert_empty!`] for assertions that are not enabled in release builds by default. -/// -/// ## Custom messages -/// -/// This macro has a second form, where a custom panic message can be provided -/// with or without arguments for formatting. See [`std::fmt`] for syntax for this form. -/// -/// ## Examples -/// -/// ```rust -/// use testutils::assert_empty; -/// # fn main() { -/// let vec: Vec = vec![]; -/// -/// assert_empty!(vec); -/// -/// // With custom messages -/// assert_empty!(vec, "Expecting {:?} to be empty", vec); -/// # } -/// ``` -/// -/// A non-empty value will cause a panic: -/// -/// ```rust,should_panic -/// use testutils::assert_empty; -/// # fn main() { -/// let vec: Vec = vec![1]; -/// -/// assert_empty!(vec); // Will panic -/// // -/// # } -/// ``` -/// -/// [`std::fmt`]: https://doc.rust-lang.org/std/fmt/index.html -/// [`debug_assert_empty!`]: ./macro.debug_assert_empty.html -#[macro_export] -macro_rules! assert_empty { - ($expression:expr) => { - assert!($expression.is_empty(), "assertion failed, expected {:?} to be empty", $expression) - }; - ($expression:expr, $($arg:tt)+) => { - assert!( - $expression.is_empty(), - "assertion failed, expected {:?} to be empty: {}", - $expression, - format_args!($($arg)+) - ) - }; -} - -/// Asserts that expression is empty using `is_empty`. -/// -/// Like [`assert_empty!`], this macro also has a second version, -/// where a custom panic message can be provided. -/// -/// ## Uses -/// -/// See [`debug_assert!`] documentation for possible use cases. -/// The same applies to this macro. -/// -/// [`debug_assert!`]: https://doc.rust-lang.org/std/macro.debug_assert.html -/// [`assert_empty!`]: ./macro.assert_empty.html -#[macro_export] -macro_rules! debug_assert_empty { - ($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_empty!($($arg)*); }) -} diff --git a/src/packages/testutils/src/assert_err_eq.rs b/src/packages/testutils/src/assert_err_eq.rs deleted file mode 100644 index 651a609..0000000 --- a/src/packages/testutils/src/assert_err_eq.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Taken and modified from https://github.com/svartalf/rust-claim/commit/815fb7da4965117917406941bc4f3a6b076d1404 -/// Asserts that expression returns [`Err(E)`] variant -/// and its value of `E` type equals to the right expression. -/// -/// ## Uses -/// -/// Assertions are always checked in both debug and release builds, and cannot be disabled. -/// See [`debug_assert_err_eq!`] for assertions that are not enabled in release builds by default. -/// -/// ## Custom messages -/// -/// This macro has a second form, where a custom panic message can be provided -/// with or without arguments for formatting. See [`std::fmt`] for syntax for this form. -/// -/// ## Examples -/// -/// ```rust -/// use testutils::assert_err_eq; -/// # fn main() { -/// let res: Result<(), i32> = Err(1); -/// -/// assert_err_eq!(res, 1); -/// -/// // With custom messages -/// assert_err_eq!(res, 1, "Everything is good with {:?}", res); -/// # } -/// ``` -/// -/// Value of `E` type from `Err(E)` will be returned from the macro call: -/// -/// ```rust -/// use testutils::assert_err_eq; -/// # fn main() { -/// let res: Result<(), i32> = Err(1); -/// -/// let value = assert_err_eq!(res, 1); -/// assert_eq!(value, 1); -/// # } -/// ``` -/// -/// `Ok(..)` variant will cause panic: -/// -/// ```rust,should_panic -/// use testutils::assert_err_eq; -/// # fn main() { -/// let res: Result<(), i32> = Ok(()); -/// -/// assert_err_eq!(res, 1); // Will panic -/// // -/// # } -/// ``` -/// -/// [`Err(E)`]: https://doc.rust-lang.org/core/result/enum.Result.html#variant.Err -/// [`std::fmt`]: https://doc.rust-lang.org/std/fmt/index.html -/// [`debug_assert_err_eq!`]: ./macro.debug_assert_err_eq.html -#[macro_export] -macro_rules! assert_err_eq { - ($cond:expr, $expected:expr,) => { - $crate::assert_err_eq!($cond, $expected); - }; - ($cond:expr, $expected:expr) => { - match $cond { - Err(t) => { - assert_eq!(t, $expected); - t - }, - ok @ Ok(..) => { - panic!("assertion failed, expected Err(..), got {ok:?}"); - } - } - }; - ($cond:expr, $expected:expr, $($arg:tt)+) => { - match $cond { - Err(t) => { - assert_eq!(t, $expected); - t - }, - ok @ Ok(..) => { - panic!("assertion failed, expected Err(..), got {ok:?}: {}", format_args!($($arg)+)); - } - } - }; -} - -/// Asserts that expression returns [`Err(E)`] variant in runtime. -/// -/// Like [`assert_err_eq!`], this macro also has a second version, -/// where a custom panic message can be provided. -/// -/// ## Uses -/// -/// See [`debug_assert!`] documentation for possible use cases. -/// The same applies to this macro. -/// -/// [`Err(E)`]: https://doc.rust-lang.org/core/result/enum.Result.html#variant.Err -/// [`debug_assert!`]: https://doc.rust-lang.org/std/macro.debug_assert.html -/// [`assert_err_eq!`]: ./macro.assert_err_eq.html -#[macro_export] -macro_rules! debug_assert_err_eq { - ($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_err_eq!($($arg)*); }) -} diff --git a/src/packages/testutils/src/assert_not_empty.rs b/src/packages/testutils/src/assert_not_empty.rs deleted file mode 100644 index 8f6d384..0000000 --- a/src/packages/testutils/src/assert_not_empty.rs +++ /dev/null @@ -1,71 +0,0 @@ -/// Asserts that expression is not empty using `is_empty`. -/// -/// ## Uses -/// -/// Assertions are always checked in both debug and release builds, and cannot be disabled. -/// See [`debug_assert_not_empty!`] for assertions that are not enabled in release builds by default. -/// -/// ## Custom messages -/// -/// This macro has a second form, where a custom panic message can be provided -/// with or without arguments for formatting. See [`std::fmt`] for syntax for this form. -/// -/// ## Examples -/// -/// ```rust -/// use testutils::assert_not_empty; -/// # fn main() { -/// let vec: Vec = vec![1]; -/// -/// assert_not_empty!(vec); -/// -/// // With custom messages -/// assert_not_empty!(vec, "Expecting {:?} to not be empty", vec); -/// # } -/// ``` -/// -/// A empty value will cause a panic: -/// -/// ```rust,should_panic -/// use testutils::assert_not_empty; -/// # fn main() { -/// let vec: Vec = vec![]; -/// -/// assert_not_empty!(vec); // Will panic -/// // -/// # } -/// ``` -/// -/// [`std::fmt`]: https://doc.rust-lang.org/std/fmt/index.html -/// [`debug_assert_not_empty!`]: ./macro.debug_assert_not_empty.html -#[macro_export] -macro_rules! assert_not_empty { - ($expression:expr) => { - assert!(!$expression.is_empty(), "assertion failed, expected {:?} to not be empty", $expression) - }; - ($expression:expr, $($arg:tt)+) => { - assert!( - !$expression.is_empty(), - "assertion failed, expected {:?} to not be empty: {}", - $expression, - format_args!($($arg)+) - ) - }; -} - -/// Asserts that expression is not empty using `is_empty`. -/// -/// Like [`assert_not_empty!`], this macro also has a second version, -/// where a custom panic message can be provided. -/// -/// ## Uses -/// -/// See [`debug_assert!`] documentation for possible use cases. -/// The same applies to this macro. -/// -/// [`debug_assert!`]: https://doc.rust-lang.org/std/macro.debug_assert.html -/// [`assert_not_empty!`]: ./macro.assert_not_empty.html -#[macro_export] -macro_rules! debug_assert_not_empty { - ($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_not_empty!($($arg)*); }) -} diff --git a/src/packages/testutils/src/lib.rs b/src/packages/testutils/src/lib.rs deleted file mode 100644 index 259adff..0000000 --- a/src/packages/testutils/src/lib.rs +++ /dev/null @@ -1,130 +0,0 @@ -// nightly sometimes removes/renames lints -#![cfg_attr(allow_unknown_lints, allow(unknown_lints))] -#![cfg_attr(allow_unknown_lints, allow(renamed_and_removed_lints))] -// enable all rustc's built-in lints -#![deny( - future_incompatible, - nonstandard_style, - rust_2018_compatibility, - rust_2018_idioms, - rust_2021_compatibility, - unused, - warnings -)] -// rustc's additional allowed by default lints -#![deny( - absolute_paths_not_starting_with_crate, - deprecated_in_future, - elided_lifetimes_in_paths, - explicit_outlives_requirements, - ffi_unwind_calls, - keyword_idents, - let_underscore_drop, - macro_use_extern_crate, - meta_variable_misuse, - missing_abi, - missing_copy_implementations, - missing_debug_implementations, - missing_docs, - non_ascii_idents, - noop_method_call, - pointer_structural_match, - rust_2021_incompatible_closure_captures, - rust_2021_incompatible_or_patterns, - rust_2021_prefixes_incompatible_syntax, - rust_2021_prelude_collisions, - single_use_lifetimes, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unsafe_code, - unsafe_op_in_unsafe_fn, - unused_crate_dependencies, - unused_extern_crates, - unused_import_braces, - unused_lifetimes, - unused_macro_rules, - unused_qualifications, - unused_results, - unused_tuple_struct_fields, - variant_size_differences -)] -// enable all of Clippy's lints -#![deny(clippy::all, clippy::cargo, clippy::pedantic, clippy::restriction)] -#![allow( - clippy::absolute_paths, - clippy::arithmetic_side_effects, - clippy::arithmetic_side_effects, - clippy::blanket_clippy_restriction_lints, - clippy::bool_to_int_with_if, - clippy::default_numeric_fallback, - clippy::else_if_without_else, - clippy::expect_used, - clippy::float_arithmetic, - clippy::implicit_return, - clippy::indexing_slicing, - clippy::map_err_ignore, - clippy::min_ident_chars, - clippy::missing_docs_in_private_items, - clippy::missing_trait_methods, - clippy::module_name_repetitions, - clippy::needless_raw_string_hashes, - clippy::needless_raw_strings, - clippy::new_without_default, - clippy::non_ascii_literal, - clippy::option_if_let_else, - clippy::pattern_type_mismatch, - clippy::pub_use, - clippy::pub_with_shorthand, - clippy::question_mark_used, - clippy::redundant_closure_call, - clippy::redundant_pub_crate, - clippy::ref_patterns, - clippy::self_named_module_files, - clippy::single_call_fn, - clippy::std_instead_of_alloc, - clippy::std_instead_of_core, - clippy::tabs_in_doc_comments, - clippy::tests_outside_test_module, - clippy::too_many_lines, - clippy::unwrap_used -)] -#![deny( - rustdoc::bare_urls, - rustdoc::broken_intra_doc_links, - rustdoc::invalid_codeblock_attributes, - rustdoc::invalid_html_tags, - rustdoc::missing_crate_level_docs, - rustdoc::private_doc_tests, - rustdoc::private_intra_doc_links -)] -// allow some things in tests -#![cfg_attr( - test, - allow( - let_underscore_drop, - clippy::cognitive_complexity, - clippy::let_underscore_must_use, - clippy::let_underscore_untyped, - clippy::needless_pass_by_value, - clippy::panic, - clippy::shadow_reuse, - clippy::shadow_unrelated, - clippy::undocumented_unsafe_blocks, - clippy::unimplemented, - clippy::unreachable - ) -)] -// allowable upcoming nightly lints -#![cfg_attr(include_nightly_lints, allow(clippy::absolute_paths, clippy::arc_with_non_send_sync))] - -//! Git Interactive Rebase Tool - Test Utils -//! -//! # Description -//! To facilitate testing the usages of this project, this crate contains a set of testing -//! utilities. These utilities are not tested, are often optimized for developer experience, rather -//! than performance, and should only be used in test code. - -mod assert_empty; -mod assert_err_eq; -mod assert_not_empty; diff --git a/src/runtime/thread_statuses.rs b/src/runtime/thread_statuses.rs index c67e787..6498b62 100644 --- a/src/runtime/thread_statuses.rs +++ b/src/runtime/thread_statuses.rs @@ -79,8 +79,7 @@ impl ThreadStatuses { mod tests { use std::{ops::Mul, thread}; - use claims::{assert_err, assert_ok, assert_some_eq}; - use testutils::assert_err_eq; + use claims::{assert_err, assert_err_eq, assert_ok, assert_some_eq}; use super::*; diff --git a/src/test_helpers/assertions.rs b/src/test_helpers/assertions.rs index 0a11cfd..bf4f166 100644 --- a/src/test_helpers/assertions.rs +++ b/src/test_helpers/assertions.rs @@ -1,3 +1,5 @@ +mod assert_empty; +mod assert_not_empty; pub(crate) mod assert_rendered_output; mod assert_results; diff --git a/src/test_helpers/assertions/assert_empty.rs b/src/test_helpers/assertions/assert_empty.rs new file mode 100644 index 0000000..21ebf41 --- /dev/null +++ b/src/test_helpers/assertions/assert_empty.rs @@ -0,0 +1,19 @@ +#[macro_export] +macro_rules! assert_empty { + ($expression:expr) => { + assert!($expression.is_empty(), "assertion failed, expected {:?} to be empty", $expression) + }; + ($expression:expr, $($arg:tt)+) => { + assert!( + $expression.is_empty(), + "assertion failed, expected {:?} to be empty: {}", + $expression, + format_args!($($arg)+) + ) + }; +} + +#[macro_export] +macro_rules! debug_assert_empty { + ($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_empty!($($arg)*); }) +} diff --git a/src/test_helpers/assertions/assert_not_empty.rs b/src/test_helpers/assertions/assert_not_empty.rs new file mode 100644 index 0000000..c4f884c --- /dev/null +++ b/src/test_helpers/assertions/assert_not_empty.rs @@ -0,0 +1,19 @@ +#[macro_export] +macro_rules! assert_not_empty { + ($expression:expr) => { + assert!(!$expression.is_empty(), "assertion failed, expected {:?} to not be empty", $expression) + }; + ($expression:expr, $($arg:tt)+) => { + assert!( + !$expression.is_empty(), + "assertion failed, expected {:?} to not be empty: {}", + $expression, + format_args!($($arg)+) + ) + }; +} + +#[macro_export] +macro_rules! debug_assert_not_empty { + ($($arg:tt)*) => (if cfg!(debug_assertions) { $crate::assert_not_empty!($($arg)*); }) +} diff --git a/src/todo_file.rs b/src/todo_file.rs index f37f1e5..59ae9a6 100644 --- a/src/todo_file.rs +++ b/src/todo_file.rs @@ -382,9 +382,9 @@ impl TodoFile { mod tests { use claims::{assert_none, assert_some_eq}; use tempfile::{Builder, NamedTempFile}; - use testutils::{assert_empty, assert_not_empty}; use super::*; + use crate::{assert_empty, assert_not_empty}; fn create_line(line: &str) -> Line { Line::parse(line).unwrap() diff --git a/src/todo_file/action.rs b/src/todo_file/action.rs index ec64ae5..f57f47a 100644 --- a/src/todo_file/action.rs +++ b/src/todo_file/action.rs @@ -110,9 +110,8 @@ impl TryFrom<&str> for Action { #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; diff --git a/src/todo_file/history/tests.rs b/src/todo_file/history/tests.rs index 726557b..f92048a 100644 --- a/src/todo_file/history/tests.rs +++ b/src/todo_file/history/tests.rs @@ -1,7 +1,7 @@ use claims::assert_some_eq; -use testutils::assert_empty; use super::*; +use crate::assert_empty; fn history_item_to_string(item: &HistoryItem) -> String { let range = if item.start_index == item.end_index { diff --git a/src/todo_file/line.rs b/src/todo_file/line.rs index 6b4616b..56389f4 100644 --- a/src/todo_file/line.rs +++ b/src/todo_file/line.rs @@ -230,9 +230,8 @@ impl Line { #[cfg(test)] mod tests { - use claims::assert_ok_eq; + use claims::{assert_err_eq, assert_ok_eq}; use rstest::rstest; - use testutils::assert_err_eq; use super::*; diff --git a/src/todo_file/line_parser.rs b/src/todo_file/line_parser.rs index 9a2af44..2f9eded 100644 --- a/src/todo_file/line_parser.rs +++ b/src/todo_file/line_parser.rs @@ -56,7 +56,7 @@ impl<'line> LineParser<'line> { #[cfg(test)] mod tests { - use testutils::assert_err_eq; + use claims::assert_err_eq; use super::*; -- cgit v1.2.3