Add fs::rmdir() and tempfile/gen_str() tests.
This commit is contained in:
committed by
Brian Anderson
parent
d468af59ed
commit
9dd4789d80
@@ -119,7 +119,7 @@ fn file_is_dir(p: path) -> bool {
|
|||||||
/*
|
/*
|
||||||
Function: make_dir
|
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 {
|
fn make_dir(p: path, mode: int) -> bool {
|
||||||
ret mkdir(p, mode);
|
ret mkdir(p, mode);
|
||||||
@@ -157,6 +157,26 @@ fn list_dir(p: path) -> [str] {
|
|||||||
ret full_paths;
|
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
|
Function: path_is_absolute
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ native mod libc {
|
|||||||
fn waitpid(pid: pid_t, &status: c_int, options: c_int) -> pid_t;
|
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 readlink(path: str::sbuf, buf: str::sbuf, bufsize: size_t) -> ssize_t;
|
||||||
fn mkdir(path: str::sbuf, mode: int) -> int;
|
fn mkdir(path: str::sbuf, mode: int) -> int;
|
||||||
|
fn rmdir(path: str::sbuf) -> int;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod libc_constants {
|
mod libc_constants {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ native mod libc {
|
|||||||
fn pipe(buf: *mutable int) -> int;
|
fn pipe(buf: *mutable int) -> int;
|
||||||
fn waitpid(pid: int, &status: int, options: int) -> int;
|
fn waitpid(pid: int, &status: int, options: int) -> int;
|
||||||
fn mkdir(s: str::sbuf, mode: int) -> int;
|
fn mkdir(s: str::sbuf, mode: int) -> int;
|
||||||
|
fn rmdir(s: str::sbuf) -> int;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod libc_constants {
|
mod libc_constants {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ native mod kernel32 {
|
|||||||
nSize: DWORD) -> DWORD;
|
nSize: DWORD) -> DWORD;
|
||||||
fn CreateDirectory(lpPathName: LPCTSTR,
|
fn CreateDirectory(lpPathName: LPCTSTR,
|
||||||
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) -> bool;
|
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) -> bool;
|
||||||
|
fn RemoveDirectory(lpPathName: LPCTSTR) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME turn into constants
|
// FIXME turn into constants
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// -*- rust -*-
|
// -*- rust -*-
|
||||||
use std;
|
use std;
|
||||||
import std::rand;
|
import std::rand;
|
||||||
|
import std::str;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test() {
|
fn test() {
|
||||||
@@ -27,3 +28,13 @@ fn test() {
|
|||||||
log r1.next();
|
log r1.next();
|
||||||
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 str;
|
||||||
mod sys;
|
mod sys;
|
||||||
mod task;
|
mod task;
|
||||||
|
mod tempfile;
|
||||||
mod test;
|
mod test;
|
||||||
mod tri;
|
mod tri;
|
||||||
mod treemap;
|
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); }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user