changeset 571:f7eb588de00d

Experiment: provide alternative path separator tests for mem env on windows
author Lewin Bormann <lbo@spheniscida.de>
date Fri, 08 Jul 2022 15:03:54 -0700
parents 6f87d002b918
children 7575b9ee7b71
files src/mem_env.rs
diffstat 1 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/mem_env.rs	Fri Jul 08 14:58:11 2022 -0700
+++ b/src/mem_env.rs	Fri Jul 08 15:03:54 2022 -0700
@@ -508,6 +508,7 @@
         Path::new(x).to_owned()
     }
 
+    #[cfg(unix)]
     #[test]
     fn test_mem_fs_children() {
         let fs = MemFS::new();
@@ -532,6 +533,31 @@
         );
     }
 
+    #[cfg(windows)]
+    #[test]
+    fn test_mem_fs_children() {
+        let fs = MemFS::new();
+        let (path1, path2, path3) = (
+            Path::new("\\a\\1.txt"),
+            Path::new("\\a\\2.txt"),
+            Path::new("\\b\\1.txt"),
+        );
+
+        for p in &[&path1, &path2, &path3] {
+            fs.open_w(*p, false, false).unwrap();
+        }
+        let children = fs.children_of(&Path::new("\\a")).unwrap();
+        assert!(
+            (children == vec![s2p("1.txt"), s2p("2.txt")])
+                || (children == vec![s2p("2.txt"), s2p("1.txt")])
+        );
+        let children = fs.children_of(&Path::new("\\a\\")).unwrap();
+        assert!(
+            (children == vec![s2p("1.txt"), s2p("2.txt")])
+                || (children == vec![s2p("2.txt"), s2p("1.txt")])
+        );
+    }
+
     #[test]
     fn test_mem_fs_lock() {
         let fs = MemFS::new();
@@ -571,6 +597,7 @@
             .is_ok());
     }
 
+    #[cfg(unix)]
     #[test]
     fn test_memenv_all() {
         let me = MemEnv::new();
@@ -603,4 +630,38 @@
         assert!(me.micros() > 0);
         me.sleep_for(10);
     }
+
+    #[cfg(windows)]
+    #[test]
+    fn test_memenv_all() {
+        let me = MemEnv::new();
+        let (p1, p2, p3) = (Path::new("\\a\\b"), Path::new("\\a\\c"), Path::new("\\a\\d"));
+        let nonexist = Path::new("\\x\\y");
+        me.open_writable_file(p2).unwrap();
+        me.open_appendable_file(p3).unwrap();
+        me.open_sequential_file(p2).unwrap();
+        me.open_random_access_file(p3).unwrap();
+
+        assert!(me.exists(p2).unwrap());
+        assert_eq!(me.children(Path::new("\\a\\")).unwrap().len(), 2);
+        assert_eq!(me.size_of(p2).unwrap(), 0);
+
+        me.delete(p2).unwrap();
+        assert!(me.mkdir(p3).is_err());
+        me.mkdir(p1).unwrap();
+        me.rmdir(p3).unwrap();
+        assert!(me.rmdir(nonexist).is_err());
+
+        me.open_writable_file(p1).unwrap();
+        me.rename(p1, p3).unwrap();
+        assert!(!me.exists(p1).unwrap());
+        assert!(me.rename(nonexist, p1).is_err());
+
+        me.unlock(me.lock(p3).unwrap()).unwrap();
+        assert!(me.lock(nonexist).is_ok());
+
+        me.new_logger(p1).unwrap();
+        assert!(me.micros() > 0);
+        me.sleep_for(10);
+    }
 }