1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

Merge branch 'master' into refactoring_parse_size

This commit is contained in:
Jan Scheer 2021-06-09 13:44:40 +02:00
commit be8650278b
76 changed files with 419 additions and 330 deletions

View file

@ -438,7 +438,7 @@ fn test_domain_socket() {
let child = new_ucmd!().args(&[socket_path]).run_no_wait();
barrier.wait();
let stdout = &child.wait_with_output().unwrap().stdout;
let output = String::from_utf8_lossy(&stdout);
let output = String::from_utf8_lossy(stdout);
assert_eq!("a\tb", output);
thread.join().unwrap();

View file

@ -618,7 +618,7 @@ fn test_cp_deref() {
// Check the content of the destination file that was copied.
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
let path_to_check = path_to_new_symlink.to_str().unwrap();
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
assert_eq!(at.read(path_to_check), "Hello, World!\n");
}
#[test]
fn test_cp_no_deref() {
@ -655,7 +655,7 @@ fn test_cp_no_deref() {
// Check the content of the destination file that was copied.
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
let path_to_check = path_to_new_symlink.to_str().unwrap();
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
assert_eq!(at.read(path_to_check), "Hello, World!\n");
}
#[test]
@ -823,7 +823,7 @@ fn test_cp_deref_folder_to_folder() {
// Check the content of the symlink
let path_to_check = path_to_new_symlink.to_str().unwrap();
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
assert_eq!(at.read(path_to_check), "Hello, World!\n");
}
#[test]
@ -923,7 +923,7 @@ fn test_cp_no_deref_folder_to_folder() {
// Check the content of the symlink
let path_to_check = path_to_new_symlink.to_str().unwrap();
assert_eq!(at.read(&path_to_check), "Hello, World!\n");
assert_eq!(at.read(path_to_check), "Hello, World!\n");
}
#[test]

View file

@ -187,11 +187,10 @@ fn test_change_directory() {
.arg(&temporary_path)
.succeeds()
.stdout_move_str();
assert_eq!(
out.lines()
.any(|line| line.ends_with(temporary_path.file_name().unwrap().to_str().unwrap())),
false
);
assert!(!out
.lines()
.any(|line| line.ends_with(temporary_path.file_name().unwrap().to_str().unwrap())));
}
#[test]

View file

@ -1,41 +1,53 @@
use crate::common::util::*;
#[test]
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn test_groups() {
let result = new_ucmd!().run();
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stdout_str().trim().is_empty() {
// In the CI, some server are failing to return the group.
// As seems to be a configuration issue, ignoring it
return;
if !is_ci() {
new_ucmd!().succeeds().stdout_is(expected_result(&[]));
} else {
// TODO: investigate how this could be tested in CI
// stderr = groups: cannot find name for group ID 116
println!("test skipped:");
}
result.success();
assert!(!result.stdout_str().trim().is_empty());
}
#[test]
fn test_groups_arg() {
// get the username with the "id -un" command
let result = TestScenario::new("id").ucmd_keepenv().arg("-un").run();
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
let s1 = String::from(result.stdout_str().trim());
if is_ci() && s1.parse::<f64>().is_ok() {
// In the CI, some server are failing to return id -un.
// So, if we are getting a uid, just skip this test
// As seems to be a configuration issue, ignoring it
#[cfg(any(target_os = "linux"))]
#[ignore = "fixme: 'groups USERNAME' needs more debugging"]
fn test_groups_username() {
let scene = TestScenario::new(util_name!());
let whoami_result = scene.cmd("whoami").run();
let username = if whoami_result.succeeded() {
whoami_result.stdout_move_str()
} else if is_ci() {
String::from("docker")
} else {
println!("test skipped:");
return;
}
};
println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr_str());
result.success();
assert!(!result.stdout_str().is_empty());
let username = result.stdout_str().trim();
// TODO: stdout should be in the form: "username : group1 group2 group3"
// call groups with the user name to check that we
// are getting something
new_ucmd!().arg(username).succeeds();
assert!(!result.stdout_str().is_empty());
scene
.ucmd()
.arg(&username)
.succeeds()
.stdout_is(expected_result(&[&username]));
}
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn expected_result(args: &[&str]) -> String {
#[cfg(target_os = "linux")]
let util_name = util_name!();
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")
.args(args)
.succeeds()
.stdout_move_str()
}

View file

@ -104,19 +104,23 @@ fn test_id_group() {
}
#[test]
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn test_id_groups() {
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-G").succeeds();
let groups = result.stdout_str().trim().split_whitespace();
for s in groups {
assert!(s.parse::<f64>().is_ok());
}
let result = scene.ucmd().arg("--groups").succeeds();
let groups = result.stdout_str().trim().split_whitespace();
for s in groups {
assert!(s.parse::<f64>().is_ok());
for g_flag in &["-G", "--groups"] {
scene
.ucmd()
.arg(g_flag)
.succeeds()
.stdout_is(expected_result(&[g_flag], false));
for &r_flag in &["-r", "--real"] {
let args = [g_flag, r_flag];
scene
.ucmd()
.args(&args)
.succeeds()
.stdout_is(expected_result(&args, false));
}
}
}
@ -167,3 +171,32 @@ fn test_id_password_style() {
assert!(result.stdout_str().starts_with(&username));
}
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn expected_result(args: &[&str], exp_fail: bool) -> String {
#[cfg(target_os = "linux")]
let util_name = util_name!();
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
let result = if !exp_fail {
TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")
.args(args)
.succeeds()
.stdout_move_str()
} else {
TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")
.args(args)
.fails()
.stderr_move_str()
};
return if cfg!(target_os = "macos") && result.starts_with("gid") {
result[1..].to_string()
} else {
result
};
}

View file

@ -398,7 +398,7 @@ fn test_ls_long_formats() {
.arg("--author")
.arg("test-long-formats")
.succeeds();
assert!(re_three.is_match(&result.stdout_str()));
assert!(re_three.is_match(result.stdout_str()));
#[cfg(unix)]
{
@ -701,20 +701,20 @@ fn test_ls_styles() {
.arg("-l")
.arg("--time-style=full-iso")
.succeeds();
assert!(re_full.is_match(&result.stdout_str()));
assert!(re_full.is_match(result.stdout_str()));
//long-iso
let result = scene
.ucmd()
.arg("-l")
.arg("--time-style=long-iso")
.succeeds();
assert!(re_long.is_match(&result.stdout_str()));
assert!(re_long.is_match(result.stdout_str()));
//iso
let result = scene.ucmd().arg("-l").arg("--time-style=iso").succeeds();
assert!(re_iso.is_match(&result.stdout_str()));
assert!(re_iso.is_match(result.stdout_str()));
//locale
let result = scene.ucmd().arg("-l").arg("--time-style=locale").succeeds();
assert!(re_locale.is_match(&result.stdout_str()));
assert!(re_locale.is_match(result.stdout_str()));
//Overwrite options tests
let result = scene
@ -723,19 +723,19 @@ fn test_ls_styles() {
.arg("--time-style=long-iso")
.arg("--time-style=iso")
.succeeds();
assert!(re_iso.is_match(&result.stdout_str()));
assert!(re_iso.is_match(result.stdout_str()));
let result = scene
.ucmd()
.arg("--time-style=iso")
.arg("--full-time")
.succeeds();
assert!(re_full.is_match(&result.stdout_str()));
assert!(re_full.is_match(result.stdout_str()));
let result = scene
.ucmd()
.arg("--full-time")
.arg("--time-style=iso")
.succeeds();
assert!(re_iso.is_match(&result.stdout_str()));
assert!(re_iso.is_match(result.stdout_str()));
let result = scene
.ucmd()
@ -743,7 +743,7 @@ fn test_ls_styles() {
.arg("--time-style=iso")
.arg("--full-time")
.succeeds();
assert!(re_full.is_match(&result.stdout_str()));
assert!(re_full.is_match(result.stdout_str()));
let result = scene
.ucmd()
@ -751,7 +751,7 @@ fn test_ls_styles() {
.arg("-x")
.arg("-l")
.succeeds();
assert!(re_full.is_match(&result.stdout_str()));
assert!(re_full.is_match(result.stdout_str()));
at.touch("test2");
let result = scene.ucmd().arg("--full-time").arg("-x").succeeds();
@ -1143,7 +1143,7 @@ fn test_ls_indicator_style() {
for opt in options {
scene
.ucmd()
.arg(format!("{}", opt))
.arg(opt.to_string())
.succeeds()
.stdout_contains(&"/");
}

View file

@ -38,7 +38,7 @@ fn test_posix_mode() {
// fail on long path
new_ucmd!()
.args(&["-p", &"dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
.args(&["-p", "dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
.fails()
.no_stdout();
@ -46,7 +46,7 @@ fn test_posix_mode() {
new_ucmd!()
.args(&[
"-p",
&format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
])
.fails()
.no_stdout();
@ -76,7 +76,7 @@ fn test_posix_special() {
// fail on long path
new_ucmd!()
.args(&["-P", &"dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
.args(&["-P", "dir".repeat(libc::PATH_MAX as usize + 1).as_str()])
.fails()
.no_stdout();
@ -84,7 +84,7 @@ fn test_posix_special() {
new_ucmd!()
.args(&[
"-P",
&format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
])
.fails()
.no_stdout();
@ -117,7 +117,7 @@ fn test_posix_all() {
.args(&[
"-p",
"-P",
&"dir".repeat(libc::PATH_MAX as usize + 1).as_str(),
"dir".repeat(libc::PATH_MAX as usize + 1).as_str(),
])
.fails()
.no_stdout();
@ -127,7 +127,7 @@ fn test_posix_all() {
.args(&[
"-p",
"-P",
&format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
format!("dir/{}", "file".repeat(libc::FILENAME_MAX as usize + 1)).as_str(),
])
.fails()
.no_stdout();

View file

@ -102,6 +102,8 @@ fn expected_result(args: &[&str]) -> String {
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
// note: clippy::needless_borrow *false positive*
#[allow(clippy::needless_borrow)]
TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")

View file

@ -313,6 +313,8 @@ fn expected_result(args: &[&str]) -> String {
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
// note: clippy::needless_borrow *false positive*
#[allow(clippy::needless_borrow)]
TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")

View file

@ -13,6 +13,8 @@ fn test_users_check_name() {
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
// note: clippy::needless_borrow *false positive*
#[allow(clippy::needless_borrow)]
let expected = TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")

View file

@ -238,6 +238,8 @@ fn expected_result(args: &[&str]) -> String {
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
// note: clippy::needless_borrow *false positive*
#[allow(clippy::needless_borrow)]
TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")

View file

@ -625,11 +625,20 @@ impl AtPath {
// Source:
// http://stackoverflow.com/questions/31439011/getfinalpathnamebyhandle-without-prepended
let prefix = "\\\\?\\";
// FixME: replace ...
#[allow(clippy::manual_strip)]
if s.starts_with(prefix) {
String::from(&s[prefix.len()..])
} else {
s
}
// ... with ...
// if let Some(stripped) = s.strip_prefix(prefix) {
// String::from(stripped)
// } else {
// s
// }
// ... when using MSRV with stabilized `strip_prefix()`
}
}