提交 510d0f22 编写于 作者: B bors

auto merge of #6687 : catamorphism/rust/list_dir_empty, r=catamorphism

r? @brson (Yes, this did happen in real life...)
......@@ -675,6 +675,11 @@ 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() && !p.is_absolute() {
// Not sure what the right behavior is here, but this
// prevents a bounds check failure later
return ~[];
}
unsafe {
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
......@@ -1596,6 +1601,26 @@ fn list_dir() {
}
}
#[test]
fn list_dir_empty_path() {
let dirs = os::list_dir(&Path(""));
assert!(dirs.is_empty());
}
#[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("."))));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册