diff --git a/.gitignore b/.gitignore index e2a3069..7f7d777 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target *~ +test-input diff --git a/Cargo.lock b/Cargo.lock index 9665fb0..52544c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,6 +435,7 @@ dependencies = [ "futures", "sha2", "tokio", + "tokio-test", ] [[package]] @@ -554,6 +555,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-test" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed0049c119b6d505c4447f5c64873636c7af6c75ab0d45fd9f618d82acb8016d" +dependencies = [ + "bytes", + "futures-core", + "tokio", +] + [[package]] name = "typenum" version = "1.12.0" diff --git a/Cargo.toml b/Cargo.toml index 0ec159c..7ae51cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,9 @@ codegen-units = 1 [features] threads = ["tokio", "futures"] +[dev-dependencies] +tokio-test = "0.2" + [dependencies] tokio = { version = "0.2", features = ["full"], optional = true } sha2 = "0.9" diff --git a/src/config.rs b/src/config.rs index 24f3d5c..d04006a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,11 +8,19 @@ pub enum RecursionMode N(usize), } +#[derive(Debug, Clone)] +pub enum OperationMode +{ + Print, + Delete, +} + #[derive(Debug, Clone)] pub struct Mode { pub error_mode: error::Mode, pub recursion_mode: RecursionMode, + pub operation_mode: OperationMode, } impl Default for Mode @@ -22,6 +30,7 @@ impl Default for Mode Self { error_mode: error::Mode::Cancel, recursion_mode: RecursionMode::None, + operation_mode: OperationMode::Print, } } } diff --git a/src/main.rs b/src/main.rs index aadc2b5..7f41513 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,48 @@ mod container; mod config; mod proc; +#[cfg(test)] +mod test { + use super::*; + use std::{ + path::Path, + }; + + #[test] + pub fn test() -> Result<(), error::Error> + { + let mut cont = container::DupeMap::new(); + let mode = config::Mode::default(); + let path = Path::new("test-input"); + + assert_eq!(proc::DupeCount{total:4, dupes:2}, proc::do_dir(path, 0, &mut cont, &mode)?); + + Ok(()) + } + + #[cfg(feature="threads")] + pub async fn _test_async() -> Result<(), error::Error> + { + use std::sync::Arc; + use tokio::{ + sync::Mutex, + }; + let cont = Arc::new(Mutex::new(container::DupeMap::new())); + let mode = config::Mode::default(); + let path = Path::new("test-input"); + + assert_eq!(proc::DupeCount{total:4, dupes:2}, proc::do_dir_async(path, 0, cont, mode).await?); + + Ok(()) + } + #[cfg(feature="threads")] + #[test] + pub fn test_async() -> Result<(), error::Error> + { + tokio_test::block_on(_test_async()) + } +} + fn main() { } diff --git a/src/proc.rs b/src/proc.rs index f8746c9..160e66f 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -18,6 +18,23 @@ use std::{ }, }; +/// Handle a detected dupe +fn handle_dupe
(path: P, _mode: &config::Mode) -> Result<(), error::Error>
+where P: AsRef (path: P, mode: &config::Mode) -> Result<(), error::Error>
+where P: AsRef