about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2013-05-22 18:57:24 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2013-05-25 20:47:44 -0700
commita243ea39c3c155ada813c129081772ede8bce3e4 (patch)
treebf131318c46711e6e779445bc518f5ec65760d10 /src/libstd
parent196851c4c92cf850d28bed749ab8c3034c04b9e3 (diff)
downloadrust-a243ea39c3c155ada813c129081772ede8bce3e4.tar.gz
rust-a243ea39c3c155ada813c129081772ede8bce3e4.zip
testsuite: Add a test for listing the root directory...
...and don't treat Path("/") like Path("").
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/os.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index e612c8cfeff..44acdd4d617 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -675,7 +675,7 @@ pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
 /// Lists the contents of a directory
 #[allow(non_implicitly_copyable_typarams)]
 pub fn list_dir(p: &Path) -> ~[~str] {
-    if p.components.is_empty() {
+    if p.components.is_empty() && !p.is_absolute() {
         // Not sure what the right behavior is here, but this
         // prevents a bounds check failure later
         return ~[];
@@ -1608,6 +1608,20 @@ mod tests {
     }
 
     #[test]
+    #[cfg(not(windows))]
+    fn list_dir_root() {
+        let dirs = os::list_dir(&Path("/"));
+        assert!(dirs.len() > 1);
+    }
+    #[test]
+    #[cfg(windows)]
+    fn list_dir_root() {
+        let dirs = os::list_dir(&Path("C:\\"));
+        assert!(dirs.len() > 1);
+    }
+
+
+    #[test]
     fn path_is_dir() {
         assert!((os::path_is_dir(&Path("."))));
         assert!((!os::path_is_dir(&Path("test/stdtest/fs.rs"))));