diff options
author | Tom Barrett <spalf0@gmail.com> | 2019-08-19 09:10:34 -0500 |
---|---|---|
committer | Tom Barrett <spalf0@gmail.com> | 2019-08-19 09:10:34 -0500 |
commit | f29c854251ee0f47a94fb88fd94b9c24809c53a2 (patch) | |
tree | e110b539b0c5c37db37f30ecb8031aa7fbbd4e87 /tests | |
parent | c79294e0bdd3f045e2de4215f71db262c6e94848 (diff) |
fixed restore bug and wrote test for it, added ideas to readme, created all_paths functionHEADmaster
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.rs | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/tests/tests.rs b/tests/tests.rs index 2a7b6e8..bfdab2a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -3,9 +3,9 @@ extern crate rsycle; #[cfg(test)] mod tests { use rsycle::main::{build_path, empty, list, restore, rsycle}; + use std::ffi::OsStr; use std::fs; use std::path::{Component, PathBuf}; - use std::ffi::OsStr; fn gen_rsyclebin(dir_name: &str) -> PathBuf { let mut rsyclebin = dirs::home_dir().unwrap(); @@ -18,34 +18,56 @@ mod tests { #[test] fn test_basics() { - test_rsycle("test_file".as_ref(), gen_rsyclebin(".test_rsyclebin")); - test_rsycle("../test_file_relative".as_ref(), gen_rsyclebin(".test_rsyclebin_relative")); + let filename = "test_file".as_ref(); + let test_path: PathBuf = [Component::CurDir, Component::Normal(filename)] + .iter() + .collect(); + assert!(!test_path.exists()); + fs::File::create(test_path.clone()).unwrap(); + + let test_rsyclebin = gen_rsyclebin(".test_rsyclebin"); + test_rsycle(filename, test_rsyclebin.clone()); + test_restore(filename, test_rsyclebin.clone()); + test_cleanup(test_path, test_rsyclebin); } - fn test_rsycle(filename: &OsStr, rsyclebin: PathBuf) { - let mut test_path: PathBuf = [Component::CurDir, Component::Normal(filename)] + #[test] + fn test_relative() { + let filename = "../test_relative_file".as_ref(); + let test_path: PathBuf = [Component::CurDir, Component::Normal(filename)] .iter() .collect(); - assert!(!test_path.exists()); - fs::File::create(test_path.clone()).unwrap(); - test_path = build_path(filename.to_str().unwrap()).unwrap(); + let test_rsyclebin = gen_rsyclebin(".test_relative_rsyclebin"); + test_rsycle(filename, test_rsyclebin.clone()); + test_restore(filename, test_rsyclebin.clone()); + test_cleanup(test_path, test_rsyclebin); + } + + fn test_rsycle(filename: &OsStr, rsyclebin: PathBuf) { + let test_path = build_path(filename.to_str().unwrap()).unwrap(); assert!(rsycle(rsyclebin.clone(), test_path.clone()).is_ok()); assert!(!test_path.exists()); assert!(list(rsyclebin.clone()).is_ok()); + } + + fn test_restore(filename: &OsStr, rsyclebin: PathBuf) { + let test_path = build_path(filename.to_str().unwrap()).unwrap(); assert!(restore(rsyclebin.clone(), test_path.clone()).is_ok()); assert!(test_path.exists()); + } + fn test_cleanup(path: PathBuf, rsyclebin: PathBuf) { assert!(empty(rsyclebin.clone()).is_ok()); - fs::remove_file(test_path).unwrap(); + fs::remove_file(path).unwrap(); fs::remove_dir_all(rsyclebin).unwrap(); } } |