]> git.lizzy.rs Git - rust.git/commitdiff
use entry file_type, improve test
authorBernardo <berublan@gmail.com>
Fri, 25 Jan 2019 21:13:55 +0000 (22:13 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 26 Jan 2019 08:46:37 +0000 (11:46 +0300)
crates/ra_vfs/src/io/watcher.rs
crates/ra_vfs/src/lib.rs
crates/ra_vfs/tests/vfs.rs

index 1d7ce213670e6805119f257161b8385b4b868c88..ff6775f59402cf13c65bebf496d78109aed917f8 100644 (file)
@@ -65,7 +65,7 @@ pub fn watch_root(&mut self, filter: &RootFilter) {
         {
             match res {
                 Ok(entry) => {
-                    if entry.path().is_dir() {
+                    if entry.file_type().is_dir() {
                         watch_one(self.watcher.as_ref(), entry.path());
                     }
                 }
@@ -172,11 +172,11 @@ fn watch_recursive(&self, dir: &Path, root: VfsRoot) {
         let filter = &self.roots[root];
         for res in WalkDir::new(dir)
             .into_iter()
-            .filter_entry(|entry| filter.can_contain(entry.path()).is_some())
+            .filter_entry(filter.entry_filter())
         {
             match res {
                 Ok(entry) => {
-                    if entry.path().is_dir() {
+                    if entry.file_type().is_dir() {
                         watch_one(self.watcher.as_ref(), entry.path());
                     } else {
                         // emit only for files otherwise we will cause watch_recursive to be called again with a dir that we are already watching
index 661892f8a25f1ba78aeed1b345828f0a15d24bd2..d1b0222e79f64420767bb1ce48b85ced2966071a 100644 (file)
@@ -62,7 +62,8 @@ pub(crate) fn can_contain(&self, path: &Path) -> Option<RelativePathBuf> {
 
     pub(crate) fn entry_filter<'a>(&'a self) -> impl FnMut(&DirEntry) -> bool + 'a {
         move |entry: &DirEntry| {
-            if entry.path().is_dir() && self.excluded_dirs.iter().any(|it| it == entry.path()) {
+            if entry.file_type().is_dir() && self.excluded_dirs.iter().any(|it| it == entry.path())
+            {
                 // do not walk nested roots
                 false
             } else {
index 8562c56b963e660cdff5db0dafafaf2534368619..357e1c775e2614ec09c3a264ecc32a62239d90ab 100644 (file)
@@ -1,12 +1,16 @@
-use std::{collections::HashSet, fs};
+use std::{collections::HashSet, fs, time::Duration};
 
-use flexi_logger::Logger;
+// use flexi_logger::Logger;
+use crossbeam_channel::RecvTimeoutError;
 use ra_vfs::{Vfs, VfsChange};
 use tempfile::tempdir;
 
 fn process_tasks(vfs: &mut Vfs, num_tasks: u32) {
     for _ in 0..num_tasks {
-        let task = vfs.task_receiver().recv().unwrap();
+        let task = vfs
+            .task_receiver()
+            .recv_timeout(Duration::from_secs(3))
+            .unwrap();
         log::debug!("{:?}", task);
         vfs.handle_task(task);
     }
@@ -14,7 +18,7 @@ fn process_tasks(vfs: &mut Vfs, num_tasks: u32) {
 
 macro_rules! assert_match {
     ($x:expr, $pat:pat) => {
-        assert_match!($x, $pat, assert!(true))
+        assert_match!($x, $pat, ())
     };
     ($x:expr, $pat:pat, $assert:expr) => {
         match $x {
@@ -26,7 +30,7 @@ macro_rules! assert_match {
 
 #[test]
 fn test_vfs_works() -> std::io::Result<()> {
-    Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
+    // Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
 
     let files = [
         ("a/foo.rs", "hello"),
@@ -166,8 +170,8 @@ fn test_vfs_works() -> std::io::Result<()> {
     fs::write(&dir.path().join("a/target/new.rs"), "ignore me").unwrap();
 
     assert_match!(
-        vfs.task_receiver().try_recv(),
-        Err(crossbeam_channel::TryRecvError::Empty)
+        vfs.task_receiver().recv_timeout(Duration::from_millis(300)), // slightly more than watcher debounce delay
+        Err(RecvTimeoutError::Timeout)
     );
 
     vfs.shutdown().unwrap();