From 1acf6e4d35a0a8f9035f285f7b9acae3afa313dd Mon Sep 17 00:00:00 2001 From: figsoda Date: Sat, 16 Oct 2021 10:10:48 -0400 Subject: [PATCH 1/2] tests: apply clippy lints --- tests/compress_and_decompress.rs | 4 ++-- tests/compress_empty_dir.rs | 4 ++-- tests/utils.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/compress_and_decompress.rs b/tests/compress_and_decompress.rs index e97ab33..6e6649f 100644 --- a/tests/compress_and_decompress.rs +++ b/tests/compress_and_decompress.rs @@ -103,9 +103,9 @@ fn test_compressing_and_decompressing_archive(format: &str) { (0..quantity_of_files).map(|_| generate_random_file_content(&mut rng)).collect(); // Create them - let mut file_paths = create_files(&testing_dir_path, &contents_of_files); + let mut file_paths = create_files(testing_dir_path, &contents_of_files); // Compress them - let compressed_archive_path = compress_files(&testing_dir_path, &file_paths, &format); + let compressed_archive_path = compress_files(testing_dir_path, &file_paths, format); // Decompress them let mut extracted_paths = extract_files(&compressed_archive_path); diff --git a/tests/compress_empty_dir.rs b/tests/compress_empty_dir.rs index 95f3348..57bfe35 100644 --- a/tests/compress_empty_dir.rs +++ b/tests/compress_empty_dir.rs @@ -20,11 +20,11 @@ fn test_compress_decompress_with_empty_dir(format: &str) { let testing_dir_path = testing_dir.path(); - let empty_dir_path: PathBuf = create_empty_dir(&testing_dir_path, "dummy_empty_dir_name"); + let empty_dir_path: PathBuf = create_empty_dir(testing_dir_path, "dummy_empty_dir_name"); let mut file_paths: Vec = vec![empty_dir_path]; - let compressed_archive_path: PathBuf = compress_files(&testing_dir_path, &file_paths, &format); + let compressed_archive_path: PathBuf = compress_files(testing_dir_path, &file_paths, format); let mut extracted_paths = extract_files(&compressed_archive_path); diff --git a/tests/utils.rs b/tests/utils.rs index 3ab9831..05b4b0f 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -22,7 +22,7 @@ pub fn compress_files(at: &Path, paths_to_compress: &[PathBuf], format: &str) -> let archive_path = String::from("archive.") + format; let archive_path = at.join(archive_path); - let command = Command::Compress { files: paths_to_compress.to_vec(), output_path: archive_path.to_path_buf() }; + let command = Command::Compress { files: paths_to_compress.to_vec(), output_path: archive_path.clone() }; run(command, &oof::Flags::default()).expect("Failed to compress test dummy files"); archive_path From 2feefb3ca35b210e41c3f132210ce01cfebc38e6 Mon Sep 17 00:00:00 2001 From: figsoda Date: Sun, 17 Oct 2021 17:54:40 -0400 Subject: [PATCH 2/2] minor cleanups --- src/macros.rs | 11 +++-------- src/oof/util.rs | 19 +------------------ src/utils.rs | 9 ++------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 14996e3..76877fa 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,13 +1,8 @@ #[macro_export] macro_rules! info { - ($writer:expr, $($arg:tt)*) => { - use crate::macros::_info_helper; - _info_helper(); - println!($writer, $($arg)*); - }; - ($writer:expr) => { - _info_helper(); - println!($writer); + ($($arg:tt)*) => { + $crate::macros::_info_helper(); + println!($($arg)*); }; } diff --git a/src/oof/util.rs b/src/oof/util.rs index 5479818..0e75350 100644 --- a/src/oof/util.rs +++ b/src/oof/util.rs @@ -1,23 +1,11 @@ /// Util function to skip the two leading long flag hyphens. pub fn trim_double_hyphen(flag_text: &str) -> &str { - let mut chars = flag_text.chars(); - chars.nth(1); // Skipping 2 chars - chars.as_str() -} - -// Currently unused -/// Util function to skip the single leading short flag hyphen. -pub fn trim_single_hyphen(flag_text: &str) -> &str { - let mut chars = flag_text.chars(); - - chars.next(); // Skipping 1 char - chars.as_str() + flag_text.get(2..).unwrap_or_default() } #[cfg(test)] mod tests { use super::trim_double_hyphen; - use super::trim_single_hyphen; #[test] fn _trim_double_hyphen() { @@ -25,9 +13,4 @@ mod tests { assert_eq!(trim_double_hyphen("--verbose"), "verbose"); assert_eq!(trim_double_hyphen("--help"), "help"); } - - fn _trim_single_hyphen() { - assert_eq!(trim_single_hyphen("-vv"), "vv"); - assert_eq!(trim_single_hyphen("-h"), "h"); - } } diff --git a/src/utils.rs b/src/utils.rs index a372051..71e0337 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,7 +11,7 @@ use crate::{dialogs::Confirmation, info, oof}; pub fn dir_is_empty(dir_path: &Path) -> bool { let is_empty = |mut rd: ReadDir| rd.next().is_none(); - dir_path.read_dir().ok().map(is_empty).unwrap_or_default() + dir_path.read_dir().map(is_empty).unwrap_or_default() } pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { @@ -45,12 +45,7 @@ pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result _ => {} } - let file_path_str = to_utf(path); - - const OVERWRITE_CONFIRMATION_QUESTION: Confirmation = - Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")); - - OVERWRITE_CONFIRMATION_QUESTION.ask(Some(&file_path_str)) + Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path))) } pub fn to_utf(os_str: impl AsRef) -> String {