mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-16 10:11:01 +00:00
commit
f0e5c19ed4
2 changed files with 80 additions and 90 deletions
|
|
@ -1,29 +1,34 @@
|
|||
#![allow(unstable)]
|
||||
#![feature(path_ext)]
|
||||
|
||||
use std::old_io::process::Command;
|
||||
use std::old_io::fs::{rmdir, PathExtensions};
|
||||
use std::borrow::ToOwned;
|
||||
use std::fs::{remove_dir, PathExt};
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
static EXE: &'static str = "./mkdir";
|
||||
static PROGNAME: &'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";
|
||||
|
||||
fn run(args: &[&'static str]) -> Output {
|
||||
Command::new(PROGNAME)
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap_or_else(|e| panic!("{}", e))
|
||||
}
|
||||
|
||||
fn cleanup(dir: &'static str) {
|
||||
let d = dir.to_owned();
|
||||
let p = Path::new(d.to_owned());
|
||||
let p = Path::new(dir);
|
||||
if p.exists() {
|
||||
rmdir(&p).unwrap();
|
||||
remove_dir(&p).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_mkdir() {
|
||||
cleanup(TEST_DIR1);
|
||||
let prog = Command::new(EXE).arg(TEST_DIR1).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
let exit_success = run(&[TEST_DIR1]).status.success();
|
||||
cleanup(TEST_DIR1);
|
||||
assert_eq!(exit_success, true);
|
||||
}
|
||||
|
|
@ -31,14 +36,12 @@ fn test_mkdir_mkdir() {
|
|||
#[test]
|
||||
fn test_mkdir_dup_dir() {
|
||||
cleanup(TEST_DIR2);
|
||||
let prog = Command::new(EXE).arg(TEST_DIR2).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
let exit_success = run(&[TEST_DIR2]).status.success();
|
||||
if !exit_success {
|
||||
cleanup(TEST_DIR2);
|
||||
panic!();
|
||||
}
|
||||
let prog2 = Command::new(EXE).arg(TEST_DIR2).status();
|
||||
let exit_success2 = prog2.unwrap().success();
|
||||
let exit_success2 = run(&[TEST_DIR2]).status.success();
|
||||
cleanup(TEST_DIR2);
|
||||
assert_eq!(exit_success2, false);
|
||||
}
|
||||
|
|
@ -46,8 +49,7 @@ fn test_mkdir_dup_dir() {
|
|||
#[test]
|
||||
fn test_mkdir_mode() {
|
||||
cleanup(TEST_DIR3);
|
||||
let prog = Command::new(EXE).arg("-m").arg("755").arg(TEST_DIR3).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
let exit_success = run(&["-m", "755", TEST_DIR3]).status.success();
|
||||
cleanup(TEST_DIR3);
|
||||
assert_eq!(exit_success, true);
|
||||
}
|
||||
|
|
@ -55,8 +57,7 @@ fn test_mkdir_mode() {
|
|||
#[test]
|
||||
fn test_mkdir_parent() {
|
||||
cleanup(TEST_DIR4);
|
||||
let prog = Command::new(EXE).arg("-p").arg(TEST_DIR4).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
let exit_success = run(&["-p", TEST_DIR4]).status.success();
|
||||
cleanup(TEST_DIR4);
|
||||
assert_eq!(exit_success, true);
|
||||
}
|
||||
|
|
@ -64,8 +65,7 @@ fn test_mkdir_parent() {
|
|||
#[test]
|
||||
fn test_mkdir_no_parent() {
|
||||
cleanup(TEST_DIR5);
|
||||
let prog = Command::new(EXE).arg(TEST_DIR5).status();
|
||||
let exit_success = prog.unwrap().success();
|
||||
let exit_success = run(&[TEST_DIR5]).status.success();
|
||||
cleanup(TEST_DIR5);
|
||||
assert_eq!(exit_success, false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue