Add fs::rmdir() and tempfile/gen_str() tests.
This commit is contained in:
parent
d468af59ed
commit
9dd4789d80
@ -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
|
||||
|
||||
|
@ -52,6 +52,7 @@
|
||||
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 {
|
||||
|
@ -45,6 +45,7 @@
|
||||
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 {
|
||||
|
@ -54,6 +54,7 @@ fn GetModuleFileNameA(hModule: HMODULE,
|
||||
nSize: DWORD) -> DWORD;
|
||||
fn CreateDirectory(lpPathName: LPCTSTR,
|
||||
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) -> bool;
|
||||
fn RemoveDirectory(lpPathName: LPCTSTR) -> bool;
|
||||
}
|
||||
|
||||
// FIXME turn into constants
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ mod sort;
|
||||
mod str;
|
||||
mod sys;
|
||||
mod task;
|
||||
mod tempfile;
|
||||
mod test;
|
||||
mod tri;
|
||||
mod treemap;
|
||||
|
17
src/test/stdtest/tempfile.rs
Normal file
17
src/test/stdtest/tempfile.rs
Normal 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); }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user