coreutils/test/mkdir.rs

72 lines
1.9 KiB
Rust
Raw Normal View History

2015-01-10 19:31:55 +00:00
#![allow(unstable)]
2015-01-29 07:29:31 +00:00
use std::old_io::process::Command;
use std::old_io::fs::{rmdir, PathExtensions};
use std::borrow::ToOwned;
2014-01-04 04:33:05 +00:00
2014-10-07 04:34:54 +00:00
static EXE: &'static str = "./mkdir";
static TEST_DIR1: &'static str = "mkdir_test1";
static TEST_DIR2: &'static str = "mkdir_test2";
static TEST_DIR3: &'static str = "mkdir_test3";
static TEST_DIR4: &'static str = "mkdir_test4/mkdir_test4_1";
static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1";
2014-01-04 04:33:05 +00:00
2014-01-05 22:03:13 +00:00
fn cleanup(dir: &'static str) {
let d = dir.to_owned();
let p = Path::new(d.to_owned());
2014-01-05 22:03:13 +00:00
if p.exists() {
rmdir(&p).unwrap();
2014-01-04 04:33:05 +00:00
}
}
2014-01-05 22:03:13 +00:00
#[test]
2014-01-04 04:33:05 +00:00
fn test_mkdir_mkdir() {
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR1);
let prog = Command::new(EXE).arg(TEST_DIR1).status();
2014-01-04 04:33:05 +00:00
let exit_success = prog.unwrap().success();
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR1);
2014-01-04 04:33:05 +00:00
assert_eq!(exit_success, true);
}
2014-01-05 22:03:13 +00:00
#[test]
2014-01-04 04:33:05 +00:00
fn test_mkdir_dup_dir() {
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR2);
let prog = Command::new(EXE).arg(TEST_DIR2).status();
2014-01-04 04:33:05 +00:00
let exit_success = prog.unwrap().success();
if !exit_success {
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR2);
2014-10-30 09:06:47 +00:00
panic!();
2014-01-04 04:33:05 +00:00
}
2014-10-07 04:34:54 +00:00
let prog2 = Command::new(EXE).arg(TEST_DIR2).status();
2014-01-04 04:33:05 +00:00
let exit_success2 = prog2.unwrap().success();
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR2);
2014-01-04 04:33:05 +00:00
assert_eq!(exit_success2, false);
}
2014-01-05 22:03:13 +00:00
#[test]
2014-01-04 04:33:05 +00:00
fn test_mkdir_mode() {
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR3);
let prog = Command::new(EXE).arg("-m").arg("755").arg(TEST_DIR3).status();
2014-01-04 04:33:05 +00:00
let exit_success = prog.unwrap().success();
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR3);
2014-01-04 04:33:05 +00:00
assert_eq!(exit_success, true);
}
2014-01-05 22:03:13 +00:00
#[test]
2014-01-04 04:33:05 +00:00
fn test_mkdir_parent() {
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR4);
let prog = Command::new(EXE).arg("-p").arg(TEST_DIR4).status();
2014-01-04 04:33:05 +00:00
let exit_success = prog.unwrap().success();
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR4);
2014-01-04 04:33:05 +00:00
assert_eq!(exit_success, true);
}
2014-01-05 22:03:13 +00:00
#[test]
2014-01-04 04:33:05 +00:00
fn test_mkdir_no_parent() {
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR5);
let prog = Command::new(EXE).arg(TEST_DIR5).status();
2014-01-04 04:33:05 +00:00
let exit_success = prog.unwrap().success();
2014-10-07 04:34:54 +00:00
cleanup(TEST_DIR5);
2014-01-04 04:33:05 +00:00
assert_eq!(exit_success, false);
2014-01-03 23:32:39 +00:00
}