about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2013-04-28 21:25:35 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2013-04-28 21:25:35 -0700
commitd045ce7b87af0fb0730ccf5291c11d28a5382254 (patch)
treed5c52898568d931a99fff0f37a131da317490738 /src/libstd
parent379dce11a958149915d1188741e03acefe1e1bd5 (diff)
downloadrust-d045ce7b87af0fb0730ccf5291c11d28a5382254.tar.gz
rust-d045ce7b87af0fb0730ccf5291c11d28a5382254.zip
core: Use a better termination condition in os::mkdir_recursive
Instead of checking whether the parent is "." or "/", check the
number of components.

Also, more tests.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/tempfile.rs65
1 files changed, 59 insertions, 6 deletions
diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs
index 846a9aec153..eec91b68454 100644
--- a/src/libstd/tempfile.rs
+++ b/src/libstd/tempfile.rs
@@ -23,9 +23,62 @@ pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
     None
 }
 
-#[test]
-fn test_mkdtemp() {
-    let p = mkdtemp(&Path("."), "foobar").unwrap();
-    os::remove_dir(&p);
-    assert!(str::ends_with(p.to_str(), "foobar"));
-}
+#[cfg(test)]
+mod tests {
+    use tempfile::mkdtemp;
+    use tempfile;
+
+    #[test]
+    fn test_mkdtemp() {
+        let p = mkdtemp(&Path("."), "foobar").unwrap();
+        os::remove_dir(&p);
+        assert!(str::ends_with(p.to_str(), "foobar"));
+    }
+
+    // Ideally these would be in core::os but then core would need
+    // to depend on std
+    #[test]
+    fn recursive_mkdir_rel() {
+        use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
+        use core::os;
+
+        let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel");
+        os::change_dir(&root);
+        let path = Path("frob");
+        assert!(os::mkdir_recursive(&path,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+        assert!(os::path_is_dir(&path));
+        assert!(os::mkdir_recursive(&path,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+        assert!(os::path_is_dir(&path));
+    }
+
+    #[test]
+    fn recursive_mkdir_dot() {
+        use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
+        use core::os;
+
+        let dot = Path(".");
+        assert!(os::mkdir_recursive(&dot,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+        let dotdot = Path("..");
+        assert!(os::mkdir_recursive(&dotdot,  (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+    }
+
+    #[test]
+    fn recursive_mkdir_rel_2() {
+        use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
+        use core::os;
+
+        let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel_2");
+        os::change_dir(&root);
+        let path = Path("./frob/baz");
+        debug!("...Making: %s in cwd %s", path.to_str(), os::getcwd().to_str());
+        assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+        assert!(os::path_is_dir(&path));
+        assert!(os::path_is_dir(&path.pop()));
+        let path2 = Path("quux/blat");
+        debug!("Making: %s in cwd %s", path2.to_str(), os::getcwd().to_str());
+        assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
+        assert!(os::path_is_dir(&path2));
+        assert!(os::path_is_dir(&path2.pop()));
+    }
+
+}
\ No newline at end of file