From 253cedcf603bfd58d0b2b20a160ab338139b9972 Mon Sep 17 00:00:00 2001 From: figsoda Date: Thu, 4 Nov 2021 16:23:09 -0400 Subject: [PATCH] crate dir-diff -> fn assert_same_directory --- Cargo.lock | 10 ------- Cargo.toml | 1 - tests/integration.rs | 10 +++---- tests/utils.rs | 66 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index de477fb..fa95b94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,15 +187,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" -[[package]] -name = "dir-diff" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2860407d7d7e2e004bb2128510ad9e8d669e76fa005ccf567977b5d71b8b4a0b" -dependencies = [ - "walkdir", -] - [[package]] name = "doc-comment" version = "0.3.3" @@ -415,7 +406,6 @@ dependencies = [ "bzip2", "clap", "clap_generate", - "dir-diff", "flate2", "fs-err", "infer", diff --git a/Cargo.toml b/Cargo.toml index 7aa78ec..0f28aef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ clap_generate = "=3.0.0-beta.5" [dev-dependencies] assert_cmd = "2.0.2" -dir-diff = "0.3.2" infer = "0.5.0" parse-display = "0.5.3" proptest = "1.0.0" diff --git a/tests/integration.rs b/tests/integration.rs index 03146a9..3929378 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -10,7 +10,7 @@ use rand::{rngs::SmallRng, RngCore, SeedableRng}; use tempfile::tempdir; use test_strategy::{proptest, Arbitrary}; -use crate::utils::create_file_random; +use crate::utils::{assert_same_directory, create_file_random}; #[derive(Arbitrary, Debug, Display)] #[display(style = "snake_case")] @@ -76,7 +76,7 @@ fn single_empty_file(ext: Extension, #[any(size_range(0..8).lift())] exts: Vec, y: impl Into, preserve_permissions: bool) { + fn read_dir(dir: impl Into) -> impl Iterator { + let mut dir: Vec<_> = fs::read_dir(dir).unwrap().map(|entry| entry.unwrap()).collect(); + dir.sort_by_key(|x| x.file_name()); + dir.into_iter() + } + + let mut x = read_dir(x); + let mut y = read_dir(y); + + loop { + match (x.next(), y.next()) { + (Some(x), Some(y)) => { + assert_eq!(x.file_name(), y.file_name()); + + let meta_x = x.metadata().unwrap(); + let meta_y = y.metadata().unwrap(); + let ft_x = meta_x.file_type(); + let ft_y = meta_y.file_type(); + + #[cfg(unix)] + if preserve_permissions { + assert_eq!(ft_x, ft_y); + } + + if ft_x.is_dir() && ft_y.is_dir() { + assert_same_directory(x.path(), y.path(), preserve_permissions); + } else if ft_x.is_file() && ft_y.is_file() { + assert_eq!(meta_x.len(), meta_y.len()); + assert_eq!(fs::read(x.path()).unwrap(), fs::read(y.path()).unwrap()); + } else { + panic!( + "entries should be both directories or both files\n left: `{:?}`,\n right: `{:?}`", + x.path(), + y.path() + ); + } + } + + (None, None) => break, + + (x, y) => { + panic!( + "directories don't have the same number of entires\n left: `{:?}`,\n right: `{:?}`", + x.map(|x| x.path()), + y.map(|y| y.path()), + ) + } + } + } +} + +#[test] +fn src_is_src() { + assert_same_directory("src", "src", true); +} + +#[test] +#[should_panic] +fn src_is_not_tests() { + assert_same_directory("src", "tests", false); +}