Add fs::rmdir() and tempfile/gen_str() tests.

This commit is contained in:
Elly Jones 2011-11-22 17:09:35 -05:00 committed by Brian Anderson
parent d468af59ed
commit 9dd4789d80
7 changed files with 53 additions and 1 deletions

View File

@ -119,7 +119,7 @@ fn file_is_dir(p: path) -> bool {
/*
Function: make_dir
Creates a directory at the specific path.
Creates a directory at the specified path.
*/
fn make_dir(p: path, mode: int) -> bool {
ret mkdir(p, mode);
@ -157,6 +157,26 @@ fn list_dir(p: path) -> [str] {
ret full_paths;
}
/*
Function: remove_dir
Removes a directory at the specified path.
*/
fn remove_dir(p: path) -> bool {
ret rmdir(p);
#[cfg(target_os = "win32")]
fn rmdir(_p: path) -> bool {
ret str::as_buf(_p, {|buf| os::kernel32::RemoveDirectory(buf)});
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
fn rmdir(_p: path) -> bool {
ret str::as_buf(_p, {|buf| os::libc::rmdir(buf) == 0 });
}
}
/*
Function: path_is_absolute

View File

@ -52,6 +52,7 @@ native mod libc {
fn waitpid(pid: pid_t, &status: c_int, options: c_int) -> pid_t;
fn readlink(path: str::sbuf, buf: str::sbuf, bufsize: size_t) -> ssize_t;
fn mkdir(path: str::sbuf, mode: int) -> int;
fn rmdir(path: str::sbuf) -> int;
}
mod libc_constants {

View File

@ -45,6 +45,7 @@ native mod libc {
fn pipe(buf: *mutable int) -> int;
fn waitpid(pid: int, &status: int, options: int) -> int;
fn mkdir(s: str::sbuf, mode: int) -> int;
fn rmdir(s: str::sbuf) -> int;
}
mod libc_constants {

View File

@ -54,6 +54,7 @@ native mod kernel32 {
nSize: DWORD) -> DWORD;
fn CreateDirectory(lpPathName: LPCTSTR,
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) -> bool;
fn RemoveDirectory(lpPathName: LPCTSTR) -> bool;
}
// FIXME turn into constants

View File

@ -3,6 +3,7 @@
// -*- rust -*-
use std;
import std::rand;
import std::str;
#[test]
fn test() {
@ -27,3 +28,13 @@ fn test() {
log r1.next();
log r1.next();
}
#[test]
fn genstr() {
let r: rand::rng = rand::mk_rng();
log r.gen_str(10u);
log r.gen_str(10u);
log r.gen_str(10u);
assert(str::char_len(r.gen_str(10u)) == 10u);
assert(str::char_len(r.gen_str(16u)) == 16u);
}

View File

@ -33,6 +33,7 @@ mod sort;
mod str;
mod sys;
mod task;
mod tempfile;
mod test;
mod tri;
mod treemap;

View File

@ -0,0 +1,17 @@
use std;
import std::fs;
import std::option::some;
import std::str;
import std::tempfile;
#[test]
fn mkdtemp() {
let r = tempfile::mkdtemp("./", "foobar");
alt r {
some(p) {
fs::remove_dir(p);
assert(str::ends_with(p, "foobar"));
}
_ { assert(false); }
}
}