coreutils/src/mkdir/test.rs

69 lines
1.8 KiB
Rust
Raw Normal View History

use std::io::process::Command;
2014-01-04 04:33:05 +00:00
use std::io::fs::rmdir;
static exe: &'static str = "build/mkdir";
2014-01-05 22:27:35 +00:00
static test_dir1: &'static str = "tmp/mkdir_test1";
static test_dir2: &'static str = "tmp/mkdir_test2";
static test_dir3: &'static str = "tmp/mkdir_test3";
static test_dir4: &'static str = "tmp/mkdir_test4/mkdir_test4_1";
static test_dir5: &'static str = "tmp/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-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +00:00
cleanup(test_dir2);
2014-01-04 04:33:05 +00:00
fail!();
}
let prog2 = Command::new(exe).arg(test_dir2).status();
2014-01-04 04:33:05 +00:00
let exit_success2 = prog2.unwrap().success();
2014-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +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-01-05 22:03:13 +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
}