summaryrefslogtreecommitdiff
path: root/cli/fs.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-02-17 19:11:45 +0100
committerGitHub <noreply@github.com>2020-02-17 13:11:45 -0500
commit95563476f604c33e91d66e164e7a804c356c0802 (patch)
tree512a0812fb30f1cb0eea7f481177b41e9601c1a8 /cli/fs.rs
parent19080667534954ac75caa1bcf34e3a55d5d55e4c (diff)
fix(deno test): support directories as arguments (#4011)
Diffstat (limited to 'cli/fs.rs')
-rw-r--r--cli/fs.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/cli/fs.rs b/cli/fs.rs
index 8d3a31bb5..521b996ac 100644
--- a/cli/fs.rs
+++ b/cli/fs.rs
@@ -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()
+}