coreutils/test/mkdir.rs

69 lines
1.8 KiB
Rust
Raw Normal View History

use std::io::process::Command;
2014-09-17 01:50:38 +00:00
use std::io::fs::{rmdir, PathExtensions};
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) {
2014-06-01 00:41:32 +00:00
let d = dir.into_string();
let p = Path::new(d.into_string());
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-01-04 04:33:05 +00:00
fail!();
}
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
}