mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
move parent opt check, update tests
This commit is contained in:
parent
233c49292d
commit
3a63b50956
3 changed files with 41 additions and 41 deletions
2
Makefile
2
Makefile
|
@ -54,7 +54,7 @@ test_$(1): tmp/$(1)_test build build/$(1)
|
||||||
$(call command,tmp/$(1)_test)
|
$(call command,tmp/$(1)_test)
|
||||||
|
|
||||||
tmp/$(1)_test: $(1)/test.rs
|
tmp/$(1)_test: $(1)/test.rs
|
||||||
$(call command,$(RUSTC) $(RUSTCFLAGS) -o tmp/$(1)_test $(1)/test.rs)
|
$(call command,$(RUSTC) $(RUSTCFLAGS) --test -o tmp/$(1)_test $(1)/test.rs)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Main rules
|
# Main rules
|
||||||
|
|
|
@ -98,13 +98,16 @@ fn print_help(opts: &[groups::OptGroup]) {
|
||||||
*/
|
*/
|
||||||
fn exec(dirs: ~[~str], mk_parents: bool, mode: u32, verbose: bool) {
|
fn exec(dirs: ~[~str], mk_parents: bool, mode: u32, verbose: bool) {
|
||||||
let mut parent_dirs: ~[~str] = ~[];
|
let mut parent_dirs: ~[~str] = ~[];
|
||||||
|
if mk_parents {
|
||||||
for dir in dirs.iter() {
|
for dir in dirs.iter() {
|
||||||
let path = Path::new((*dir).clone());
|
let path = Path::new((*dir).clone());
|
||||||
// Build list of parent dirs which need to be created
|
// Build list of parent dirs which need to be created
|
||||||
if mk_parents {
|
let parent = path.dirname_str();
|
||||||
match path.dirname_str() {
|
match parent {
|
||||||
Some(p) => if p != "." {
|
Some(p) => {
|
||||||
|
if !Path::new(p).exists() {
|
||||||
parent_dirs.push(p.into_owned())
|
parent_dirs.push(p.into_owned())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,69 +3,66 @@ use std::io::fs::rmdir;
|
||||||
|
|
||||||
static exe: &'static str = "build/mkdir";
|
static exe: &'static str = "build/mkdir";
|
||||||
static test_dir1: &'static str = "mkdir_test1";
|
static test_dir1: &'static str = "mkdir_test1";
|
||||||
static test_dir2: &'static str = "mkdir_test1/mkdir_test2";
|
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 main() {
|
fn cleanup(dir: &'static str) {
|
||||||
test_mkdir_mkdir();
|
let d = dir.into_owned();
|
||||||
test_mkdir_dup_dir();
|
|
||||||
test_mkdir_mode();
|
|
||||||
test_mkdir_parent();
|
|
||||||
test_mkdir_no_parent();
|
|
||||||
println("mkdir tests completed successfully!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cleanup() {
|
|
||||||
let dirs = [test_dir2, test_dir1];
|
|
||||||
for d in dirs.iter() {
|
|
||||||
let p = Path::new(d.into_owned());
|
let p = Path::new(d.into_owned());
|
||||||
if p.exists() {
|
if p.exists() {
|
||||||
rmdir(&p);
|
rmdir(&p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn test_mkdir_mkdir() {
|
fn test_mkdir_mkdir() {
|
||||||
cleanup();
|
cleanup(test_dir1);
|
||||||
let prog = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
|
let prog = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
|
||||||
let exit_success = prog.unwrap().success();
|
let exit_success = prog.unwrap().success();
|
||||||
cleanup();
|
cleanup(test_dir1);
|
||||||
assert_eq!(exit_success, true);
|
assert_eq!(exit_success, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn test_mkdir_dup_dir() {
|
fn test_mkdir_dup_dir() {
|
||||||
cleanup();
|
cleanup(test_dir2);
|
||||||
let prog = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
|
let prog = run::process_status(exe.into_owned(), [test_dir2.into_owned()]);
|
||||||
let exit_success = prog.unwrap().success();
|
let exit_success = prog.unwrap().success();
|
||||||
if !exit_success {
|
if !exit_success {
|
||||||
cleanup();
|
cleanup(test_dir2);
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
let prog2 = run::process_status(exe.into_owned(), [test_dir1.into_owned()]);
|
let prog2 = run::process_status(exe.into_owned(), [test_dir2.into_owned()]);
|
||||||
let exit_success2 = prog2.unwrap().success();
|
let exit_success2 = prog2.unwrap().success();
|
||||||
cleanup();
|
cleanup(test_dir2);
|
||||||
assert_eq!(exit_success2, false);
|
assert_eq!(exit_success2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn test_mkdir_mode() {
|
fn test_mkdir_mode() {
|
||||||
cleanup();
|
cleanup(test_dir3);
|
||||||
let prog = run::process_status(exe.into_owned(), [~"-m", ~"755", test_dir1.into_owned()]);
|
let prog = run::process_status(exe.into_owned(), [~"-m", ~"755", test_dir3.into_owned()]);
|
||||||
let exit_success = prog.unwrap().success();
|
let exit_success = prog.unwrap().success();
|
||||||
cleanup();
|
cleanup(test_dir3);
|
||||||
assert_eq!(exit_success, true);
|
assert_eq!(exit_success, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn test_mkdir_parent() {
|
fn test_mkdir_parent() {
|
||||||
cleanup();
|
cleanup(test_dir4);
|
||||||
let prog = run::process_status(exe.into_owned(), [~"-p", test_dir2.into_owned()]);
|
let prog = run::process_status(exe.into_owned(), [~"-p", test_dir4.into_owned()]);
|
||||||
let exit_success = prog.unwrap().success();
|
let exit_success = prog.unwrap().success();
|
||||||
cleanup();
|
cleanup(test_dir4);
|
||||||
assert_eq!(exit_success, true);
|
assert_eq!(exit_success, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn test_mkdir_no_parent() {
|
fn test_mkdir_no_parent() {
|
||||||
cleanup();
|
cleanup(test_dir5);
|
||||||
let prog = run::process_status(exe.into_owned(), [test_dir2.into_owned()]);
|
let prog = run::process_status(exe.into_owned(), [test_dir5.into_owned()]);
|
||||||
let exit_success = prog.unwrap().success();
|
let exit_success = prog.unwrap().success();
|
||||||
cleanup();
|
cleanup(test_dir5);
|
||||||
assert_eq!(exit_success, false);
|
assert_eq!(exit_success, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue