1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 19:36:16 +00:00

Merge branch 'main' into cp-force-dangling-symlink

This commit is contained in:
Sylvestre Ledru 2022-10-28 21:24:42 +02:00 committed by GitHub
commit b3af47a390
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 293 additions and 125 deletions

View file

@ -423,6 +423,38 @@ fn test_chown_only_user_id() {
.stderr_contains("failed to change");
}
#[test]
fn test_chown_fail_id() {
// test chown 1111. file.txt
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let result = scene.cmd_keepenv("id").arg("-u").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let user_id = String::from(result.stdout_str().trim());
assert!(!user_id.is_empty());
let file1 = "test_chown_file1";
at.touch(file1);
scene
.ucmd()
.arg(format!("{}:", user_id))
.arg(file1)
.fails()
.stderr_contains("invalid spec");
scene
.ucmd()
.arg(format!("{}.", user_id))
.arg(file1)
.fails()
.stderr_contains("invalid spec");
}
/// Test for setting the owner to a user ID for a user that does not exist.
///
/// For example:
@ -708,7 +740,7 @@ fn test_chown_file_notexisting() {
.fails();
// TODO: uncomment once "failed to change ownership of '{}' to {}" added to stdout
// result.stderr_contains(&"retained as");
// result.stderr_contains("retained as");
// TODO: uncomment once message changed from "cannot dereference" to "cannot access"
// result.stderr_contains(&"cannot access 'not_existing': No such file or directory");
// result.stderr_contains("cannot access 'not_existing': No such file or directory");
}

View file

@ -215,6 +215,18 @@ fn test_cp_target_directory_is_file() {
.stderr_contains(format!("'{}' is not a directory", TEST_HOW_ARE_YOU_SOURCE));
}
#[test]
fn test_cp_arg_update_interactive() {
new_ucmd!()
.arg(TEST_HELLO_WORLD_SOURCE)
.arg(TEST_HOW_ARE_YOU_SOURCE)
.arg("-i")
.arg("--update")
.succeeds()
.no_stdout()
.no_stderr();
}
#[test]
fn test_cp_arg_interactive() {
let (at, mut ucmd) = at_and_ucmd!();

View file

@ -1863,7 +1863,7 @@ fn test_ls_recursive() {
#[cfg(not(windows))]
result.stdout_contains("a/b:\nb");
#[cfg(windows)]
result.stdout_contains(&"a\\b:\nb");
result.stdout_contains("a\\b:\nb");
}
#[test]
@ -2093,13 +2093,13 @@ fn test_ls_indicator_style() {
.ucmd()
.arg(format!("--indicator-style={}", opt))
.succeeds()
.stdout_contains(&"/");
.stdout_contains("/");
}
// Same test as above, but with the alternate flags.
let options = vec!["--classify", "--file-type", "-p"];
for opt in options {
scene.ucmd().arg(opt).succeeds().stdout_contains(&"/");
scene.ucmd().arg(opt).succeeds().stdout_contains("/");
}
// Classify and File-Type all contain indicators for pipes and links.
@ -2110,7 +2110,7 @@ fn test_ls_indicator_style() {
.ucmd()
.arg(format!("--indicator-style={}", opt))
.succeeds()
.stdout_contains(&"@");
.stdout_contains("@");
}
}
@ -3195,7 +3195,7 @@ fn test_ls_context_format() {
] {
let format = format!("--format={}", word);
ts.ucmd()
.args(&[&"-Z", &format.as_str(), &"/"])
.args(&["-Z", format.as_str(), "/"])
.succeeds()
.stdout_only(
unwrap_or_return!(expected_result(&ts, &["-Z", format.as_str(), "/"])).stdout_str(),

View file

@ -184,6 +184,25 @@ fn test_mv_interactive() {
assert!(at.file_exists(file_b));
}
#[test]
fn test_mv_arg_update_interactive() {
let (at, mut ucmd) = at_and_ucmd!();
let file_a = "test_mv_replace_file_a";
let file_b = "test_mv_replace_file_b";
at.touch(file_a);
at.touch(file_b);
ucmd.arg(file_a)
.arg(file_b)
.arg("-i")
.arg("--update")
.succeeds()
.no_stdout()
.no_stderr();
}
#[test]
fn test_mv_no_clobber() {
let (at, mut ucmd) = at_and_ucmd!();

View file

@ -184,6 +184,11 @@ fn test_negative() {
.stdout_is("-1.0Ki\n-1.2Mi\n-103Mi\n");
}
#[test]
fn test_negative_zero() {
new_ucmd!().pipe_in("-0\n-0.0").run().stdout_is("0\n0.0\n");
}
#[test]
fn test_no_op() {
new_ucmd!()
@ -525,7 +530,7 @@ fn test_round() {
new_ucmd!()
.args(&[
"--to=si",
&format!("--round={}", method),
&format!("--round={method}"),
"--",
"9001",
"-9001",
@ -537,6 +542,32 @@ fn test_round() {
}
}
#[test]
fn test_round_with_to_unit() {
for (method, exp) in [
("from-zero", ["6", "-6", "5.9", "-5.9", "5.86", "-5.86"]),
("towards-zero", ["5", "-5", "5.8", "-5.8", "5.85", "-5.85"]),
("up", ["6", "-5", "5.9", "-5.8", "5.86", "-5.85"]),
("down", ["5", "-6", "5.8", "-5.9", "5.85", "-5.86"]),
("nearest", ["6", "-6", "5.9", "-5.9", "5.86", "-5.86"]),
] {
new_ucmd!()
.args(&[
"--to-unit=1024",
&format!("--round={method}"),
"--",
"6000",
"-6000",
"6000.0",
"-6000.0",
"6000.00",
"-6000.00",
])
.succeeds()
.stdout_only(exp.join("\n") + "\n");
}
}
#[test]
fn test_suffix_is_added_if_not_supplied() {
new_ucmd!()

View file

@ -90,6 +90,35 @@ fn test_symlinked_default() {
env.ucmd.succeeds().stdout_is(env.subdir + "\n");
}
#[test]
fn test_symlinked_default_posix() {
let mut env = symlinked_env();
env.ucmd
.env("POSIXLY_CORRECT", "1")
.succeeds()
.stdout_is(env.symdir.clone() + "\n");
}
#[test]
fn test_symlinked_default_posix_l() {
let mut env = symlinked_env();
env.ucmd
.env("POSIXLY_CORRECT", "1")
.arg("-L")
.succeeds()
.stdout_is(env.symdir + "\n");
}
#[test]
fn test_symlinked_default_posix_p() {
let mut env = symlinked_env();
env.ucmd
.env("POSIXLY_CORRECT", "1")
.arg("-P")
.succeeds()
.stdout_is(env.symdir + "\n");
}
#[cfg(not(windows))]
pub mod untrustworthy_pwd_var {
use std::path::Path;

View file

@ -58,11 +58,11 @@ impl Distribution<u8> for AlphanumericNewline {
/// use rand::distributions::Alphanumeric;
///
/// // generates a 100 byte string with characters from AlphanumericNewline
/// let random_string = RandomString::generate(&AlphanumericNewline, 100);
/// let random_string = RandomString::generate(AlphanumericNewline, 100);
/// assert_eq!(100, random_string.len());
///
/// // generates a 100 byte string with 10 newline characters not ending with a newline
/// let string = RandomString::generate_with_delimiter(&Alphanumeric, b'\n', 10, false, 100);
/// let string = RandomString::generate_with_delimiter(Alphanumeric, b'\n', 10, false, 100);
/// assert_eq!(100, random_string.len());
/// ```
pub struct RandomString;
@ -108,7 +108,7 @@ impl RandomString {
/// use crate::common::random::{AlphanumericNewline, RandomString};
///
/// // generates a 100 byte string with 10 '\0' byte characters not ending with a '\0' byte
/// let string = RandomString::generate_with_delimiter(&AlphanumericNewline, 0, 10, false, 100);
/// let string = RandomString::generate_with_delimiter(AlphanumericNewline, 0, 10, false, 100);
/// assert_eq!(100, random_string.len());
/// assert_eq!(
/// 10,