From d44041040d755306c39d6de8da5b42d7ded6808c Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 25 Sep 2024 15:13:34 +0200 Subject: added notifications and improved stuff --- src/pathinfo.rs | 110 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 54 deletions(-) (limited to 'src/pathinfo.rs') diff --git a/src/pathinfo.rs b/src/pathinfo.rs index 1231ff8..009f46a 100644 --- a/src/pathinfo.rs +++ b/src/pathinfo.rs @@ -6,7 +6,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use tracing::{debug, info}; +use tracing::{debug, info, trace}; use crate::{ backup::{Backup, Id}, @@ -35,7 +35,7 @@ impl PathInfo { rel_location: &str, location_root: &LocationRoot, ) -> Result { - info!("Handling {rel_location}"); + trace!("Handling {rel_location}"); let path = Self::get_abs_path(&location_root.to_string(), rel_location); Ok(if path.is_dir() { let mut last_modified = Some(String::new()); @@ -83,7 +83,7 @@ impl PathInfo { ) -> Result { let last_modified = Self::compare_to_last_modified(config, location_root, rel_location)?; - info!("From file {rel_location} ({last_modified:?})"); + debug!("From file {rel_location} ({last_modified:?})"); Ok(Self { rel_location: rel_location.to_string(), @@ -301,14 +301,15 @@ mod tests { .custom_directories .insert("test".to_string(), "/usr/local/test".to_string()); - let mut values_ok: Vec<(&str, LocationRoot)> = Vec::new(); - values_ok.push(("u:test", LocationRoot::User)); - values_ok.push(("s:", LocationRoot::SystemConfig)); - values_ok.push(("r:", LocationRoot::Root)); - values_ok.push(( - "c:test", - LocationRoot::Custom("/usr/local/test".to_string()), - )); + let values_ok = vec![ + ("u:test", LocationRoot::User), + ("s:", LocationRoot::SystemConfig), + ("r:", LocationRoot::Root), + ( + "c:test", + LocationRoot::Custom("/usr/local/test".to_string()), + ), + ]; for value in values_ok { println!("Testing {value:?}"); @@ -316,18 +317,19 @@ mod tests { println!("\x1B[FTesting {value:?} ✓"); } - let mut values_err: Vec<(&str, String)> = Vec::new(); - values_err.push(( - "c:rest", - Error::CustomDirectory("rest".to_string()).to_string(), - )); - values_err.push(("t:test/", Error::InvalidIndex("t".to_string()).to_string())); - values_err.push(( - "test:test/usr", - Error::InvalidIndex("test".to_string()).to_string(), - )); - values_err.push(("/usr/local/test", Error::NoIndex.to_string())); - values_err.push(("c/usr/local/test", Error::NoIndex.to_string())); + let values_err = vec![ + ( + "c:rest", + Error::CustomDirectory("rest".to_string()).to_string(), + ), + ("t:test/", Error::InvalidIndex("t".to_string()).to_string()), + ( + "test:test/usr", + Error::InvalidIndex("test".to_string()).to_string(), + ), + ("/usr/local/test", Error::NoIndex.to_string()), + ("c/usr/local/test", Error::NoIndex.to_string()), + ]; for value in values_err { println!("Testing {value:?}"); @@ -351,47 +353,47 @@ mod tests { .custom_directories .insert("test".to_string(), "/usr/local/test".to_string()); - let mut values_ok: Vec<(&str, (String, LocationRoot))> = Vec::new(); - values_ok.push(( - "~/.config/nvim", - (".config/nvim".to_string(), LocationRoot::User), - )); - values_ok.push(( - "u:test/.config/nvim", - (".config/nvim".to_string(), LocationRoot::User), - )); - values_ok.push(( - "r:/.config/nvim", - (".config/nvim".to_string(), LocationRoot::Root), - )); - values_ok.push(( - "r:/.config/nvim", - (".config/nvim".to_string(), LocationRoot::Root), - )); - values_ok.push(( - "s:/.config/nvim", - (".config/nvim".to_string(), LocationRoot::SystemConfig), - )); - values_ok.push(( - "c:test/.config/nvim", + let values_ok = vec![ ( - ".config/nvim".to_string(), - LocationRoot::Custom("/usr/local/test".to_string()), + "~/.config/nvim", + (".config/nvim".to_string(), LocationRoot::User), + ), + ( + "u:test/.config/nvim", + (".config/nvim".to_string(), LocationRoot::User), ), - )); + ( + "r:/.config/nvim", + (".config/nvim".to_string(), LocationRoot::Root), + ), + ( + "r:/.config/nvim", + (".config/nvim".to_string(), LocationRoot::Root), + ), + ( + "s:/.config/nvim", + (".config/nvim".to_string(), LocationRoot::SystemConfig), + ), + ( + "c:test/.config/nvim", + ( + ".config/nvim".to_string(), + LocationRoot::Custom("/usr/local/test".to_string()), + ), + ), + ]; for value in values_ok { print!("Testing {value:?}"); - assert_eq!(PathInfo::parse_location(&value.0, &config)?, value.1); + assert_eq!(PathInfo::parse_location(value.0, &config)?, value.1); println!("\x1B[FTesting {value:?} ✓"); } Ok(()) } #[test] - fn compare_to_last_modified() -> color_eyre::Result<()> { - let mut config = Config::default(); - config.root = "./backup-test".to_string(); + fn compare_to_last_modified() -> Result<()> { + let mut config = Config { root: "./backup-test".to_string(), ..Default::default() }; config .directories .push("u:fx/code/proj/arbs/backup-test-dir".to_string()); @@ -404,7 +406,7 @@ mod tests { let mut f = File::create("./backup-test-dir/nothing.txt")?; f.write_all("unmodified".as_bytes())?; - let backup = Backup::create(&config, None)?; + let backup = Backup::create(&config)?; backup.save(&config)?; let mut f = File::create("./backup-test-dir/size.txt")?; -- cgit v1.2.3