mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 19:56:17 +00:00
Merge branch 'master' into tail_notify
This commit is contained in:
commit
22b59289e8
28 changed files with 1092 additions and 391 deletions
|
@ -38,6 +38,30 @@ macro_rules! test_digest {
|
|||
.no_stderr()
|
||||
.stdout_is("input.txt: OK\n");
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn test_text_mode() {
|
||||
// TODO Replace this with hard-coded files that store the
|
||||
// expected output of text mode on an input file that has
|
||||
// "\r\n" line endings.
|
||||
let result = new_ucmd!()
|
||||
.args(&[DIGEST_ARG, BITS_ARG, "-b"])
|
||||
.pipe_in("a\nb\nc\n")
|
||||
.succeeds();
|
||||
let expected = result.no_stderr().stdout();
|
||||
// Replace the "*-\n" at the end of the output with " -\n".
|
||||
// The asterisk indicates that the digest was computed in
|
||||
// binary mode.
|
||||
let n = expected.len();
|
||||
let expected = [&expected[..n - 3], &[b' ', b'-', b'\n']].concat();
|
||||
new_ucmd!()
|
||||
.args(&[DIGEST_ARG, BITS_ARG, "-t"])
|
||||
.pipe_in("a\r\nb\r\nc\r\n")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is(std::str::from_utf8(&expected).unwrap());
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
|
|
@ -56,6 +56,12 @@ fn test_kill_list_all_signals() {
|
|||
.stdout_contains("HUP");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kill_list_final_new_line() {
|
||||
let re = Regex::new("\\n$").unwrap();
|
||||
assert!(re.is_match(new_ucmd!().arg("-l").succeeds().stdout_str()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kill_list_all_signals_as_table() {
|
||||
// Check for a few signals. Do not try to be comprehensive.
|
||||
|
@ -104,6 +110,26 @@ fn test_kill_with_signal_number_old_form() {
|
|||
assert_eq!(target.wait_for_signal(), Some(9));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kill_with_signal_name_old_form() {
|
||||
let mut target = Target::new();
|
||||
new_ucmd!()
|
||||
.arg("-KILL")
|
||||
.arg(format!("{}", target.pid()))
|
||||
.succeeds();
|
||||
assert_eq!(target.wait_for_signal(), Some(libc::SIGKILL));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kill_with_signal_prefixed_name_old_form() {
|
||||
let mut target = Target::new();
|
||||
new_ucmd!()
|
||||
.arg("-SIGKILL")
|
||||
.arg(format!("{}", target.pid()))
|
||||
.succeeds();
|
||||
assert_eq!(target.wait_for_signal(), Some(libc::SIGKILL));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kill_with_signal_number_new_form() {
|
||||
let mut target = Target::new();
|
||||
|
@ -125,3 +151,14 @@ fn test_kill_with_signal_name_new_form() {
|
|||
.succeeds();
|
||||
assert_eq!(target.wait_for_signal(), Some(libc::SIGKILL));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kill_with_signal_prefixed_name_new_form() {
|
||||
let mut target = Target::new();
|
||||
new_ucmd!()
|
||||
.arg("-s")
|
||||
.arg("SIGKILL")
|
||||
.arg(format!("{}", target.pid()))
|
||||
.succeeds();
|
||||
assert_eq!(target.wait_for_signal(), Some(libc::SIGKILL));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,56 @@ fn test_rejects_non_floats() {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_float() {
|
||||
new_ucmd!()
|
||||
.args(&["1e2.3"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["1e2.3", "2"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["1", "1e2.3"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["1e2.3", "2", "3"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["1", "1e2.3", "3"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
new_ucmd!()
|
||||
.args(&["1", "2", "1e2.3"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_width_invalid_float() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", "1e2.3"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid floating point argument: '1e2.3'")
|
||||
.stderr_contains("for more information.");
|
||||
}
|
||||
|
||||
// ---- Tests for the big integer based path ----
|
||||
|
||||
#[test]
|
||||
|
@ -149,6 +199,16 @@ fn test_preserve_negative_zero_start() {
|
|||
.succeeds()
|
||||
.stdout_is("-0\n1\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-0", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n1\n2\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-0", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n1\n2\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -176,6 +236,203 @@ fn test_width_negative_zero() {
|
|||
.succeeds()
|
||||
.stdout_is("-0\n01\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n01\n02\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n01\n02\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_width_negative_zero_decimal_notation() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.0", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.0\n01.0\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.0", "1.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.0\n01.0\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.0", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.0\n01.0\n02.0\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.0", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.0\n01.0\n02.0\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.0", "1.0", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.0\n01.0\n02.0\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.0", "1.0", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.0\n01.0\n02.0\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_width_negative_zero_scientific_notation() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0e0", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n01\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0e0", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n01\n02\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0e0", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0\n01\n02\n")
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0e+1", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-00\n001\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0e+1", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-00\n001\n002\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0e+1", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-00\n001\n002\n")
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e0", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.000\n01.000\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e0", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.000\n01.000\n02.000\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e0", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.000\n01.000\n02.000\n")
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e-2", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.00000\n01.00000\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e-2", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.00000\n01.00000\n02.00000\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e-2", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-0.00000\n01.00000\n02.00000\n")
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e5", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-000000\n0000001\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e5", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-000000\n0000001\n0000002\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e5", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-000000\n0000001\n0000002\n")
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e5", "1"])
|
||||
.succeeds()
|
||||
.stdout_is("-000000\n0000001\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e5", "1", "2"])
|
||||
.succeeds()
|
||||
.stdout_is("-000000\n0000001\n0000002\n")
|
||||
.no_stderr();
|
||||
new_ucmd!()
|
||||
.args(&["-w", "-0.000e5", "1", "2.0"])
|
||||
.succeeds()
|
||||
.stdout_is("-000000\n0000001\n0000002\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_width_decimal_scientific_notation_increment() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", ".1", "1e-2", ".11"])
|
||||
.succeeds()
|
||||
.stdout_is("0.10\n0.11\n")
|
||||
.no_stderr();
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-w", ".0", "1.500e-1", ".2"])
|
||||
.succeeds()
|
||||
.stdout_is("0.0000\n0.1500\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
/// Test that trailing zeros in the start argument contribute to precision.
|
||||
#[test]
|
||||
fn test_width_decimal_scientific_notation_trailing_zeros_start() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", ".1000", "1e-2", ".11"])
|
||||
.succeeds()
|
||||
.stdout_is("0.1000\n0.1100\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
/// Test that trailing zeros in the increment argument contribute to precision.
|
||||
#[test]
|
||||
fn test_width_decimal_scientific_notation_trailing_zeros_increment() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", "1e-1", "0.0100", ".11"])
|
||||
.succeeds()
|
||||
.stdout_is("0.1000\n0.1100\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
/// Test that trailing zeros in the end argument do not contribute to width.
|
||||
#[test]
|
||||
fn test_width_decimal_scientific_notation_trailing_zeros_end() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", "1e-1", "1e-2", ".1100"])
|
||||
.succeeds()
|
||||
.stdout_is("0.10\n0.11\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_width_floats() {
|
||||
new_ucmd!()
|
||||
.args(&["-w", "9.0", "10.0"])
|
||||
.succeeds()
|
||||
.stdout_is("09.0\n10.0\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
// TODO This is duplicated from `test_yes.rs`; refactor them.
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// * For the full copyright and license information, please view the LICENSE
|
||||
// * file that was distributed with this source code.
|
||||
|
||||
#[cfg(unix)]
|
||||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
|
@ -34,7 +33,6 @@ fn test_normal_compare_id() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_normal_compare_env() {
|
||||
let whoami = whoami();
|
||||
if whoami == "nobody" {
|
||||
|
|
|
@ -1069,10 +1069,12 @@ pub fn whoami() -> String {
|
|||
|
||||
// Use environment variable to get current user instead of
|
||||
// invoking `whoami` and fall back to user "nobody" on error.
|
||||
std::env::var("USER").unwrap_or_else(|e| {
|
||||
println!("{}: {}, using \"nobody\" instead", UUTILS_WARNING, e);
|
||||
"nobody".to_string()
|
||||
})
|
||||
std::env::var("USER")
|
||||
.or_else(|_| std::env::var("USERNAME"))
|
||||
.unwrap_or_else(|e| {
|
||||
println!("{}: {}, using \"nobody\" instead", UUTILS_WARNING, e);
|
||||
"nobody".to_string()
|
||||
})
|
||||
}
|
||||
|
||||
/// Add prefix 'g' for `util_name` if not on linux
|
||||
|
@ -1167,7 +1169,7 @@ pub fn check_coreutil_version(
|
|||
if s.contains(&format!("(GNU coreutils) {}", version_expected)) {
|
||||
Ok(format!("{}: {}", UUTILS_INFO, s.to_string()))
|
||||
} else if s.contains("(GNU coreutils)") {
|
||||
let version_found = s.split_whitespace().last().unwrap()[..4].parse::<f32>().unwrap_or_default();
|
||||
let version_found = parse_coreutil_version(s);
|
||||
let version_expected = version_expected.parse::<f32>().unwrap_or_default();
|
||||
if version_found > version_expected {
|
||||
Ok(format!("{}: version for the reference coreutil '{}' is higher than expected; expected: {}, found: {}", UUTILS_INFO, util_name, version_expected, version_found))
|
||||
|
@ -1180,6 +1182,20 @@ pub fn check_coreutil_version(
|
|||
)
|
||||
}
|
||||
|
||||
// simple heuristic to parse the coreutils SemVer string, e.g. "id (GNU coreutils) 8.32.263-0475"
|
||||
fn parse_coreutil_version(version_string: &str) -> f32 {
|
||||
version_string
|
||||
.split_whitespace()
|
||||
.last()
|
||||
.unwrap()
|
||||
.split('.')
|
||||
.take(2)
|
||||
.collect::<Vec<_>>()
|
||||
.join(".")
|
||||
.parse::<f32>()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// This runs the GNU coreutils `util_name` binary in `$PATH` in order to
|
||||
/// dynamically gather reference values on the system.
|
||||
/// If the `util_name` in `$PATH` doesn't include a coreutils version string,
|
||||
|
@ -1472,6 +1488,36 @@ mod tests {
|
|||
res.normalized_newlines_stdout_is("A\r\nB\nC\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_parse_coreutil_version() {
|
||||
use std::assert_eq;
|
||||
assert_eq!(
|
||||
parse_coreutil_version("id (GNU coreutils) 9.0.123-0123").to_string(),
|
||||
"9"
|
||||
);
|
||||
assert_eq!(
|
||||
parse_coreutil_version("id (GNU coreutils) 8.32.263-0475").to_string(),
|
||||
"8.32"
|
||||
);
|
||||
assert_eq!(
|
||||
parse_coreutil_version("id (GNU coreutils) 8.25.123-0123").to_string(),
|
||||
"8.25"
|
||||
);
|
||||
assert_eq!(
|
||||
parse_coreutil_version("id (GNU coreutils) 9.0").to_string(),
|
||||
"9"
|
||||
);
|
||||
assert_eq!(
|
||||
parse_coreutil_version("id (GNU coreutils) 8.32").to_string(),
|
||||
"8.32"
|
||||
);
|
||||
assert_eq!(
|
||||
parse_coreutil_version("id (GNU coreutils) 8.25").to_string(),
|
||||
"8.25"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_check_coreutil_version() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue