mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 19:36:16 +00:00
Merge branch 'main' into test_ls_fix
This commit is contained in:
commit
7ea63d0b59
12 changed files with 297 additions and 75 deletions
|
@ -4,9 +4,8 @@ use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
|
|||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||
use std::sync::Mutex;
|
||||
|
||||
extern crate libc;
|
||||
use uucore::mode::strip_minus_from_mode;
|
||||
extern crate chmod;
|
||||
extern crate libc;
|
||||
use self::libc::umask;
|
||||
|
||||
static TEST_FILE: &str = "file";
|
||||
|
@ -503,35 +502,6 @@ fn test_chmod_symlink_non_existing_file_recursive() {
|
|||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chmod_strip_minus_from_mode() {
|
||||
let tests = vec![
|
||||
// ( before, after )
|
||||
("chmod -v -xw -R FILE", "chmod -v xw -R FILE"),
|
||||
("chmod g=rwx FILE -c", "chmod g=rwx FILE -c"),
|
||||
(
|
||||
"chmod -c -R -w,o+w FILE --preserve-root",
|
||||
"chmod -c -R w,o+w FILE --preserve-root",
|
||||
),
|
||||
("chmod -c -R +w FILE ", "chmod -c -R +w FILE "),
|
||||
("chmod a=r,=xX FILE", "chmod a=r,=xX FILE"),
|
||||
(
|
||||
"chmod -v --reference REF_FILE -R FILE",
|
||||
"chmod -v --reference REF_FILE -R FILE",
|
||||
),
|
||||
("chmod -Rvc -w-x FILE", "chmod -Rvc w-x FILE"),
|
||||
("chmod 755 -v FILE", "chmod 755 -v FILE"),
|
||||
("chmod -v +0004 FILE -R", "chmod -v +0004 FILE -R"),
|
||||
("chmod -v -0007 FILE -R", "chmod -v 0007 FILE -R"),
|
||||
];
|
||||
|
||||
for test in tests {
|
||||
let mut args: Vec<String> = test.0.split(' ').map(|v| v.to_string()).collect();
|
||||
let _mode_had_minus_prefix = strip_minus_from_mode(&mut args);
|
||||
assert_eq!(test.1, args.join(" "));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chmod_keep_setgid() {
|
||||
for (from, arg, to) in [
|
||||
|
@ -671,3 +641,68 @@ fn test_quiet_n_verbose_used_multiple_times() {
|
|||
.arg("file")
|
||||
.succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gnu_invalid_mode() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.touch("file");
|
||||
scene.ucmd().arg("u+gr").arg("file").fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gnu_options() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.touch("file");
|
||||
scene.ucmd().arg("-w").arg("file").succeeds();
|
||||
scene.ucmd().arg("file").arg("-w").succeeds();
|
||||
scene.ucmd().arg("-w").arg("--").arg("file").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gnu_repeating_options() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.touch("file");
|
||||
scene.ucmd().arg("-w").arg("-w").arg("file").succeeds();
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-w")
|
||||
.arg("-w")
|
||||
.arg("-w")
|
||||
.arg("file")
|
||||
.succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gnu_special_filenames() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let perms_before = Permissions::from_mode(0o100640);
|
||||
let perms_after = Permissions::from_mode(0o100440);
|
||||
|
||||
make_file(&at.plus_as_string("--"), perms_before.mode());
|
||||
scene.ucmd().arg("-w").arg("--").arg("--").succeeds();
|
||||
assert_eq!(at.metadata("--").permissions(), perms_after);
|
||||
set_permissions(at.plus("--"), perms_before.clone()).unwrap();
|
||||
scene.ucmd().arg("--").arg("-w").arg("--").succeeds();
|
||||
assert_eq!(at.metadata("--").permissions(), perms_after);
|
||||
at.remove("--");
|
||||
|
||||
make_file(&at.plus_as_string("-w"), perms_before.mode());
|
||||
scene.ucmd().arg("-w").arg("--").arg("-w").succeeds();
|
||||
assert_eq!(at.metadata("-w").permissions(), perms_after);
|
||||
set_permissions(at.plus("-w"), perms_before).unwrap();
|
||||
scene.ucmd().arg("--").arg("-w").arg("-w").succeeds();
|
||||
assert_eq!(at.metadata("-w").permissions(), perms_after);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gnu_special_options() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.touch("file");
|
||||
scene.ucmd().arg("--").arg("--").arg("file").succeeds();
|
||||
scene.ucmd().arg("--").arg("--").fails();
|
||||
}
|
||||
|
|
|
@ -44,16 +44,84 @@ fn test_date_rfc_3339() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601() {
|
||||
fn test_date_rfc_8601_default() {
|
||||
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}\n$").unwrap();
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!().arg(format!("{param}=ns")).succeeds();
|
||||
new_ucmd!().arg(param).succeeds().stdout_matches(&re);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601() {
|
||||
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},\d{9}[+-]\d{2}:\d{2}\n$").unwrap();
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=ns"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601_invalid_arg() {
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!().arg(format!("{param}=@")).fails();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601_second() {
|
||||
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}\n$").unwrap();
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!().arg(format!("{param}=second")).succeeds();
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=second"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=seconds"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601_minute() {
|
||||
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}[+-]\d{2}:\d{2}\n$").unwrap();
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=minute"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=minutes"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601_hour() {
|
||||
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}T\d{2}[+-]\d{2}:\d{2}\n$").unwrap();
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=hour"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=hours"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601_date() {
|
||||
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}\n$").unwrap();
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!()
|
||||
.arg(format!("{param}=date"))
|
||||
.succeeds()
|
||||
.stdout_matches(&re);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ fn test_shred_remove() {
|
|||
assert!(at.file_exists(file_b));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "freebsd"))]
|
||||
#[test]
|
||||
fn test_shred_force() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue