mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
commit
f47fafb28d
4 changed files with 56 additions and 25 deletions
|
@ -24,18 +24,14 @@ fn mkfile(file: &str, mode: mode_t) {
|
|||
std::fs::set_permissions(file, perms).unwrap();
|
||||
}
|
||||
|
||||
fn run_tests(tests: Vec<TestCase>) {
|
||||
for test in tests {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
|
||||
fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
|
||||
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();
|
||||
if perms != test.before{
|
||||
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);
|
||||
}
|
||||
let r = ucmd.run();
|
||||
|
@ -48,6 +44,12 @@ fn run_tests(tests: Vec<TestCase>) {
|
|||
if perms != test.after {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,10 +59,9 @@ fn test_chmod_octal() {
|
|||
TestCase{args: vec!{"0700", TEST_FILE}, before: 0o000, after: 0o700},
|
||||
TestCase{args: vec!{"0070", TEST_FILE}, before: 0o000, after: 0o070},
|
||||
TestCase{args: vec!{"0007", TEST_FILE}, before: 0o000, after: 0o007},
|
||||
// Known failues: #788
|
||||
// TestCase{args: vec!{"-0700", TEST_FILE}, before: 0o700, after: 0o000},
|
||||
// TestCase{args: vec!{"-0070", TEST_FILE}, before: 0o060, after: 0o000},
|
||||
// TestCase{args: vec!{"-0007", TEST_FILE}, before: 0o001, after: 0o000},
|
||||
TestCase{args: vec!{"-0700", TEST_FILE}, before: 0o700, after: 0o000},
|
||||
TestCase{args: vec!{"-0070", TEST_FILE}, before: 0o060, after: 0o000},
|
||||
TestCase{args: vec!{"-0007", TEST_FILE}, before: 0o001, after: 0o000},
|
||||
TestCase{args: vec!{"+0100", TEST_FILE}, before: 0o600, after: 0o700},
|
||||
TestCase{args: vec!{"+0020", TEST_FILE}, before: 0o050, after: 0o070},
|
||||
TestCase{args: vec!{"+0004", TEST_FILE}, before: 0o003, after: 0o007},
|
||||
|
@ -75,6 +76,9 @@ fn test_chmod_ugoa() {
|
|||
TestCase{args: vec!{"g=rwx", TEST_FILE}, before: 0o000, after: 0o070},
|
||||
TestCase{args: vec!{"o=rwx", TEST_FILE}, before: 0o000, after: 0o007},
|
||||
TestCase{args: vec!{"a=rwx", TEST_FILE}, before: 0o000, after: 0o777},
|
||||
TestCase{args: vec!{"-r", TEST_FILE}, before: 0o777, after: 0o333},
|
||||
TestCase{args: vec!{"-w", TEST_FILE}, before: 0o777, after: 0o555},
|
||||
TestCase{args: vec!{"-x", TEST_FILE}, before: 0o777, after: 0o666},
|
||||
};
|
||||
run_tests(tests);
|
||||
}
|
||||
|
@ -92,9 +96,20 @@ fn test_chmod_ugo_copy() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_chmod_reference_file() {
|
||||
fn test_chmod_many_options() {
|
||||
let tests = vec!{
|
||||
TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247},
|
||||
TestCase{args: vec!{"-r,a+w", TEST_FILE}, before: 0o444, after: 0o222},
|
||||
};
|
||||
run_tests(tests);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chmod_reference_file() {
|
||||
let tests = vec!{
|
||||
TestCase{args: vec!{"--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247},
|
||||
TestCase{args: vec!{"a-w", "--reference", REFERENCE_FILE, TEST_FILE}, before: 0o070, after: 0o247},
|
||||
};
|
||||
let (at, ucmd) = testing(UTIL_NAME);
|
||||
mkfile(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
|
||||
run_single_test(&tests[0], at, ucmd);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue