1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests/chmod: refactor tests to only create reference file once

This commit is contained in:
Luca Ottaviano 2016-03-11 19:35:03 +01:00
parent 9e5a2400be
commit 9005ae7dbf

View file

@ -24,18 +24,14 @@ fn mkfile(file: &str, mode: mode_t) {
std::fs::set_permissions(file, perms).unwrap(); std::fs::set_permissions(file, perms).unwrap();
} }
fn run_tests(tests: Vec<TestCase>) { fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
for test in tests {
let (at, mut ucmd) = testing(UTIL_NAME);
mkfile(&at.plus_as_string(TEST_FILE), test.before); mkfile(&at.plus_as_string(TEST_FILE), test.before);
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
let perms = at.metadata(TEST_FILE).permissions().mode(); let perms = at.metadata(TEST_FILE).permissions().mode();
if perms != test.before{ if perms != test.before{
panic!(format!("{}: expected: {:o} got: {:o}", "setting permissions failed", test.after, perms)); panic!(format!("{}: expected: {:o} got: {:o}", "setting permissions failed", test.after, perms));
} }
for arg in test.args { for arg in &test.args {
ucmd.arg(arg); ucmd.arg(arg);
} }
let r = ucmd.run(); let r = ucmd.run();
@ -49,6 +45,12 @@ fn run_tests(tests: Vec<TestCase>) {
panic!(format!("{:?}: expected: {:o} got: {:o}", ucmd.raw, test.after, perms)); panic!(format!("{:?}: expected: {:o} got: {:o}", ucmd.raw, test.after, perms));
} }
} }
fn run_tests(tests: Vec<TestCase>) {
for test in tests {
let (at, ucmd) = testing(UTIL_NAME);
run_single_test(&test, at, ucmd);
}
} }
#[test] #[test]
@ -96,5 +98,7 @@ fn test_chmod_reference_file() {
let tests = vec!{ let tests = vec!{
TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247}, TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247},
}; };
run_tests(tests); let (at, ucmd) = testing(UTIL_NAME);
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
run_single_test(&tests[0], at, ucmd);
} }