diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-02-17 19:11:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 13:11:45 -0500 |
commit | 95563476f604c33e91d66e164e7a804c356c0802 (patch) | |
tree | 512a0812fb30f1cb0eea7f481177b41e9601c1a8 /cli/fs.rs | |
parent | 19080667534954ac75caa1bcf34e3a55d5d55e4c (diff) |
fix(deno test): support directories as arguments (#4011)
Diffstat (limited to 'cli/fs.rs')
-rw-r--r-- | cli/fs.rs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -9,6 +9,7 @@ use deno_core::ErrBox; use rand; use rand::Rng; use url::Url; +use walkdir::WalkDir; #[cfg(unix)] use nix::unistd::{chown as unix_chown, Gid, Uid}; @@ -188,3 +189,17 @@ mod tests { assert_eq!(resolve_from_cwd(expected).unwrap(), expected); } } + +pub fn files_in_subtree<F>(root: PathBuf, filter: F) -> Vec<PathBuf> +where + F: Fn(&Path) -> bool, +{ + assert!(root.is_dir()); + + WalkDir::new(root) + .into_iter() + .filter_map(|e| e.ok()) + .map(|e| e.path().to_owned()) + .filter(|p| if p.is_dir() { false } else { filter(&p) }) + .collect() +} |