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

Merge branch 'main' into mktemp-set-dir-mode

This commit is contained in:
353fc443 aka Seagull 2022-05-16 19:07:18 +01:00 committed by 353fc443
commit 2086d04996
No known key found for this signature in database
GPG key ID: D58B14ED3D42A937
88 changed files with 725 additions and 221 deletions

View file

@ -418,6 +418,29 @@ fn test_chown_only_user_id() {
.stderr_contains(&"failed to change");
}
/// Test for setting the owner to a user ID for a user that does not exist.
///
/// For example:
///
/// $ touch f && chown 12345 f
///
/// succeeds with exit status 0 and outputs nothing. The owner of the
/// file is set to 12345, even though no user with that ID exists.
///
/// This test must be run as root, because only the root user can
/// transfer ownership of a file.
#[test]
fn test_chown_only_user_id_nonexistent_user() {
let ts = TestScenario::new(util_name!());
let at = ts.fixtures.clone();
at.touch("f");
if let Ok(result) = run_ucmd_as_root(&ts, &["12345", "f"]) {
result.success().no_stdout().no_stderr();
} else {
print!("Test skipped; requires root user");
}
}
#[test]
// FixME: stderr = chown: ownership of 'test_chown_file1' retained as cuuser:wheel
#[cfg(not(target_os = "freebsd"))]
@ -461,6 +484,29 @@ fn test_chown_only_group_id() {
.stderr_contains(&"failed to change");
}
/// Test for setting the group to a group ID for a group that does not exist.
///
/// For example:
///
/// $ touch f && chown :12345 f
///
/// succeeds with exit status 0 and outputs nothing. The group of the
/// file is set to 12345, even though no group with that ID exists.
///
/// This test must be run as root, because only the root user can
/// transfer ownership of a file.
#[test]
fn test_chown_only_group_id_nonexistent_group() {
let ts = TestScenario::new(util_name!());
let at = ts.fixtures.clone();
at.touch("f");
if let Ok(result) = run_ucmd_as_root(&ts, &[":12345", "f"]) {
result.success().no_stdout().no_stderr();
} else {
print!("Test skipped; requires root user");
}
}
#[test]
fn test_chown_owner_group_id() {
// test chown 1111:1111 file.txt

View file

@ -73,7 +73,7 @@ fn test_df_output() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Capacity",
"Use%",
"Mounted",
@ -84,7 +84,7 @@ fn test_df_output() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Use%",
"Mounted",
"on",
@ -107,7 +107,7 @@ fn test_df_output_overridden() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Capacity",
"Use%",
"Mounted",
@ -118,7 +118,7 @@ fn test_df_output_overridden() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Use%",
"Mounted",
"on",
@ -134,6 +134,46 @@ fn test_df_output_overridden() {
assert_eq!(actual, expected);
}
#[test]
fn test_default_headers() {
let expected = if cfg!(target_os = "macos") {
vec![
"Filesystem",
"1K-blocks",
"Used",
"Available",
"Capacity",
"Use%",
"Mounted",
"on",
]
} else {
vec![
"Filesystem",
"1K-blocks",
"Used",
"Available",
"Use%",
"Mounted",
"on",
]
};
let output = new_ucmd!().succeeds().stdout_move_str();
let actual = output.lines().take(1).collect::<Vec<&str>>()[0];
let actual = actual.split_whitespace().collect::<Vec<_>>();
assert_eq!(actual, expected);
}
#[test]
fn test_precedence_of_human_readable_header_over_output_header() {
let output = new_ucmd!()
.args(&["-H", "--output=size"])
.succeeds()
.stdout_move_str();
let header = output.lines().next().unwrap().to_string();
assert_eq!(header.trim(), "Size");
}
#[test]
fn test_total_option_with_single_dash() {
// These should fail because `-total` should have two dashes,
@ -395,6 +435,30 @@ fn test_default_block_size() {
assert_eq!(header, "512B-blocks");
}
#[test]
fn test_default_block_size_in_posix_portability_mode() {
fn get_header(s: &str) -> String {
s.lines()
.next()
.unwrap()
.to_string()
.split_whitespace()
.nth(1)
.unwrap()
.to_string()
}
let output = new_ucmd!().arg("-P").succeeds().stdout_move_str();
assert_eq!(get_header(&output), "1024-blocks");
let output = new_ucmd!()
.arg("-P")
.env("POSIXLY_CORRECT", "1")
.succeeds()
.stdout_move_str();
assert_eq!(get_header(&output), "512-blocks");
}
#[test]
fn test_block_size_1024() {
fn get_header(block_size: u64) -> String {
@ -443,6 +507,31 @@ fn test_block_size_with_suffix() {
assert_eq!(get_header("1GB"), "1GB-blocks");
}
#[test]
fn test_block_size_in_posix_portability_mode() {
fn get_header(block_size: &str) -> String {
let output = new_ucmd!()
.args(&["-P", "-B", block_size])
.succeeds()
.stdout_move_str();
output
.lines()
.next()
.unwrap()
.to_string()
.split_whitespace()
.nth(1)
.unwrap()
.to_string()
}
assert_eq!(get_header("1024"), "1024-blocks");
assert_eq!(get_header("1K"), "1024-blocks");
assert_eq!(get_header("1KB"), "1000-blocks");
assert_eq!(get_header("1M"), "1048576-blocks");
assert_eq!(get_header("1MB"), "1000000-blocks");
}
#[test]
fn test_too_large_block_size() {
fn run_command(size: &str) {
@ -465,6 +554,16 @@ fn test_invalid_block_size() {
.arg("--block-size=x")
.fails()
.stderr_contains("invalid --block-size argument 'x'");
new_ucmd!()
.arg("--block-size=0")
.fails()
.stderr_contains("invalid --block-size argument '0'");
new_ucmd!()
.arg("--block-size=0K")
.fails()
.stderr_contains("invalid --block-size argument '0K'");
}
#[test]

View file

@ -2,6 +2,8 @@
use crate::common::util::*;
use uucore::display::Quotable;
use std::path::PathBuf;
use tempfile::tempdir;
@ -497,3 +499,15 @@ fn test_directory_permissions() {
assert!(metadata.is_dir());
assert_eq!(metadata.permissions().mode(), 0o40700);
}
/// Test that a template with a path separator is invalid.
#[test]
fn test_template_path_separator() {
new_ucmd!()
.args(&["-t", "a/bXXX"])
.fails()
.stderr_only(format!(
"mktemp: invalid template, {}, contains directory separator\n",
"a/bXXX".quote()
));
}

View file

@ -346,14 +346,25 @@ fn test_printf() {
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
}
#[cfg(unix)]
#[test]
#[cfg(disable_until_fixed)]
#[cfg(unix)]
fn test_pipe_fifo() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkfifo("FIFO");
ucmd.arg("FIFO")
.run()
.no_stderr()
.stdout_contains("fifo")
.stdout_contains("File: FIFO")
.succeeded();
}
#[test]
#[cfg(all(unix, not(target_os = "android")))]
fn test_stdin_pipe_fifo1() {
// $ echo | stat -
// File: -
// Size: 0 Blocks: 0 IO Block: 4096 fifo
// use std::process::{Command, Stdio};
new_ucmd!()
.arg("-")
.set_stdin(std::process::Stdio::piped())
@ -362,17 +373,25 @@ fn test_stdin_pipe_fifo1() {
.stdout_contains("fifo")
.stdout_contains("File: -")
.succeeded();
new_ucmd!()
.args(&["-L", "-"])
.set_stdin(std::process::Stdio::piped())
.run()
.no_stderr()
.stdout_contains("fifo")
.stdout_contains("File: -")
.succeeded();
}
#[cfg(unix)]
#[test]
#[cfg(disable_until_fixed)]
#[cfg(all(unix, not(target_os = "android")))]
fn test_stdin_pipe_fifo2() {
// $ stat -
// File: -
// Size: 0 Blocks: 0 IO Block: 1024 character special file
new_ucmd!()
.arg("-")
.set_stdin(std::process::Stdio::null())
.run()
.no_stderr()
.stdout_contains("character special file")
@ -380,20 +399,18 @@ fn test_stdin_pipe_fifo2() {
.succeeded();
}
#[cfg(unix)]
#[test]
#[cfg(disable_until_fixed)]
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
fn test_stdin_redirect() {
// $ touch f && stat - < f
// File: -
// Size: 0 Blocks: 0 IO Block: 4096 regular empty file
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("f");
new_ucmd!()
ts.ucmd()
.arg("-")
.set_stdin(std::fs::File::open("f").unwrap())
.set_stdin(std::fs::File::open(at.plus("f")).unwrap())
.run()
.no_stderr()
.stdout_contains("regular empty file")